fix(time): update time when resuming from sleep

This commit is contained in:
Jason Hansen 2025-07-08 08:58:08 -06:00 committed by GitHub
parent a7ed5c8813
commit 2e4460b423
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 0 deletions

1
Cargo.lock generated
View file

@ -1297,6 +1297,7 @@ dependencies = [
"i18n-embed-fl",
"icu",
"libcosmic",
"logind-zbus",
"once_cell",
"rust-embed",
"serde",

View file

@ -26,3 +26,4 @@ icu = { version = "1.5.0", features = [
serde.workspace = true
zbus.workspace = true
timedate-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" }
logind-zbus = "5.3.2"

View file

@ -25,6 +25,7 @@ use cosmic::{
},
Element, Task,
};
use logind_zbus::manager::ManagerProxy;
use once_cell::sync::Lazy;
use timedate_zbus::TimeDateProxy;
use tokio::{sync::watch, time};
@ -278,12 +279,40 @@ impl cosmic::Application for Window {
)
}
// Update the time when waking from sleep, so it doesn't need to wait until the next
// scheduled tick to update.
async fn wake_from_sleep(output: &mut mpsc::Sender<Message>) -> zbus::Result<()> {
let connection = zbus::Connection::system().await?;
let proxy = ManagerProxy::new(&connection).await?;
while let Some(property) = proxy.receive_prepare_for_sleep().await?.next().await {
let waking = !property.args()?.start();
if waking {
let _ = output.send(Message::Tick).await;
}
}
Ok(())
}
fn wake_from_sleep_subscription() -> Subscription<Message> {
Subscription::run_with_id(
"wake-from-suspend-sub",
stream::channel(1, |mut output| async move {
if let Err(err) = wake_from_sleep(&mut output).await {
tracing::error!(?err, "Failed to subscribe to wake-from-sleep signal");
}
}),
)
}
let show_seconds_rx = self.show_seconds_tx.subscribe();
Subscription::batch(vec![
rectangle_tracker_subscription(0).map(|e| Message::Rectangle(e.1)),
time_subscription(show_seconds_rx),
activation_token_subscription(0).map(Message::Token),
timezone_subscription(),
wake_from_sleep_subscription(),
self.core.watch_config(Self::APP_ID).map(|u| {
for err in u.errors {
tracing::error!(?err, "Error watching config");