feat(desktop): tray + lancement au login + auto-update (C5)
tray.ts : icône de barre système (Ouvrir, bascule « Launch at login », Quitter). autostart.ts : login items (Windows/macOS) + fichier ~/.config/autostart/*.desktop (Linux). updater.ts : electron-updater (provider generic -> release Gitea), no-op en dev, actif Windows/Linux. main.ts : fermeture de fenêtre = réduction dans le tray, quit explicite via tray/menu, arrêt propre du daemon avant sortie. icon.png ajouté aux extraResources (tray en packagé). Vérifié : typecheck contre l'API Electron + electron-updater, bundle esbuild.
This commit is contained in:
44
packages/desktop/src/main/autostart.ts
Normal file
44
packages/desktop/src/main/autostart.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { app } from 'electron';
|
||||
import { existsSync, mkdirSync, unlinkSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { homedir } from 'node:os';
|
||||
|
||||
// Lancement au login. Windows/macOS : API Electron (login items). Linux : fichier .desktop dans
|
||||
// ~/.config/autostart (pas d'API Electron fiable pour l'autostart Linux).
|
||||
|
||||
function desktopFile(): string {
|
||||
return join(homedir(), '.config', 'autostart', 'arboretum.desktop');
|
||||
}
|
||||
|
||||
function desktopEntry(): string {
|
||||
const exec = process.env.APPIMAGE ?? app.getPath('exe');
|
||||
return `[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Arboretum
|
||||
Exec=${exec}
|
||||
Terminal=false
|
||||
X-GNOME-Autostart-enabled=true
|
||||
`;
|
||||
}
|
||||
|
||||
export function isAutoStartEnabled(): boolean {
|
||||
if (process.platform === 'linux') return existsSync(desktopFile());
|
||||
return app.getLoginItemSettings().openAtLogin;
|
||||
}
|
||||
|
||||
export function setAutoStart(enabled: boolean): void {
|
||||
if (process.platform === 'linux') {
|
||||
if (enabled) {
|
||||
mkdirSync(dirname(desktopFile()), { recursive: true });
|
||||
writeFileSync(desktopFile(), desktopEntry());
|
||||
} else {
|
||||
try {
|
||||
unlinkSync(desktopFile());
|
||||
} catch {
|
||||
/* déjà absent */
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
app.setLoginItemSettings({ openAtLogin: enabled });
|
||||
}
|
||||
Reference in New Issue
Block a user