mirror of
https://github.com/dream-pep/koring-launcher.git
synced 2026-09-12 05:45:18 +08:00
Introduce crash monitoring and an OOBE onboarding flow. Adds a crash logger (koring-crash.log), crash-monitor handler/window, preload-crash bridge, crash UI (crash.html, src/crash.tsx, pages/crash) and a debug page. Main process now sets up crash listeners, startup checks (first-launch, .minecraft), and a config reset/factory-reset that removes Koring.yml, koring-auth.json and background cache and can relaunch the app. Exposes config preloading to renderer, adds OOBE pages/layout, confirm dialog store/UI, trims Silk renderer settings, bumps version to 1.0.1 and adds motion dependency, and registers crash.html in Vite. Various related type and config updates included.
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import electron from 'electron';
|
|
const { app } = electron;
|
|
|
|
const LOG_FILE = 'koring-crash.log';
|
|
const MAX_LINES = 1000;
|
|
|
|
function logPath(): string {
|
|
if (app.isPackaged) {
|
|
return path.join(path.dirname(app.getPath('exe')), LOG_FILE);
|
|
}
|
|
return path.join(__dirname, '..', LOG_FILE);
|
|
}
|
|
|
|
export interface CrashEntry {
|
|
timestamp: string;
|
|
type: 'renderer-gone' | 'unresponsive' | 'uncaught-exception' | 'unhandled-rejection' | 'child-process-gone' | 'test';
|
|
message: string;
|
|
stack?: string;
|
|
details?: Record<string, unknown>;
|
|
}
|
|
|
|
function trimFile(filePath: string): void {
|
|
try {
|
|
if (!fs.existsSync(filePath)) return;
|
|
const lines = fs.readFileSync(filePath, 'utf-8').split('\n').filter(Boolean);
|
|
if (lines.length > MAX_LINES) {
|
|
fs.writeFileSync(filePath, lines.slice(-MAX_LINES).join('\n') + '\n', 'utf-8');
|
|
}
|
|
} catch {}
|
|
}
|
|
|
|
export function writeCrashLog(entry: CrashEntry): void {
|
|
const filePath = logPath();
|
|
try {
|
|
const line = JSON.stringify(entry) + '\n';
|
|
fs.appendFileSync(filePath, line, 'utf-8');
|
|
trimFile(filePath);
|
|
} catch {}
|
|
}
|
|
|
|
export function readCrashLog(): string {
|
|
const filePath = logPath();
|
|
try {
|
|
if (!fs.existsSync(filePath)) return '';
|
|
return fs.readFileSync(filePath, 'utf-8');
|
|
} catch {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
export function clearCrashLog(): void {
|
|
const filePath = logPath();
|
|
try {
|
|
if (fs.existsSync(filePath)) {
|
|
fs.writeFileSync(filePath, '', 'utf-8');
|
|
}
|
|
} catch {}
|
|
}
|