Skip to content

Commit

Permalink
feat: add default applications page
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Nov 25, 2024
1 parent 4e31002 commit 91daff1
Show file tree
Hide file tree
Showing 25 changed files with 683 additions and 206 deletions.
220 changes: 124 additions & 96 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inherits = "release"
debug = true

[profile.release]
lto = "thin"
# lto = "thin"

# [patch.'https://github.com/smithay/client-toolkit/']
# smithay-client-toolkit = { git = "https://github.com/smithay/client-toolkit//", rev = "c583de8" }
Expand Down
4 changes: 4 additions & 0 deletions cosmic-settings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ itertools = "0.13.0"
itoa = "1.0.11"
libcosmic.workspace = true
locale1 = { git = "https://github.com/pop-os/dbus-settings-bindings", optional = true }
mime-apps = { package = "cosmic-mime-apps", git = "https://github.com/pop-os/cosmic-mime-apps", optional = true }
notify = "6.1.1"
once_cell = "1.19.0"
regex = "1.10.6"
Expand All @@ -67,6 +68,7 @@ zbus = { version = "4.4.0", features = ["tokio"], optional = true }
ustr = "1.0.0"
fontdb = "0.16.2"
fixed_decimal = "0.5.6"
mime = "0.3.17"

[dependencies.cosmic-settings-subscriptions]
git = "https://github.com/pop-os/cosmic-settings-subscriptions"
Expand Down Expand Up @@ -96,6 +98,7 @@ linux = [
"page-about",
"page-bluetooth",
"page-date",
"page-default-apps",
"page-input",
"page-networking",
"page-power",
Expand All @@ -111,6 +114,7 @@ linux = [
page-about = ["dep:cosmic-settings-system", "dep:hostname1-zbus", "dep:zbus"]
page-bluetooth = ["dep:bluez-zbus", "dep:zbus"]
page-date = ["dep:timedate-zbus", "dep:zbus"]
page-default-apps = ["dep:mime-apps"]
page-input = [
"dep:cosmic-comp-config",
"dep:cosmic-settings-config",
Expand Down
21 changes: 13 additions & 8 deletions cosmic-settings/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ use desktop::{
use event::wayland;
use page::Entity;
use std::collections::BTreeSet;
use std::time::Duration;
use std::{borrow::Cow, str::FromStr};

#[allow(clippy::struct_excessive_bools)]
Expand Down Expand Up @@ -82,6 +81,8 @@ impl SettingsApp {
PageCommands::Bluetooth => self.pages.page_id::<bluetooth::Page>(),
#[cfg(feature = "page-date")]
PageCommands::DateTime => self.pages.page_id::<time::date::Page>(),
#[cfg(feature = "page-default-apps")]
PageCommands::DefaultApps => self.pages.page_id::<system::default_apps::Page>(),
PageCommands::Desktop => self.pages.page_id::<desktop::Page>(),
PageCommands::Displays => self.pages.page_id::<display::Page>(),
#[cfg(feature = "wayland")]
Expand Down Expand Up @@ -212,10 +213,7 @@ impl cosmic::Application for SettingsApp {
}
.unwrap_or(desktop_id);

(
app,
cosmic::command::message(Message::DelayedInit(active_id)),
)
(app, cosmic::task::message(Message::DelayedInit(active_id)))
}

fn nav_model(&self) -> Option<&nav_bar::Model> {
Expand Down Expand Up @@ -389,6 +387,13 @@ impl cosmic::Application for SettingsApp {
}
}

#[cfg(feature = "page-default-apps")]
crate::pages::Message::DefaultApps(message) => {
if let Some(page) = self.pages.page_mut::<system::default_apps::Page>() {
return page.update(message).map(Into::into);
}
}

crate::pages::Message::Desktop(message) => {
page::update!(self.pages, message, desktop::Page);
}
Expand Down Expand Up @@ -718,7 +723,7 @@ impl cosmic::Application for SettingsApp {
// It is necessary to delay init to allow time for the page sender to be initialized
Message::DelayedInit(active_id) => {
if self.page_sender.is_none() {
return cosmic::command::message(Message::DelayedInit(active_id));
return cosmic::task::message(Message::DelayedInit(active_id));
}

return self.activate_page(active_id);
Expand Down Expand Up @@ -832,7 +837,7 @@ impl SettingsApp {
Task::batch(vec![
leave_task,
page_task,
cosmic::command::future(async { Message::SetWindowTitle }),
cosmic::task::future(async { Message::SetWindowTitle }),
])
}

Expand Down Expand Up @@ -1005,7 +1010,7 @@ impl SettingsApp {
if tasks.is_empty() {
Task::none()
} else {
cosmic::command::batch(tasks)
cosmic::task::batch(tasks)
.map(Message::PageMessage)
.map(Into::into)
}
Expand Down
3 changes: 3 additions & 0 deletions cosmic-settings/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub enum PageCommands {
/// Date & Time settings page
#[cfg(feature = "page-date")]
DateTime,
/// Default application associations
#[cfg(feature = "page-default-apps")]
DefaultApps,
/// Desktop settings page
Desktop,
/// Displays settings page
Expand Down
33 changes: 17 additions & 16 deletions cosmic-settings/src/pages/bluetooth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl page::Page<crate::pages::Message> for Page {
sender: tokio::sync::mpsc::Sender<crate::pages::Message>,
) -> cosmic::Task<crate::pages::Message> {
// TODO start stream for new device
cosmic::command::future(async move {
cosmic::task::future(async move {
match zbus::Connection::system().await {
Ok(connection) => Message::DBusConnect(connection, sender),
Err(why) => Message::DBusError(why.to_string()),
Expand Down Expand Up @@ -261,7 +261,7 @@ impl Page {
Active::Disabling
};
self.update_status();
return cosmic::command::future(change_adapter_status(
return cosmic::task::future(change_adapter_status(
connection.clone(),
path,
active,
Expand All @@ -276,15 +276,15 @@ impl Page {
} else {
Active::Disabling
};
cosmic::command::future(change_adapter_status(
cosmic::task::future(change_adapter_status(
connection.clone(),
path.clone(),
active,
))
})
.collect();
self.update_status();
return cosmic::command::batch(tasks);
return cosmic::task::batch(tasks);
}
tracing::warn!("No DBus connection ready");
}
Expand All @@ -306,7 +306,7 @@ impl Page {
));
}

return cosmic::command::future(async move {
return cosmic::task::future(async move {
let result: zbus::Result<HashMap<OwnedObjectPath, Adapter>> = async {
futures::future::join_all(
bluez_zbus::get_adapters(&connection)
Expand Down Expand Up @@ -342,7 +342,7 @@ impl Page {
self.update_status();

if self.selected_adapter.is_none() && self.adapters.len() == 1 {
return cosmic::command::message(Message::SelectAdapter(
return cosmic::task::message(Message::SelectAdapter(
self.adapters.keys().next().cloned(),
));
}
Expand All @@ -365,7 +365,7 @@ impl Page {
tracing::debug!("Adapter {} added", adapter.address);
self.adapters.insert(path.clone(), adapter);
if self.selected_adapter.is_none() {
return cosmic::command::message(Message::SelectAdapter(Some(path)));
return cosmic::task::message(Message::SelectAdapter(Some(path)));
}
}
Message::UpdatedAdapter(path, update) => {
Expand All @@ -381,7 +381,7 @@ impl Page {
&& existing.scanning == Active::Disabled =>
{
existing.scanning = Active::Enabling;
return cosmic::command::future(start_discovery(connection, path));
return cosmic::task::future(start_discovery(connection, path));
}
_ => {}
}
Expand Down Expand Up @@ -412,19 +412,20 @@ impl Page {
if let Some(connection) = self.connection.as_ref() {
let connection = connection.clone();
if let Some((path, adapter)) = self.get_selected_adapter_mut() {
let mut fut: Vec<Task<Message>> = vec![cosmic::command::future(
get_devices(connection.clone(), path.clone()),
)];
let mut fut: Vec<Task<Message>> = vec![cosmic::task::future(get_devices(
connection.clone(),
path.clone(),
))];
if adapter.enabled == Active::Enabled
&& adapter.scanning == Active::Disabled
{
fut.push(cosmic::command::future(start_discovery(
fut.push(cosmic::task::future(start_discovery(
connection,
path.clone(),
)));
}

return cosmic::command::batch(fut);
return cosmic::task::batch(fut);
}
} else {
tracing::warn!("No DBus connection ready");
Expand All @@ -440,7 +441,7 @@ impl Page {
let connection = connection.clone();
if let Some(device) = self.devices.get_mut(&path) {
device.enabled = Active::Disabling;
return cosmic::command::future(forget_device(connection, path.clone()));
return cosmic::task::future(forget_device(connection, path.clone()));
}
} else {
tracing::warn!("No DBus connection ready");
Expand All @@ -458,7 +459,7 @@ impl Page {
return cosmic::Task::none();
}
device.enabled = Active::Enabling;
return cosmic::command::future(connect_device(connection, path));
return cosmic::task::future(connect_device(connection, path));
}
} else {
tracing::warn!("No DBus connection ready");
Expand All @@ -474,7 +475,7 @@ impl Page {
return cosmic::Task::none();
}
device.enabled = Active::Disabling;
return cosmic::command::future(disconnect_device(connection, path));
return cosmic::task::future(disconnect_device(connection, path));
}
} else {
tracing::warn!("No DBus connection ready");
Expand Down
Loading

0 comments on commit 91daff1

Please sign in to comment.