Files
arboretum/packages/desktop/src/main/autostart.ts
Johan LEROY ccbc1b9e4e
Some checks failed
CI / Build & test (Node 24) (push) Has been cancelled
CI / Pack & boot smoke (Node 22) (push) Has been cancelled
CI / No em/en dashes (push) Has been cancelled
CI / Build & test (Node 22) (push) Has been cancelled
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.
2026-07-17 18:04:36 +02:00

45 lines
1.2 KiB
TypeScript

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 });
}