Skip to content

Commit

Permalink
Implement autostart for flatpak
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Nov 15, 2024
1 parent d55c871 commit e6d02ef
Show file tree
Hide file tree
Showing 9 changed files with 491 additions and 14 deletions.
443 changes: 432 additions & 11 deletions apps/desktop/desktop_native/Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion apps/desktop/desktop_native/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ssh-key = { version = "0.6.6", default-features = false, features = [
"getrandom",
] }
bitwarden-russh = { git = "https://github.com/bitwarden/bitwarden-russh.git", branch = "km/pm-10098/clean-russh-implementation" }
tokio = { version = "=1.40.0", features = ["io-util", "sync", "macros", "net"] }
tokio = { version = "=1.41.0", features = ["io-util", "sync", "macros", "net"] }
tokio-stream = { version = "=0.1.15", features = ["net"] }
tokio-util = "=0.7.12"
thiserror = "=1.0.69"
Expand All @@ -60,6 +60,7 @@ rand_chacha = "=0.3.1"
pkcs8 = { version = "=0.10.2", features = ["alloc", "encryption", "pem"] }
rsa = "=0.9.6"
ed25519 = { version = "=2.2.3", features = ["pkcs8"] }
ashpd = "0.10.2"

[target.'cfg(windows)'.dependencies]
widestring = { version = "=1.1.0", optional = true }
Expand Down
22 changes: 22 additions & 0 deletions apps/desktop/desktop_native/core/src/autostart/linux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use anyhow::Result;
use ashpd::desktop::background::Background;

pub async fn set_autostart(autostart: bool, params: Vec<String>) -> Result<()> {
let request = Background::request()
.command(params)
.auto_start(autostart);

match request.send().await.and_then(|r| r.response()) {
Ok(response) => {
println!("enable autostart response {:?}", response);
return Ok(());
}
Err(err) => {
println!("error enabling autostart {}", err);
return Err(anyhow::anyhow!(
"error enabling autostart {}",
err
));
}
}
}
5 changes: 5 additions & 0 deletions apps/desktop/desktop_native/core/src/autostart/mod.rs
Original file line number Diff line number Diff line change
@@ -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 autostart;
pub use autostart::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub async fn set_autostart(autostart: bool, params: Vec<String>) -> Result<()> {
unimplemented!();
}
3 changes: 2 additions & 1 deletion apps/desktop/desktop_native/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ pub mod process_isolation;
#[cfg(feature = "sys")]
pub mod powermonitor;
#[cfg(feature = "sys")]

pub mod ssh_agent;
#[cfg(feature = "sys")]
pub mod autostart;
2 changes: 1 addition & 1 deletion apps/desktop/desktop_native/napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ anyhow = "=1.0.93"
desktop_core = { path = "../core" }
napi = { version = "=2.16.13", features = ["async"] }
napi-derive = "=2.16.12"
tokio = { version = "=1.40.0" }
tokio = { version = "=1.41.0" }
tokio-util = "=0.7.12"
tokio-stream = "=0.1.15"

Expand Down
4 changes: 4 additions & 0 deletions apps/desktop/desktop_native/napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export declare namespace passwords {
export declare namespace biometrics {
export function prompt(hwnd: Buffer, message: string): Promise<boolean>
export function available(): Promise<boolean>
export function needsSetup(): Promise<boolean>
export function setBiometricSecret(service: string, account: string, secret: string, keyMaterial: KeyMaterial | undefined | null, ivB64: string): Promise<string>
export function getBiometricSecret(service: string, account: string, keyMaterial?: KeyMaterial | undefined | null): Promise<string>
/**
Expand Down Expand Up @@ -122,3 +123,6 @@ export declare namespace ipc {
send(message: string): number
}
}
export declare namespace autostart {
export function setAutostart(autostart: boolean, params: Array<string>): Promise<void>
}
20 changes: 20 additions & 0 deletions apps/desktop/desktop_native/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ pub mod biometrics {
.map_err(|e| napi::Error::from_reason(e.to_string()))
}

#[napi]
async fn needs_setup() -> napi::Result<bool> {
Biometric::needs_setup()
.await
.map_err(|e| napi::Error::from_reason(e.to_string()))
}

#[napi]
pub async fn set_biometric_secret(
service: String,
Expand Down Expand Up @@ -516,3 +523,16 @@ pub mod ipc {
}
}
}

#[napi]
pub mod autostart {
#[napi]
pub async fn set_autostart(autostart: bool, params: Vec<String>) -> napi::Result<()> {
desktop_core::autostart::set_autostart(autostart, params)
.await
.map_err(|e| {
napi::Error::from_reason(format!("Error setting autostart - {e} - {e:?}"))
})
}
}

0 comments on commit e6d02ef

Please sign in to comment.