Compare commits
1 commit
master
...
theme-subs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc447cbfbe |
2 changed files with 76 additions and 53 deletions
|
|
@ -156,6 +156,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
fn subscription(&self) -> Subscription<Self::Message> {
|
fn subscription(&self) -> Subscription<Self::Message> {
|
||||||
let window_events = listen_with(|event, _| {
|
let window_events = listen_with(|event, _| {
|
||||||
match event {
|
match event {
|
||||||
|
|
@ -429,6 +430,11 @@ impl<T: Application> Cosmic<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::SystemThemeChange(keys, theme) => {
|
Message::SystemThemeChange(keys, theme) => {
|
||||||
|
let cur_is_dark = THEME.with(|t| t.borrow().theme_type.is_dark());
|
||||||
|
// Ignore updates if the current theme mode does not match.
|
||||||
|
if cur_is_dark != theme.cosmic().is_dark {
|
||||||
|
return iced::Command::none();
|
||||||
|
}
|
||||||
let cmd = self.app.system_theme_update(&keys, theme.cosmic());
|
let cmd = self.app.system_theme_update(&keys, theme.cosmic());
|
||||||
// Record the last-known system theme in event that the current theme is custom.
|
// Record the last-known system theme in event that the current theme is custom.
|
||||||
self.app.core_mut().system_theme = theme.clone();
|
self.app.core_mut().system_theme = theme.clone();
|
||||||
|
|
@ -472,6 +478,9 @@ impl<T: Application> Cosmic<T> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Message::SystemThemeModeChange(keys, mode) => {
|
Message::SystemThemeModeChange(keys, mode) => {
|
||||||
|
if !keys.contains(&"is_dark") {
|
||||||
|
return iced::Command::none();
|
||||||
|
}
|
||||||
if THEME.with(|t| match t.borrow().theme_type {
|
if THEME.with(|t| match t.borrow().theme_type {
|
||||||
ThemeType::System {
|
ThemeType::System {
|
||||||
theme: _,
|
theme: _,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use ashpd::desktop::settings::{ColorScheme, Contrast};
|
use ashpd::desktop::settings::{ColorScheme, Contrast};
|
||||||
use ashpd::desktop::Color;
|
use ashpd::desktop::Color;
|
||||||
use iced::futures::{self, select, FutureExt, SinkExt, StreamExt};
|
use iced::futures::{self, select, FutureExt, SinkExt, StreamExt};
|
||||||
use iced::Subscription;
|
|
||||||
use iced_futures::subscription;
|
use iced_futures::subscription;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
|
|
@ -15,11 +14,20 @@ pub enum Desktop {
|
||||||
pub fn desktop_settings() -> iced_futures::Subscription<Desktop> {
|
pub fn desktop_settings() -> iced_futures::Subscription<Desktop> {
|
||||||
subscription::channel(std::any::TypeId::of::<Desktop>(), 10, |mut tx| {
|
subscription::channel(std::any::TypeId::of::<Desktop>(), 10, |mut tx| {
|
||||||
async move {
|
async move {
|
||||||
|
let mut attempts = 0;
|
||||||
|
loop {
|
||||||
let Ok(settings) = ashpd::desktop::settings::Settings::new().await else {
|
let Ok(settings) = ashpd::desktop::settings::Settings::new().await else {
|
||||||
// wait forever
|
|
||||||
error!("Failed to create the settings proxy");
|
error!("Failed to create the settings proxy");
|
||||||
futures::future::pending::<()>().await;
|
#[cfg(feature = "tokio")]
|
||||||
unreachable!()
|
::tokio::time::sleep(::tokio::time::Duration::from_secs(2_u64.pow(attempts)))
|
||||||
|
.await;
|
||||||
|
#[cfg(not(feature = "tokio"))]
|
||||||
|
{
|
||||||
|
pending::<()>().await;
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
attempts += 1;
|
||||||
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
match settings.color_scheme().await {
|
match settings.color_scheme().await {
|
||||||
|
|
@ -46,6 +54,9 @@ pub fn desktop_settings() -> iced_futures::Subscription<Desktop> {
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
if color_scheme_stream.is_none() && contrast_stream.is_none() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let next_color_scheme = async {
|
let next_color_scheme = async {
|
||||||
if let Some(s) = color_scheme_stream.as_mut() {
|
if let Some(s) = color_scheme_stream.as_mut() {
|
||||||
return s.next().await;
|
return s.next().await;
|
||||||
|
|
@ -77,6 +88,9 @@ pub fn desktop_settings() -> iced_futures::Subscription<Desktop> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Reset the attempts counter if we successfully received a change
|
||||||
|
attempts = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue