mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
Add support for linux autostart
This commit is contained in:
parent
f512df309d
commit
75d26de581
@ -1,4 +1,6 @@
|
||||
import { app, ipcMain } from 'electron';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import { Main } from '../main';
|
||||
|
||||
@ -49,14 +51,10 @@ export class MessagingMain {
|
||||
this.main.trayMain.hideToTray();
|
||||
break;
|
||||
case 'addOpenAtLogin':
|
||||
if (process.platform !== 'linux') {
|
||||
app.setLoginItemSettings({openAtLogin: true});
|
||||
}
|
||||
this.addOpenAtLogin();
|
||||
break;
|
||||
case 'removeOpenAtLogin':
|
||||
if (process.platform !== 'linux') {
|
||||
app.setLoginItemSettings({openAtLogin: false});
|
||||
}
|
||||
this.removeOpenAtLogin();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -88,4 +86,36 @@ export class MessagingMain {
|
||||
lockNowTrayMenuItem.enabled = isAuthenticated && !isLocked;
|
||||
}
|
||||
}
|
||||
|
||||
private addOpenAtLogin() {
|
||||
if (process.platform === 'linux') {
|
||||
const data = `[Desktop Entry]
|
||||
Type=Application
|
||||
Version=${app.getVersion()}
|
||||
Name=Bitwarden
|
||||
Comment=Bitwarden startup script
|
||||
Exec=${app.getPath('exe')}
|
||||
StartupNotify=false
|
||||
Terminal=false`;
|
||||
|
||||
fs.writeFileSync(this.linuxStartupFile(), data);
|
||||
} else {
|
||||
app.setLoginItemSettings({openAtLogin: true});
|
||||
}
|
||||
}
|
||||
|
||||
private removeOpenAtLogin() {
|
||||
if (process.platform === 'linux') {
|
||||
const file = this.linuxStartupFile();
|
||||
if (fs.existsSync(file)) {
|
||||
fs.unlinkSync(file);
|
||||
}
|
||||
} else {
|
||||
app.setLoginItemSettings({openAtLogin: false});
|
||||
}
|
||||
}
|
||||
|
||||
private linuxStartupFile(): string {
|
||||
return path.join(app.getPath('home'), '.config', 'autostart', 'bitwarden.desktop');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user