feat: add subscription method for Page trait
This commit is contained in:
parent
e810acd8f1
commit
6701a634b7
4 changed files with 49 additions and 20 deletions
|
|
@ -42,8 +42,6 @@ use cosmic::{
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
use cosmic_panel_config::CosmicPanelConfig;
|
use cosmic_panel_config::CosmicPanelConfig;
|
||||||
use cosmic_settings_page::{self as page, section};
|
use cosmic_settings_page::{self as page, section};
|
||||||
#[cfg(feature = "page-accessibility")]
|
|
||||||
use cosmic_settings_subscriptions::accessibility::subscription as a11y_subscription;
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
use desktop::{
|
use desktop::{
|
||||||
dock,
|
dock,
|
||||||
|
|
@ -290,7 +288,9 @@ impl cosmic::Application for SettingsApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
Subscription::batch(vec![
|
let page = &self.pages.page[self.active_page];
|
||||||
|
|
||||||
|
let subscriptions = vec![
|
||||||
#[cfg(feature = "ashpd")]
|
#[cfg(feature = "ashpd")]
|
||||||
crate::subscription::daytime().map(|daytime| {
|
crate::subscription::daytime().map(|daytime| {
|
||||||
Message::PageMessage(pages::Message::Appearance(appearance::Message::Daytime(
|
Message::PageMessage(pages::Message::Appearance(appearance::Message::Daytime(
|
||||||
|
|
@ -313,6 +313,7 @@ impl cosmic::Application for SettingsApp {
|
||||||
// Watch for changes to installed desktop entries
|
// Watch for changes to installed desktop entries
|
||||||
desktop_files(0).map(|_| Message::DesktopInfo),
|
desktop_files(0).map(|_| Message::DesktopInfo),
|
||||||
// Watch for configuration changes to the panel.
|
// Watch for configuration changes to the panel.
|
||||||
|
// TODO: This should only be active when the panel page is active.
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
self.core()
|
self.core()
|
||||||
.watch_config::<CosmicPanelConfig>("com.system76.CosmicPanel.Panel")
|
.watch_config::<CosmicPanelConfig>("com.system76.CosmicPanel.Panel")
|
||||||
|
|
@ -323,6 +324,7 @@ impl cosmic::Application for SettingsApp {
|
||||||
|
|
||||||
Message::PanelConfig(update.config)
|
Message::PanelConfig(update.config)
|
||||||
}),
|
}),
|
||||||
|
// TODO: This should only be active when the dock page is active.
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
self.core()
|
self.core()
|
||||||
.watch_config::<CosmicPanelConfig>("com.system76.CosmicPanel.Dock")
|
.watch_config::<CosmicPanelConfig>("com.system76.CosmicPanel.Dock")
|
||||||
|
|
@ -333,21 +335,10 @@ impl cosmic::Application for SettingsApp {
|
||||||
|
|
||||||
Message::PanelConfig(update.config)
|
Message::PanelConfig(update.config)
|
||||||
}),
|
}),
|
||||||
// Watch for state changes from the cosmic-bg session service.
|
page.subscription(self.core()).map(Message::PageMessage),
|
||||||
self.core()
|
];
|
||||||
.watch_state::<cosmic_bg_config::state::State>(cosmic_bg_config::NAME)
|
|
||||||
.map(|update| {
|
Subscription::batch(subscriptions)
|
||||||
Message::PageMessage(pages::Message::DesktopWallpaper(
|
|
||||||
pages::desktop::wallpaper::Message::UpdateState(update.config),
|
|
||||||
))
|
|
||||||
}),
|
|
||||||
#[cfg(feature = "page-accessibility")]
|
|
||||||
a11y_subscription().map(|m| {
|
|
||||||
Message::PageMessage(pages::Message::Accessibility(
|
|
||||||
pages::accessibility::Message::DBusUpdate(m),
|
|
||||||
))
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ use cosmic_settings_page::{
|
||||||
self as page, Insert,
|
self as page, Insert,
|
||||||
section::{self, Section},
|
section::{self, Section},
|
||||||
};
|
};
|
||||||
use cosmic_settings_subscriptions::accessibility::{DBusRequest, DBusUpdate};
|
use cosmic_settings_subscriptions::accessibility::{
|
||||||
|
DBusRequest, DBusUpdate, subscription as a11y_subscription,
|
||||||
|
};
|
||||||
use cosmic_settings_subscriptions::cosmic_a11y_manager;
|
use cosmic_settings_subscriptions::cosmic_a11y_manager;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use slotmap::SlotMap;
|
use slotmap::SlotMap;
|
||||||
|
|
@ -88,6 +90,18 @@ pub enum Message {
|
||||||
ScreenReaderEnabled(bool),
|
ScreenReaderEnabled(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Message> for crate::pages::Message {
|
||||||
|
fn from(message: Message) -> Self {
|
||||||
|
crate::pages::Message::Accessibility(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Message> for crate::app::Message {
|
||||||
|
fn from(message: Message) -> Self {
|
||||||
|
crate::app::Message::PageMessage(message.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl page::Page<crate::pages::Message> for Page {
|
impl page::Page<crate::pages::Message> for Page {
|
||||||
fn set_id(&mut self, entity: page::Entity) {
|
fn set_id(&mut self, entity: page::Entity) {
|
||||||
self.entity = entity;
|
self.entity = entity;
|
||||||
|
|
@ -150,6 +164,13 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
|
|
||||||
cosmic::Task::none()
|
cosmic::Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn subscription(
|
||||||
|
&self,
|
||||||
|
_core: &cosmic::Core,
|
||||||
|
) -> cosmic::iced::Subscription<crate::pages::Message> {
|
||||||
|
a11y_subscription().map(|m| super::Message::Accessibility(Message::DBusUpdate(m)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl page::AutoBind<crate::pages::Message> for Page {
|
impl page::AutoBind<crate::pages::Message> for Page {
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,17 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
.title(fl!("color-picker"))
|
.title(fl!("color-picker"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Watch for state changes from the cosmic-bg session service.
|
||||||
|
fn subscription(
|
||||||
|
&self,
|
||||||
|
core: &cosmic::Core,
|
||||||
|
) -> cosmic::iced::Subscription<crate::pages::Message> {
|
||||||
|
core.watch_state::<cosmic_bg_config::state::State>(cosmic_bg_config::NAME)
|
||||||
|
.map(|update| {
|
||||||
|
crate::pages::Message::DesktopWallpaper(Message::UpdateState(update.config))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl page::AutoBind<crate::pages::Message> for Page {}
|
impl page::AutoBind<crate::pages::Message> for Page {}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ mod binder;
|
||||||
pub use binder::{AutoBind, Binder};
|
pub use binder::{AutoBind, Binder};
|
||||||
|
|
||||||
mod insert;
|
mod insert;
|
||||||
use cosmic::{Element, Task, app::ContextDrawer};
|
use cosmic::{Element, Task, app::ContextDrawer, iced::Subscription};
|
||||||
use downcast_rs::{Downcast, impl_downcast};
|
use downcast_rs::{Downcast, impl_downcast};
|
||||||
pub use insert::Insert;
|
pub use insert::Insert;
|
||||||
|
|
||||||
|
|
@ -89,6 +89,12 @@ pub trait Page<Message: Clone + 'static>: Downcast {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Subscription unique to the page when it is active.
|
||||||
|
#[inline]
|
||||||
|
fn subscription(&self, _core: &cosmic::Core) -> Subscription<Message> {
|
||||||
|
Subscription::none()
|
||||||
|
}
|
||||||
|
|
||||||
/// Assigns the entity ID of the page to the page.
|
/// Assigns the entity ID of the page to the page.
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue