66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import { app, BrowserWindow } from 'electron';
|
|
import { cleanupLinuxScreenShareAudioRouting } from '../audio/linux-screen-share-routing';
|
|
import { initializeDesktopUpdater, shutdownDesktopUpdater } from '../update/desktop-updater';
|
|
import { synchronizeAutoStartSetting } from './auto-start';
|
|
import {
|
|
initializeDatabase,
|
|
destroyDatabase,
|
|
getDataSource
|
|
} from '../db/database';
|
|
import {
|
|
createWindow,
|
|
getDockIconPath,
|
|
getMainWindow,
|
|
prepareWindowForAppQuit,
|
|
showMainWindow
|
|
} 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 synchronizeAutoStartSetting();
|
|
initializeDesktopUpdater();
|
|
await createWindow();
|
|
|
|
app.on('activate', () => {
|
|
if (getMainWindow()) {
|
|
void showMainWindow();
|
|
return;
|
|
}
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0)
|
|
void createWindow();
|
|
});
|
|
});
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin')
|
|
app.quit();
|
|
});
|
|
|
|
app.on('before-quit', async (event) => {
|
|
prepareWindowForAppQuit();
|
|
|
|
if (getDataSource()?.isInitialized) {
|
|
event.preventDefault();
|
|
shutdownDesktopUpdater();
|
|
await cleanupLinuxScreenShareAudioRouting();
|
|
await destroyDatabase();
|
|
app.quit();
|
|
}
|
|
});
|
|
}
|