Files
arboretum/packages/desktop/src/main/tray.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

41 lines
1.2 KiB
TypeScript

import { app, Menu, Tray, nativeImage } from 'electron';
import { join } from 'node:path';
import { isAutoStartEnabled, setAutoStart } from './autostart';
function iconPath(): string {
return app.isPackaged
? join(process.resourcesPath, 'icon.png')
: join(__dirname, '..', 'resources', 'icon.png');
}
/** Icône de barre système : ouvrir la fenêtre, basculer le lancement au login, quitter. */
export function createTray(opts: { show: () => void; quit: () => void }): Tray {
const image = nativeImage.createFromPath(iconPath());
const tray = new Tray(image.isEmpty() ? nativeImage.createEmpty() : image.resize({ width: 18, height: 18 }));
tray.setToolTip('Arboretum');
const buildMenu = (): void => {
tray.setContextMenu(
Menu.buildFromTemplate([
{ label: 'Open Arboretum', click: opts.show },
{ type: 'separator' },
{
label: 'Launch at login',
type: 'checkbox',
checked: isAutoStartEnabled(),
click: (item) => {
setAutoStart(item.checked);
buildMenu();
},
},
{ type: 'separator' },
{ label: 'Quit', click: opts.quit },
]),
);
};
buildMenu();
tray.on('click', opts.show);
return tray;
}