use 'Self' to refer to own type
This commit is contained in:
parent
a88cbad37f
commit
b9723dd5e0
15 changed files with 48 additions and 54 deletions
|
|
@ -108,7 +108,7 @@ impl DockItem {
|
||||||
rectangle_tracker: Option<&RectangleTracker<u32>>,
|
rectangle_tracker: Option<&RectangleTracker<u32>>,
|
||||||
interaction_enabled: bool,
|
interaction_enabled: bool,
|
||||||
) -> Element<'_, Message> {
|
) -> Element<'_, Message> {
|
||||||
let DockItem {
|
let Self {
|
||||||
toplevels,
|
toplevels,
|
||||||
desktop_info,
|
desktop_info,
|
||||||
id,
|
id,
|
||||||
|
|
@ -377,7 +377,7 @@ impl cosmic::Application for CosmicAppList {
|
||||||
_flags: Self::Flags,
|
_flags: Self::Flags,
|
||||||
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
|
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
|
||||||
let config = config::AppListConfig::load().unwrap_or_default();
|
let config = config::AppListConfig::load().unwrap_or_default();
|
||||||
let mut self_ = CosmicAppList {
|
let mut self_ = Self {
|
||||||
core,
|
core,
|
||||||
favorite_list: desktop_info_for_app_ids(config.favorites.clone())
|
favorite_list: desktop_info_for_app_ids(config.favorites.clone())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ pub struct AppListConfig {
|
||||||
impl AppListConfig {
|
impl AppListConfig {
|
||||||
// TODO async?
|
// TODO async?
|
||||||
/// load config with the provided name
|
/// load config with the provided name
|
||||||
pub fn load() -> anyhow::Result<AppListConfig> {
|
pub fn load() -> anyhow::Result<Self> {
|
||||||
let mut relative_path = PathBuf::from(APP_ID);
|
let mut relative_path = PathBuf::from(APP_ID);
|
||||||
relative_path.push("config.ron");
|
relative_path.push("config.ron");
|
||||||
let file = match BaseDirectories::new()
|
let file = match BaseDirectories::new()
|
||||||
|
|
@ -40,7 +40,7 @@ impl AppListConfig {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ron::de::from_reader::<_, AppListConfig>(file)
|
ron::de::from_reader::<_, Self>(file)
|
||||||
.map_err(|err| anyhow!("Failed to parse config file: {}", err))
|
.map_err(|err| anyhow!("Failed to parse config file: {}", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -261,9 +261,9 @@ impl cosmic::Application for Audio {
|
||||||
type Flags = ();
|
type Flags = ();
|
||||||
const APP_ID: &'static str = "com.system76.CosmicAppletAudio";
|
const APP_ID: &'static str = "com.system76.CosmicAppletAudio";
|
||||||
|
|
||||||
fn init(core: cosmic::app::Core, _flags: ()) -> (Audio, Command<Message>) {
|
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command<Message>) {
|
||||||
(
|
(
|
||||||
Audio {
|
Self {
|
||||||
core,
|
core,
|
||||||
is_open: IsOpen::None,
|
is_open: IsOpen::None,
|
||||||
current_output: None,
|
current_output: None,
|
||||||
|
|
@ -797,27 +797,27 @@ enum PulseState {
|
||||||
impl PulseState {
|
impl PulseState {
|
||||||
fn connection(&mut self) -> Option<&mut pulse::Connection> {
|
fn connection(&mut self) -> Option<&mut pulse::Connection> {
|
||||||
match self {
|
match self {
|
||||||
PulseState::Disconnected(c) => Some(c),
|
Self::Disconnected(c) => Some(c),
|
||||||
PulseState::Connected(c) => Some(c),
|
Self::Connected(c) => Some(c),
|
||||||
PulseState::Init => None,
|
Self::Init => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connected(&mut self) {
|
fn connected(&mut self) {
|
||||||
if let PulseState::Disconnected(c) = self {
|
if let Self::Disconnected(c) = self {
|
||||||
*self = PulseState::Connected(c.clone());
|
*self = Self::Connected(c.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disconnected(&mut self) {
|
fn disconnected(&mut self) {
|
||||||
if let PulseState::Connected(c) = self {
|
if let Self::Connected(c) = self {
|
||||||
*self = PulseState::Disconnected(c.clone());
|
*self = Self::Disconnected(c.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for IsOpen {
|
impl Default for IsOpen {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
IsOpen::None
|
Self::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ struct PulseHandle {
|
||||||
|
|
||||||
impl PulseHandle {
|
impl PulseHandle {
|
||||||
// Create pulse server thread, and bidirectional comms
|
// Create pulse server thread, and bidirectional comms
|
||||||
pub fn new() -> PulseHandle {
|
pub fn new() -> Self {
|
||||||
let (to_pulse, mut to_pulse_recv) = tokio::sync::mpsc::channel(10);
|
let (to_pulse, mut to_pulse_recv) = tokio::sync::mpsc::channel(10);
|
||||||
let (mut from_pulse_send, from_pulse) = tokio::sync::mpsc::channel(10);
|
let (mut from_pulse_send, from_pulse) = tokio::sync::mpsc::channel(10);
|
||||||
// get initial connection status
|
// get initial connection status
|
||||||
|
|
@ -195,9 +195,7 @@ impl PulseHandle {
|
||||||
.send(Message::SetDefaultSink(sink))
|
.send(Message::SetDefaultSink(sink))
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Err(_) => {
|
Err(_) => Self::send_disconnected(&mut from_pulse_send).await,
|
||||||
PulseHandle::send_disconnected(&mut from_pulse_send).await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::GetDefaultSource => {
|
Message::GetDefaultSource => {
|
||||||
|
|
@ -212,7 +210,7 @@ impl PulseHandle {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("ERROR! {:?}", e);
|
tracing::error!("ERROR! {:?}", e);
|
||||||
PulseHandle::send_disconnected(&mut from_pulse_send).await;
|
Self::send_disconnected(&mut from_pulse_send).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -226,9 +224,7 @@ impl PulseHandle {
|
||||||
.send(Message::SetSinks(sinks))
|
.send(Message::SetSinks(sinks))
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Err(_) => {
|
Err(_) => Self::send_disconnected(&mut from_pulse_send).await,
|
||||||
PulseHandle::send_disconnected(&mut from_pulse_send).await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::GetSources => {
|
Message::GetSources => {
|
||||||
|
|
@ -241,9 +237,7 @@ impl PulseHandle {
|
||||||
.send(Message::SetSources(sinks))
|
.send(Message::SetSources(sinks))
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Err(_) => {
|
Err(_) => Self::send_disconnected(&mut from_pulse_send).await,
|
||||||
PulseHandle::send_disconnected(&mut from_pulse_send).await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::SetSinkVolumeByName(name, channel_volumes) => {
|
Message::SetSinkVolumeByName(name, channel_volumes) => {
|
||||||
|
|
@ -269,7 +263,7 @@ impl PulseHandle {
|
||||||
tracing::trace!("getting server info...");
|
tracing::trace!("getting server info...");
|
||||||
if cur_server.get_server_info().is_err() {
|
if cur_server.get_server_info().is_err() {
|
||||||
tracing::warn!("got error, server must be disconnected...");
|
tracing::warn!("got error, server must be disconnected...");
|
||||||
PulseHandle::send_disconnected(&mut from_pulse_send).await;
|
Self::send_disconnected(&mut from_pulse_send).await;
|
||||||
} else {
|
} else {
|
||||||
tracing::trace!("got server info, still connected...");
|
tracing::trace!("got server info, still connected...");
|
||||||
server = Some(cur_server);
|
server = Some(cur_server);
|
||||||
|
|
@ -278,7 +272,7 @@ impl PulseHandle {
|
||||||
match PulseServer::connect().and_then(|server| server.init()) {
|
match PulseServer::connect().and_then(|server| server.init()) {
|
||||||
Ok(new_server) => {
|
Ok(new_server) => {
|
||||||
tracing::info!("Connected to server");
|
tracing::info!("Connected to server");
|
||||||
PulseHandle::send_connected(&mut from_pulse_send).await;
|
Self::send_connected(&mut from_pulse_send).await;
|
||||||
server = Some(new_server);
|
server = Some(new_server);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -336,7 +330,7 @@ impl PulseHandle {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
PulseHandle {
|
Self {
|
||||||
to_pulse,
|
to_pulse,
|
||||||
from_pulse,
|
from_pulse,
|
||||||
}
|
}
|
||||||
|
|
@ -372,7 +366,7 @@ enum PulseServerError<'a> {
|
||||||
// https://crates.io/crates/pulsectl-rs
|
// https://crates.io/crates/pulsectl-rs
|
||||||
impl PulseServer {
|
impl PulseServer {
|
||||||
// connect() requires init() to be run after
|
// connect() requires init() to be run after
|
||||||
pub fn connect() -> Result<PulseServer, PulseServerError<'static>> {
|
pub fn connect() -> Result<Self, PulseServerError<'static>> {
|
||||||
// TODO: fix app name, should be variable
|
// TODO: fix app name, should be variable
|
||||||
let mut proplist = Proplist::new().unwrap();
|
let mut proplist = Proplist::new().unwrap();
|
||||||
proplist
|
proplist
|
||||||
|
|
@ -398,7 +392,7 @@ impl PulseServer {
|
||||||
.connect(None, pulse::context::FlagSet::NOFLAGS, None)
|
.connect(None, pulse::context::FlagSet::NOFLAGS, None)
|
||||||
.map_err(PulseServerError::PAErr)?;
|
.map_err(PulseServerError::PAErr)?;
|
||||||
|
|
||||||
Ok(PulseServer {
|
Ok(Self {
|
||||||
mainloop,
|
mainloop,
|
||||||
context,
|
context,
|
||||||
introspector,
|
introspector,
|
||||||
|
|
@ -729,7 +723,7 @@ pub struct ServerInfo {
|
||||||
|
|
||||||
impl<'a> From<&'a pulse::context::introspect::ServerInfo<'a>> for ServerInfo {
|
impl<'a> From<&'a pulse::context::introspect::ServerInfo<'a>> for ServerInfo {
|
||||||
fn from(info: &'a pulse::context::introspect::ServerInfo<'a>) -> Self {
|
fn from(info: &'a pulse::context::introspect::ServerInfo<'a>) -> Self {
|
||||||
ServerInfo {
|
Self {
|
||||||
user_name: info.user_name.as_ref().map(|cow| cow.to_string()),
|
user_name: info.user_name.as_ref().map(|cow| cow.to_string()),
|
||||||
host_name: info.host_name.as_ref().map(|cow| cow.to_string()),
|
host_name: info.host_name.as_ref().map(|cow| cow.to_string()),
|
||||||
server_version: info.server_version.as_ref().map(|cow| cow.to_string()),
|
server_version: info.server_version.as_ref().map(|cow| cow.to_string()),
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ impl cosmic::Application for CosmicBatteryApplet {
|
||||||
cosmic::iced::Command<cosmic::app::Message<Self::Message>>,
|
cosmic::iced::Command<cosmic::app::Message<Self::Message>>,
|
||||||
) {
|
) {
|
||||||
(
|
(
|
||||||
CosmicBatteryApplet {
|
Self {
|
||||||
core,
|
core,
|
||||||
icon_name: "battery-symbolic".to_string(),
|
icon_name: "battery-symbolic".to_string(),
|
||||||
display_icon_name: "display-brightness-symbolic".to_string(),
|
display_icon_name: "display-brightness-symbolic".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ impl cosmic::Application for CosmicBluetoothApplet {
|
||||||
_flags: Self::Flags,
|
_flags: Self::Flags,
|
||||||
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
|
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
|
||||||
(
|
(
|
||||||
CosmicBluetoothApplet {
|
Self {
|
||||||
core,
|
core,
|
||||||
icon_name: "bluetooth-symbolic".to_string(),
|
icon_name: "bluetooth-symbolic".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ enum GraphicsMode {
|
||||||
impl GraphicsMode {
|
impl GraphicsMode {
|
||||||
fn inner(&self) -> Graphics {
|
fn inner(&self) -> Graphics {
|
||||||
match self {
|
match self {
|
||||||
GraphicsMode::Selected { new, .. } => *new,
|
Self::Selected { new, .. } => *new,
|
||||||
GraphicsMode::Current(g) => *g,
|
Self::Current(g) => *g,
|
||||||
GraphicsMode::Applied(g) => *g,
|
Self::Applied(g) => *g,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +67,7 @@ impl cosmic::Application for Window {
|
||||||
core: cosmic::app::Core,
|
core: cosmic::app::Core,
|
||||||
_flags: Self::Flags,
|
_flags: Self::Flags,
|
||||||
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
|
) -> (Self, iced::Command<cosmic::app::Message<Self::Message>>) {
|
||||||
let window = Window {
|
let window = Self {
|
||||||
core,
|
core,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,12 @@ enum NewConnectionState {
|
||||||
impl NewConnectionState {
|
impl NewConnectionState {
|
||||||
pub fn ssid(&self) -> &str {
|
pub fn ssid(&self) -> &str {
|
||||||
&match self {
|
&match self {
|
||||||
NewConnectionState::EnterPassword {
|
Self::EnterPassword {
|
||||||
access_point,
|
access_point,
|
||||||
password: _,
|
password: _,
|
||||||
} => access_point,
|
} => access_point,
|
||||||
NewConnectionState::Waiting(ap) => ap,
|
Self::Waiting(ap) => ap,
|
||||||
NewConnectionState::Failure(ap) => ap,
|
Self::Failure(ap) => ap,
|
||||||
}
|
}
|
||||||
.ssid
|
.ssid
|
||||||
}
|
}
|
||||||
|
|
@ -66,12 +66,12 @@ impl NewConnectionState {
|
||||||
impl Into<AccessPoint> for NewConnectionState {
|
impl Into<AccessPoint> for NewConnectionState {
|
||||||
fn into(self) -> AccessPoint {
|
fn into(self) -> AccessPoint {
|
||||||
match self {
|
match self {
|
||||||
NewConnectionState::EnterPassword {
|
Self::EnterPassword {
|
||||||
access_point,
|
access_point,
|
||||||
password: _,
|
password: _,
|
||||||
} => access_point,
|
} => access_point,
|
||||||
NewConnectionState::Waiting(access_point) => access_point,
|
Self::Waiting(access_point) => access_point,
|
||||||
NewConnectionState::Failure(access_point) => access_point,
|
Self::Failure(access_point) => access_point,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +192,7 @@ impl cosmic::Application for CosmicNetworkApplet {
|
||||||
|
|
||||||
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command<Message>) {
|
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command<Message>) {
|
||||||
(
|
(
|
||||||
CosmicNetworkApplet {
|
Self {
|
||||||
core,
|
core,
|
||||||
icon_name: "network-offline-symbolic".to_string(),
|
icon_name: "network-offline-symbolic".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,9 @@ pub enum ActiveConnectionInfo {
|
||||||
impl ActiveConnectionInfo {
|
impl ActiveConnectionInfo {
|
||||||
pub fn name(&self) -> String {
|
pub fn name(&self) -> String {
|
||||||
match &self {
|
match &self {
|
||||||
ActiveConnectionInfo::Wired { name, .. } => name.clone(),
|
Self::Wired { name, .. } => name.clone(),
|
||||||
ActiveConnectionInfo::WiFi { name, .. } => name.clone(),
|
Self::WiFi { name, .. } => name.clone(),
|
||||||
ActiveConnectionInfo::Vpn { name, .. } => name.clone(),
|
Self::Vpn { name, .. } => name.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ impl cosmic::Application for Notifications {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let mut _self = Notifications {
|
let mut _self = Self {
|
||||||
core,
|
core,
|
||||||
config_helper: helper,
|
config_helper: helper,
|
||||||
config,
|
config,
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,9 @@ impl cosmic::Application for Power {
|
||||||
&mut self.core
|
&mut self.core
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(core: cosmic::app::Core, _flags: ()) -> (Power, Command<Message>) {
|
fn init(core: cosmic::app::Core, _flags: ()) -> (Self, Command<Message>) {
|
||||||
(
|
(
|
||||||
Power {
|
Self {
|
||||||
core,
|
core,
|
||||||
icon_name: "system-shutdown-symbolic".to_string(),
|
icon_name: "system-shutdown-symbolic".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ impl cosmic::Application for Window {
|
||||||
gaps.value = core.system_theme().cosmic().gaps.1 as i32;
|
gaps.value = core.system_theme().cosmic().gaps.1 as i32;
|
||||||
let mut active_hint = spin_button::Model::default().max(99).min(0).step(1);
|
let mut active_hint = spin_button::Model::default().max(99).min(0).step(1);
|
||||||
active_hint.value = core.system_theme().cosmic().active_hint as i32;
|
active_hint.value = core.system_theme().cosmic().active_hint as i32;
|
||||||
let window = Window {
|
let window = Self {
|
||||||
core,
|
core,
|
||||||
gaps,
|
gaps,
|
||||||
active_hint,
|
active_hint,
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ impl cosmic::Application for Window {
|
||||||
_flags: Self::Flags,
|
_flags: Self::Flags,
|
||||||
) -> (Self, cosmic::iced::Command<app::Message<Self::Message>>) {
|
) -> (Self, cosmic::iced::Command<app::Message<Self::Message>>) {
|
||||||
(
|
(
|
||||||
Window {
|
Self {
|
||||||
core,
|
core,
|
||||||
popup: None,
|
popup: None,
|
||||||
id_ctr: 0,
|
id_ctr: 0,
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ impl cosmic::Application for IcedWorkspacesApplet {
|
||||||
cosmic::iced::Command<cosmic::app::Message<Self::Message>>,
|
cosmic::iced::Command<cosmic::app::Message<Self::Message>>,
|
||||||
) {
|
) {
|
||||||
(
|
(
|
||||||
IcedWorkspacesApplet {
|
Self {
|
||||||
layout: match &core.applet.anchor {
|
layout: match &core.applet.anchor {
|
||||||
PanelAnchor::Left | PanelAnchor::Right => Layout::Column,
|
PanelAnchor::Left | PanelAnchor::Right => Layout::Column,
|
||||||
PanelAnchor::Top | PanelAnchor::Bottom => Layout::Row,
|
PanelAnchor::Top | PanelAnchor::Bottom => Layout::Row,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ impl cosmic::Application for Button {
|
||||||
const APP_ID: &'static str = "com.system76.CosmicPanelButton";
|
const APP_ID: &'static str = "com.system76.CosmicPanelButton";
|
||||||
|
|
||||||
fn init(core: cosmic::app::Core, desktop: Desktop) -> (Self, app::Command<Msg>) {
|
fn init(core: cosmic::app::Core, desktop: Desktop) -> (Self, app::Command<Msg>) {
|
||||||
(Button { core, desktop }, app::Command::none())
|
(Self { core, desktop }, app::Command::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn core(&self) -> &cosmic::app::Core {
|
fn core(&self) -> &cosmic::app::Core {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue