mirror of
https://github.com/dream-pep/koring-launcher.git
synced 2026-09-12 05:45:18 +08:00
- 引入 electron-updater 实现自动更新功能 - 新增 Java 环境扫描与校验的 IPC 处理逻辑 - 实现离线账号登录功能 - 新增配置变更跨进程广播机制 - 重构游戏启动逻辑,使用主进程内存配置作为唯一权威来源 - 新增界面显示与语言设置的配置页面 - 添加 Windows 平台自动发布 CI 流水线 - 迁移旧版配置/认证文件到用户数据目录 - 修复崩溃日志路径、表单控件等多项 bug - 重构设置页组件系统统一界面样式
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(app.getPath('userData'), 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 {}
|
|
}
|