1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 11:43:46 +00:00

[PM-9149] Enable "Timeout on System Lock" on Linux Desktop (#9645)

* Enable system lock detection on linux

* Fix order of vault timeout options

* Port to new plit core / napi desktop native crates

* Make unimplemented implementation panic for on_lock

* Remove unecessary String::from

* Update cargo lock

* Extract generation of vault timeout options
This commit is contained in:
Bernd Schoolmann
2024-07-25 17:09:03 +02:00
committed by GitHub
parent 5180ec44e0
commit 5cf29a655b
13 changed files with 718 additions and 32 deletions

View File

@@ -3,3 +3,4 @@ pub mod clipboard;
pub mod crypto;
pub mod error;
pub mod password;
pub mod powermonitor;

View File

@@ -0,0 +1,51 @@
use std::borrow::Cow;
use zbus::{Connection, MatchRule, export::futures_util::TryStreamExt};
struct ScreenLock {
interface: Cow<'static, str>,
path: Cow<'static, str>,
}
const SCREEN_LOCK_MONITORS: [ScreenLock; 2] = [
ScreenLock {
interface: Cow::Borrowed("org.gnome.ScreenSaver"),
path: Cow::Borrowed("/org/gnome/ScreenSaver"),
},
ScreenLock {
interface: Cow::Borrowed("org.freedesktop.ScreenSaver"),
path: Cow::Borrowed("/org/freedesktop/ScreenSaver"),
},
];
pub async fn on_lock(tx: tokio::sync::mpsc::Sender<()>) -> Result<(), Box<dyn std::error::Error>> {
let connection = Connection::session().await?;
let proxy = zbus::fdo::DBusProxy::new(&connection).await?;
for monitor in SCREEN_LOCK_MONITORS.iter() {
let match_rule = MatchRule::builder()
.msg_type(zbus::MessageType::Signal)
.interface(monitor.interface.clone())?
.member("ActiveChanged")?
.build();
proxy.add_match_rule(match_rule).await?;
}
tokio::spawn(async move {
while let Ok(Some(_)) = zbus::MessageStream::from(&connection).try_next().await {
tx.send(()).await.unwrap();
}
});
Ok(())
}
pub async fn is_lock_monitor_available() -> bool {
let connection = Connection::session().await.unwrap();
for monitor in SCREEN_LOCK_MONITORS {
let res = connection.call_method(Some(monitor.interface.clone()), monitor.path.clone(), Some(monitor.interface.clone()), "GetActive", &()).await;
if res.is_ok() {
return true;
}
}
false
}

View File

@@ -0,0 +1,5 @@
#[cfg_attr(target_os = "linux", path = "linux.rs")]
#[cfg_attr(target_os = "windows", path = "unimplemented.rs")]
#[cfg_attr(target_os = "macos", path = "unimplemented.rs")]
mod powermonitor;
pub use powermonitor::*;

View File

@@ -0,0 +1,7 @@
pub async fn on_lock(_: tokio::sync::mpsc::Sender<()>) -> Result<(), Box<dyn std::error::Error>> {
unimplemented!();
}
pub async fn is_lock_monitor_available() -> bool {
return false;
}