fix(time): update time when resuming from sleep
This commit is contained in:
parent
a7ed5c8813
commit
2e4460b423
3 changed files with 31 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1297,6 +1297,7 @@ dependencies = [
|
||||||
"i18n-embed-fl",
|
"i18n-embed-fl",
|
||||||
"icu",
|
"icu",
|
||||||
"libcosmic",
|
"libcosmic",
|
||||||
|
"logind-zbus",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,4 @@ icu = { version = "1.5.0", features = [
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
timedate-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
timedate-zbus = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
||||||
|
logind-zbus = "5.3.2"
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ use cosmic::{
|
||||||
},
|
},
|
||||||
Element, Task,
|
Element, Task,
|
||||||
};
|
};
|
||||||
|
use logind_zbus::manager::ManagerProxy;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use timedate_zbus::TimeDateProxy;
|
use timedate_zbus::TimeDateProxy;
|
||||||
use tokio::{sync::watch, time};
|
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();
|
let show_seconds_rx = self.show_seconds_tx.subscribe();
|
||||||
Subscription::batch(vec![
|
Subscription::batch(vec![
|
||||||
rectangle_tracker_subscription(0).map(|e| Message::Rectangle(e.1)),
|
rectangle_tracker_subscription(0).map(|e| Message::Rectangle(e.1)),
|
||||||
time_subscription(show_seconds_rx),
|
time_subscription(show_seconds_rx),
|
||||||
activation_token_subscription(0).map(Message::Token),
|
activation_token_subscription(0).map(Message::Token),
|
||||||
timezone_subscription(),
|
timezone_subscription(),
|
||||||
|
wake_from_sleep_subscription(),
|
||||||
self.core.watch_config(Self::APP_ID).map(|u| {
|
self.core.watch_config(Self::APP_ID).map(|u| {
|
||||||
for err in u.errors {
|
for err in u.errors {
|
||||||
tracing::error!(?err, "Error watching config");
|
tracing::error!(?err, "Error watching config");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue