45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { ElectronEgg } from 'ee-core';
|
|
import { Lifecycle } from './preload/lifecycle';
|
|
import { preload } from './preload';
|
|
import { app as electronApp } from 'electron';
|
|
|
|
function writeRuntimeLog(message: string): void {
|
|
try {
|
|
const baseDir = electronApp.isPackaged ? path.dirname(process.execPath) : process.cwd();
|
|
const logFile = path.join(baseDir, 'runtime.log');
|
|
const line = `[${new Date().toISOString()}] ${message}\n`;
|
|
fs.appendFileSync(logFile, line, 'utf8');
|
|
} catch (error) {
|
|
console.error('[runtime-log] write failed:', error);
|
|
}
|
|
}
|
|
|
|
process.on('uncaughtException', (error) => {
|
|
writeRuntimeLog(`uncaughtException: ${error?.stack || error}`);
|
|
});
|
|
|
|
process.on('unhandledRejection', (reason) => {
|
|
writeRuntimeLog(`unhandledRejection: ${String(reason)}`);
|
|
});
|
|
|
|
writeRuntimeLog('app bootstrap start');
|
|
|
|
// New app
|
|
const app = new ElectronEgg();
|
|
|
|
// Register lifecycle
|
|
const life = new Lifecycle();
|
|
app.register("ready", life.ready);
|
|
app.register("electron-app-ready", life.electronAppReady);
|
|
app.register("window-ready", life.windowReady);
|
|
app.register("before-close", life.beforeClose);
|
|
|
|
// Register preload
|
|
app.register("preload", preload);
|
|
|
|
// Run
|
|
app.run();
|
|
writeRuntimeLog('app bootstrap end');
|