2026-03-20 19:59:20 +02:00
|
|
|
import { app, BrowserWindow, shell, ipcMain, Menu } from 'electron';
|
2026-03-20 19:44:48 +02:00
|
|
|
import { registerGlobalErrorHandlers, showErrorDialog } from './modules/errors';
|
2026-03-20 19:55:44 +02:00
|
|
|
import { startNextServer } from './modules/server';
|
|
|
|
|
import { createMainWindow } from './modules/window';
|
|
|
|
|
import { setupDeepLinks, handlePendingDeepLink } from './modules/deep-links';
|
2026-03-20 19:59:20 +02:00
|
|
|
import { setupAutoUpdater } from './modules/auto-updater';
|
2026-03-17 16:22:14 +02:00
|
|
|
|
2026-03-20 19:44:48 +02:00
|
|
|
registerGlobalErrorHandlers();
|
2026-03-18 19:49:50 +02:00
|
|
|
|
2026-03-20 19:55:44 +02:00
|
|
|
if (!setupDeepLinks()) {
|
|
|
|
|
app.quit();
|
|
|
|
|
}
|
2026-03-17 16:22:14 +02:00
|
|
|
|
|
|
|
|
// IPC handlers
|
|
|
|
|
ipcMain.on('open-external', (_event, url: string) => {
|
2026-03-18 20:58:49 +02:00
|
|
|
try {
|
|
|
|
|
const parsed = new URL(url);
|
|
|
|
|
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
|
|
|
|
|
shell.openExternal(url);
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
// invalid URL — ignore
|
|
|
|
|
}
|
2026-03-17 16:22:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ipcMain.handle('get-app-version', () => {
|
|
|
|
|
return app.getVersion();
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-18 20:10:30 +02:00
|
|
|
function setupMenu() {
|
|
|
|
|
const isMac = process.platform === 'darwin';
|
|
|
|
|
const template: Electron.MenuItemConstructorOptions[] = [
|
|
|
|
|
...(isMac ? [{ role: 'appMenu' as const }] : []),
|
|
|
|
|
{ role: 'fileMenu' as const },
|
|
|
|
|
{ role: 'editMenu' as const },
|
|
|
|
|
{ role: 'viewMenu' as const },
|
|
|
|
|
{ role: 'windowMenu' as const },
|
|
|
|
|
];
|
|
|
|
|
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 16:22:14 +02:00
|
|
|
// App lifecycle
|
|
|
|
|
app.whenReady().then(async () => {
|
2026-03-18 20:10:30 +02:00
|
|
|
setupMenu();
|
2026-03-18 19:49:59 +02:00
|
|
|
try {
|
|
|
|
|
await startNextServer();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
showErrorDialog('Failed to start SurfSense', error);
|
|
|
|
|
setTimeout(() => app.quit(), 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-20 19:50:50 +02:00
|
|
|
createMainWindow();
|
2026-03-19 20:20:26 +02:00
|
|
|
setupAutoUpdater();
|
2026-03-17 16:22:14 +02:00
|
|
|
|
2026-03-20 19:55:44 +02:00
|
|
|
handlePendingDeepLink();
|
2026-03-17 17:32:28 +02:00
|
|
|
|
2026-03-17 16:22:14 +02:00
|
|
|
app.on('activate', () => {
|
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
2026-03-20 19:50:50 +02:00
|
|
|
createMainWindow();
|
2026-03-17 16:22:14 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
|
app.quit();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on('will-quit', () => {
|
2026-03-18 17:51:47 +02:00
|
|
|
// Server runs in-process — no child process to kill
|
2026-03-17 16:22:14 +02:00
|
|
|
});
|