1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 21:33:27 +00:00

[BEEEP/PM-8492] Add autostart for flatpak (#12016)

* Add autostart for flatpak via ashpd

* Fix clippy errors

* Cargo fmt

* Fix clippy
This commit is contained in:
Bernd Schoolmann
2025-05-26 00:30:52 +02:00
committed by GitHub
parent 23f4af6984
commit 04ed114e0e
10 changed files with 73 additions and 14 deletions

View File

@@ -863,6 +863,7 @@ dependencies = [
"anyhow", "anyhow",
"arboard", "arboard",
"argon2", "argon2",
"ashpd",
"base64", "base64",
"bitwarden-russh", "bitwarden-russh",
"byteorder", "byteorder",

View File

@@ -13,6 +13,7 @@ aes = "=0.8.4"
anyhow = "=1.0.94" anyhow = "=1.0.94"
arboard = { version = "=3.5.0", default-features = false } arboard = { version = "=3.5.0", default-features = false }
argon2 = "=0.5.3" argon2 = "=0.5.3"
ashpd = "=0.11.0"
base64 = "=0.22.1" base64 = "=0.22.1"
bindgen = "=0.71.1" bindgen = "=0.71.1"
bitwarden-russh = { git = "https://github.com/bitwarden/bitwarden-russh.git", rev = "3d48f140fd506412d186203238993163a8c4e536" } bitwarden-russh = { git = "https://github.com/bitwarden/bitwarden-russh.git", rev = "3d48f140fd506412d186203238993163a8c4e536" }

View File

@@ -85,6 +85,7 @@ desktop_objc = { path = "../objc" }
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
oo7 = { workspace = true } oo7 = { workspace = true }
libc = { workspace = true } libc = { workspace = true }
ashpd = { workspace = true }
zbus = { workspace = true, optional = true } zbus = { workspace = true, optional = true }
zbus_polkit = { workspace = true, optional = true } zbus_polkit = { workspace = true, optional = true }

View File

@@ -0,0 +1,21 @@
use anyhow::Result;
use ashpd::desktop::background::Background;
pub async fn set_autostart(autostart: bool, params: Vec<String>) -> Result<()> {
let request = if params.is_empty() {
Background::request().auto_start(autostart)
} else {
Background::request().command(params).auto_start(autostart)
};
match request.send().await.and_then(|r| r.response()) {
Ok(response) => {
println!("[ASHPD] Autostart enabled: {:?}", response);
Ok(())
}
Err(err) => {
println!("[ASHPD] Error enabling autostart: {}", err);
Err(anyhow::anyhow!("error enabling autostart {}", err))
}
}
}

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 autostart_impl;
pub use autostart_impl::*;

View File

@@ -0,0 +1,5 @@
use anyhow::Result;
pub async fn set_autostart(_autostart: bool, _params: Vec<String>) -> Result<()> {
unimplemented!();
}

View File

@@ -1,4 +1,5 @@
pub mod autofill; pub mod autofill;
pub mod autostart;
pub mod biometric; pub mod biometric;
pub mod clipboard; pub mod clipboard;
pub mod crypto; pub mod crypto;

View File

@@ -111,6 +111,9 @@ export declare namespace ipc {
send(message: string): number send(message: string): number
} }
} }
export declare namespace autostart {
export function setAutostart(autostart: boolean, params: Array<string>): Promise<void>
}
export declare namespace autofill { export declare namespace autofill {
export function runCommand(value: string): Promise<string> export function runCommand(value: string): Promise<string>
export const enum UserVerification { export const enum UserVerification {

View File

@@ -477,6 +477,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:?}")))
}
}
#[napi] #[napi]
pub mod autofill { pub mod autofill {
use desktop_core::ipc::server::{Message, MessageType}; use desktop_core::ipc::server::{Message, MessageType};

View File

@@ -6,8 +6,11 @@ import * as path from "path";
import { app, ipcMain } from "electron"; import { app, ipcMain } from "electron";
import { firstValueFrom } from "rxjs"; import { firstValueFrom } from "rxjs";
import { autostart } from "@bitwarden/desktop-napi";
import { Main } from "../main"; import { Main } from "../main";
import { DesktopSettingsService } from "../platform/services/desktop-settings.service"; import { DesktopSettingsService } from "../platform/services/desktop-settings.service";
import { isFlatpak } from "../utils";
import { MenuUpdateRequest } from "./menu/menu.updater"; import { MenuUpdateRequest } from "./menu/menu.updater";
@@ -122,20 +125,24 @@ export class MessagingMain {
private addOpenAtLogin() { private addOpenAtLogin() {
if (process.platform === "linux") { if (process.platform === "linux") {
const data = `[Desktop Entry] if (isFlatpak()) {
Type=Application autostart.setAutostart(true, []).catch((e) => {});
Version=${app.getVersion()} } else {
Name=Bitwarden const data = `[Desktop Entry]
Comment=Bitwarden startup script Type=Application
Exec=${app.getPath("exe")} Version=${app.getVersion()}
StartupNotify=false Name=Bitwarden
Terminal=false`; Comment=Bitwarden startup script
Exec=${app.getPath("exe")}
StartupNotify=false
Terminal=false`;
const dir = path.dirname(this.linuxStartupFile()); const dir = path.dirname(this.linuxStartupFile());
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
fs.mkdirSync(dir); fs.mkdirSync(dir);
}
fs.writeFileSync(this.linuxStartupFile(), data);
} }
fs.writeFileSync(this.linuxStartupFile(), data);
} else { } else {
app.setLoginItemSettings({ openAtLogin: true }); app.setLoginItemSettings({ openAtLogin: true });
} }
@@ -143,8 +150,12 @@ Terminal=false`;
private removeOpenAtLogin() { private removeOpenAtLogin() {
if (process.platform === "linux") { if (process.platform === "linux") {
if (fs.existsSync(this.linuxStartupFile())) { if (isFlatpak()) {
fs.unlinkSync(this.linuxStartupFile()); autostart.setAutostart(false, []).catch((e) => {});
} else {
if (fs.existsSync(this.linuxStartupFile())) {
fs.unlinkSync(this.linuxStartupFile());
}
} }
} else { } else {
app.setLoginItemSettings({ openAtLogin: false }); app.setLoginItemSettings({ openAtLogin: false });