1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-04 09:33:27 +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

@@ -41,3 +41,7 @@ export namespace clipboards {
export function read(): Promise<string>
export function write(text: string, password: boolean): Promise<void>
}
export namespace powermonitors {
export function onLock(callback: (err: Error | null, ) => any): Promise<void>
export function isLockMonitorAvailable(): Promise<boolean>
}

View File

@@ -206,8 +206,9 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}
const { passwords, biometrics, clipboards } = nativeBinding
const { passwords, biometrics, clipboards, powermonitors } = nativeBinding
module.exports.passwords = passwords
module.exports.biometrics = biometrics
module.exports.clipboards = clipboards
module.exports.powermonitors = powermonitors

View File

@@ -1,6 +1,5 @@
#[macro_use]
extern crate napi_derive;
#[napi]
pub mod passwords {
/// Fetch the stored password from the keychain.
@@ -142,3 +141,26 @@ pub mod clipboards {
.map_err(|e| napi::Error::from_reason(e.to_string()))
}
}
#[napi]
pub mod powermonitors {
use napi::{threadsafe_function::{ErrorStrategy::CalleeHandled, ThreadsafeFunction, ThreadsafeFunctionCallMode}, tokio};
#[napi]
pub async fn on_lock(callback: ThreadsafeFunction<(), CalleeHandled>) -> napi::Result<()> {
let (tx, mut rx) = tokio::sync::mpsc::channel::<()>(32);
desktop_core::powermonitor::on_lock(tx).await.map_err(|e| napi::Error::from_reason(e.to_string()))?;
tokio::spawn(async move {
while let Some(message) = rx.recv().await {
callback.call(Ok(message.into()), ThreadsafeFunctionCallMode::NonBlocking);
}
});
Ok(())
}
#[napi]
pub async fn is_lock_monitor_available() -> napi::Result<bool> {
Ok(desktop_core::powermonitor::is_lock_monitor_available().await)
}
}