import { app, BrowserWindow } from 'electron'; import { cleanupLinuxScreenShareAudioRouting } from '../audio/linux-screen-share-routing'; import { initializeDatabase, destroyDatabase, getDataSource } from '../db/database'; import { createWindow, getDockIconPath } from '../window/create-window'; import { setupCqrsHandlers, setupSystemHandlers, setupWindowControlHandlers } from '../ipc'; export function registerAppLifecycle(): void { app.whenReady().then(async () => { const dockIconPath = getDockIconPath(); if (process.platform === 'darwin' && dockIconPath) app.dock?.setIcon(dockIconPath); await initializeDatabase(); setupCqrsHandlers(); setupWindowControlHandlers(); setupSystemHandlers(); await createWindow(); app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); }); }); app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit(); }); app.on('before-quit', async (event) => { if (getDataSource()?.isInitialized) { event.preventDefault(); await cleanupLinuxScreenShareAudioRouting(); await destroyDatabase(); app.quit(); } }); }