[PM-38362] fix(powermonitor): Improve connection handling and remove unwraps (#20919)

* fix(powermonitor): Improve connection handling and remove unwraps

Potentially fix crashing issue for KDE

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>

* Increase method timeout from 2 to 25 seconds

* Format

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>

* Change timeout back to 2 seconds

---------

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
Co-authored-by: Addison Beck <github@addisonbeck.com>
This commit is contained in:
Zhiwei Liang 2026-06-15 14:09:28 -04:00 committed by GitHub
parent da6603de29
commit 5e88c4e90a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::{borrow::Cow, time::Duration};
use futures::TryStreamExt;
use zbus::{Connection, MatchRule};
use zbus::{connection::Builder, Connection, MatchRule};
struct ScreenLock {
interface: Cow<'static, str>,
@ -43,10 +43,18 @@ pub async fn on_lock(tx: tokio::sync::mpsc::Sender<()>) -> Result<(), Box<dyn st
Ok(())
}
// FIXME: Remove unwraps! They panic and terminate the whole application.
#[allow(clippy::unwrap_used)]
async fn lock_monitor_connection() -> zbus::Result<Connection> {
Builder::session()?
.method_timeout(Duration::from_secs(2))
.build()
.await
}
pub async fn is_lock_monitor_available() -> bool {
let connection = Connection::session().await.unwrap();
let connection = match lock_monitor_connection().await {
Ok(connection) => connection,
Err(_) => return false,
};
for monitor in SCREEN_LOCK_MONITORS {
let res = connection
.call_method(