feat(desktop): add error dialog and global exception handlers

This commit is contained in:
CREDO23 2026-03-18 19:49:50 +02:00
parent c6f3218085
commit 9434965803

View file

@ -1,7 +1,37 @@
import { app, BrowserWindow, shell, ipcMain, session } from 'electron';
import { app, BrowserWindow, shell, ipcMain, session, dialog, clipboard } from 'electron';
import path from 'path';
import { getPort } from 'get-port-please';
function showErrorDialog(title: string, error: unknown): void {
const err = error instanceof Error ? error : new Error(String(error));
console.error(`${title}:`, err);
if (app.isReady()) {
const detail = err.stack || err.message;
const buttonIndex = dialog.showMessageBoxSync({
type: 'error',
buttons: ['OK', process.platform === 'darwin' ? 'Copy Error' : 'Copy error'],
defaultId: 0,
noLink: true,
message: title,
detail,
});
if (buttonIndex === 1) {
clipboard.writeText(`${title}\n${detail}`);
}
} else {
dialog.showErrorBox(title, err.stack || err.message);
}
}
process.on('uncaughtException', (error) => {
showErrorDialog('Unhandled Error', error);
});
process.on('unhandledRejection', (reason) => {
showErrorDialog('Unhandled Promise Rejection', reason);
});
const isDev = !app.isPackaged;
let mainWindow: BrowserWindow | null = null;
let deepLinkUrl: string | null = null;