mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 13:23:34 +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:
1
apps/desktop/desktop_native/Cargo.lock
generated
1
apps/desktop/desktop_native/Cargo.lock
generated
@@ -863,6 +863,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"arboard",
|
||||
"argon2",
|
||||
"ashpd",
|
||||
"base64",
|
||||
"bitwarden-russh",
|
||||
"byteorder",
|
||||
|
||||
@@ -13,6 +13,7 @@ aes = "=0.8.4"
|
||||
anyhow = "=1.0.94"
|
||||
arboard = { version = "=3.5.0", default-features = false }
|
||||
argon2 = "=0.5.3"
|
||||
ashpd = "=0.11.0"
|
||||
base64 = "=0.22.1"
|
||||
bindgen = "=0.71.1"
|
||||
bitwarden-russh = { git = "https://github.com/bitwarden/bitwarden-russh.git", rev = "3d48f140fd506412d186203238993163a8c4e536" }
|
||||
|
||||
@@ -85,6 +85,7 @@ desktop_objc = { path = "../objc" }
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
oo7 = { workspace = true }
|
||||
libc = { workspace = true }
|
||||
ashpd = { workspace = true }
|
||||
|
||||
zbus = { workspace = true, optional = true }
|
||||
zbus_polkit = { workspace = true, optional = true }
|
||||
|
||||
21
apps/desktop/desktop_native/core/src/autostart/linux.rs
Normal file
21
apps/desktop/desktop_native/core/src/autostart/linux.rs
Normal 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))
|
||||
}
|
||||
}
|
||||
}
|
||||
5
apps/desktop/desktop_native/core/src/autostart/mod.rs
Normal file
5
apps/desktop/desktop_native/core/src/autostart/mod.rs
Normal 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::*;
|
||||
@@ -0,0 +1,5 @@
|
||||
use anyhow::Result;
|
||||
|
||||
pub async fn set_autostart(_autostart: bool, _params: Vec<String>) -> Result<()> {
|
||||
unimplemented!();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod autofill;
|
||||
pub mod autostart;
|
||||
pub mod biometric;
|
||||
pub mod clipboard;
|
||||
pub mod crypto;
|
||||
|
||||
3
apps/desktop/desktop_native/napi/index.d.ts
vendored
3
apps/desktop/desktop_native/napi/index.d.ts
vendored
@@ -111,6 +111,9 @@ export declare namespace ipc {
|
||||
send(message: string): number
|
||||
}
|
||||
}
|
||||
export declare namespace autostart {
|
||||
export function setAutostart(autostart: boolean, params: Array<string>): Promise<void>
|
||||
}
|
||||
export declare namespace autofill {
|
||||
export function runCommand(value: string): Promise<string>
|
||||
export const enum UserVerification {
|
||||
|
||||
@@ -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]
|
||||
pub mod autofill {
|
||||
use desktop_core::ipc::server::{Message, MessageType};
|
||||
|
||||
@@ -6,8 +6,11 @@ import * as path from "path";
|
||||
import { app, ipcMain } from "electron";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { autostart } from "@bitwarden/desktop-napi";
|
||||
|
||||
import { Main } from "../main";
|
||||
import { DesktopSettingsService } from "../platform/services/desktop-settings.service";
|
||||
import { isFlatpak } from "../utils";
|
||||
|
||||
import { MenuUpdateRequest } from "./menu/menu.updater";
|
||||
|
||||
@@ -122,20 +125,24 @@ export class MessagingMain {
|
||||
|
||||
private addOpenAtLogin() {
|
||||
if (process.platform === "linux") {
|
||||
if (isFlatpak()) {
|
||||
autostart.setAutostart(true, []).catch((e) => {});
|
||||
} else {
|
||||
const data = `[Desktop Entry]
|
||||
Type=Application
|
||||
Version=${app.getVersion()}
|
||||
Name=Bitwarden
|
||||
Comment=Bitwarden startup script
|
||||
Exec=${app.getPath("exe")}
|
||||
StartupNotify=false
|
||||
Terminal=false`;
|
||||
Type=Application
|
||||
Version=${app.getVersion()}
|
||||
Name=Bitwarden
|
||||
Comment=Bitwarden startup script
|
||||
Exec=${app.getPath("exe")}
|
||||
StartupNotify=false
|
||||
Terminal=false`;
|
||||
|
||||
const dir = path.dirname(this.linuxStartupFile());
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
fs.writeFileSync(this.linuxStartupFile(), data);
|
||||
}
|
||||
} else {
|
||||
app.setLoginItemSettings({ openAtLogin: true });
|
||||
}
|
||||
@@ -143,9 +150,13 @@ Terminal=false`;
|
||||
|
||||
private removeOpenAtLogin() {
|
||||
if (process.platform === "linux") {
|
||||
if (isFlatpak()) {
|
||||
autostart.setAutostart(false, []).catch((e) => {});
|
||||
} else {
|
||||
if (fs.existsSync(this.linuxStartupFile())) {
|
||||
fs.unlinkSync(this.linuxStartupFile());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
app.setLoginItemSettings({ openAtLogin: false });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user