mirror of
https://github.com/bitwarden/clients.git
synced 2026-07-21 21:17:06 +08:00
[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:
parent
da6603de29
commit
5e88c4e90a
@ -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(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user