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 - 重构设置页组件系统统一界面样式
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import electron from 'electron';
|
|
const { ipcMain, app } = electron;
|
|
import * as fs from 'fs';
|
|
import { getConfig, saveConfig, updateConfig, type AppConfig, configPath } from '../config';
|
|
|
|
interface WinRef {
|
|
mainWindow: electron.BrowserWindow | null;
|
|
}
|
|
|
|
export function registerConfigHandlers(win: WinRef) {
|
|
ipcMain.handle('config:get', () => {
|
|
try {
|
|
const config = getConfig();
|
|
return { success: true, data: config, error: null };
|
|
} catch (e: unknown) {
|
|
return { success: false, data: null, error: String(e) };
|
|
}
|
|
});
|
|
|
|
ipcMain.handle('config:save', (_event, config: AppConfig) => {
|
|
try {
|
|
saveConfig(config);
|
|
return { success: true, data: null, error: null };
|
|
} catch (e: unknown) {
|
|
return { success: false, data: null, error: String(e) };
|
|
}
|
|
});
|
|
|
|
// 主进程权威更新:渲染进程提交 { section, patch } 补丁,
|
|
// 主进程深度合并到内存配置 → debounce 稀疏写盘 → 广播完整配置给所有渲染进程
|
|
ipcMain.handle('config:update', (_event, payload: { section: string; patch: unknown }) => {
|
|
try {
|
|
const { section, patch } = payload;
|
|
const config = updateConfig({ [section]: patch } as Record<string, unknown>);
|
|
win.mainWindow?.webContents.send('config:changed', config);
|
|
return { success: true, data: config, error: null };
|
|
} catch (e: unknown) {
|
|
return { success: false, data: null, error: String(e) };
|
|
}
|
|
});
|
|
|
|
ipcMain.handle('config:reset', () => {
|
|
try {
|
|
const filePath = configPath();
|
|
if (fs.existsSync(filePath)) {
|
|
fs.unlinkSync(filePath);
|
|
}
|
|
app.relaunch();
|
|
app.exit(0);
|
|
return { success: true, data: null, error: null };
|
|
} catch (e: unknown) {
|
|
return { success: false, data: null, error: String(e) };
|
|
}
|
|
});
|
|
}
|