mirror of
https://github.com/dream-pep/koring-launcher.git
synced 2026-09-12 05:45:18 +08:00
重构自动更新模块的版本比较逻辑,替换原有的semver比较规则为项目自定义的版本序:仅对比主版本号与构建号,忽略beta通道标记,确保同主版本下按构建号排序。新增correctAvailability方法在检查更新与下载前复核版本有效性,避免陈旧的更新信息导致误更新。调整GitHub release拉取逻辑,过滤掉草稿与不符合通道权限的预发布版本。新增src/resources目录下的运行时资源缓存管理系统,包含类型定义、图片解码管线与全局资源注册表,支持LRU内存逐出、引用计数与预算控制。新增系统内存监控的IPC接口与前端API,支持获取进程内存快照用于调试面板。更新auto-update-plan.md文档,补充本次版本判定修复的相关说明。
115 lines
3.2 KiB
TypeScript
115 lines
3.2 KiB
TypeScript
import electron from 'electron';
|
|
import { execSync } from 'child_process';
|
|
import * as os from 'os';
|
|
|
|
const { ipcMain, app, shell } = electron;
|
|
|
|
interface ProcessMemorySample {
|
|
type: string;
|
|
pid: number;
|
|
workingSetSize: number; // KB
|
|
peakWorkingSetSize: number; // KB
|
|
}
|
|
|
|
function getBiosId(): string {
|
|
if (process.platform !== 'win32') return 'N/A (non-Windows)';
|
|
try {
|
|
const output = execSync('powershell -NoProfile -Command "(Get-CimInstance Win32_BIOS).SerialNumber"', {
|
|
encoding: 'utf-8',
|
|
timeout: 5000,
|
|
});
|
|
return output.trim() || 'Unknown';
|
|
} catch {
|
|
return 'Unknown';
|
|
}
|
|
}
|
|
|
|
function getOsVersion(): string {
|
|
if (process.platform !== 'win32') return 'N/A (non-Windows)';
|
|
try {
|
|
const output = execSync('powershell -NoProfile -Command "[System.Environment]::OSVersion.VersionString"', {
|
|
encoding: 'utf-8',
|
|
timeout: 5000,
|
|
});
|
|
return output.trim() || 'Unknown';
|
|
} catch {
|
|
return 'Unknown';
|
|
}
|
|
}
|
|
|
|
function getOsName(): string {
|
|
if (process.platform !== 'win32') return 'N/A (non-Windows)';
|
|
try {
|
|
const output = execSync('powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).Caption"', {
|
|
encoding: 'utf-8',
|
|
timeout: 5000,
|
|
});
|
|
return output.trim() || 'Unknown';
|
|
} catch {
|
|
return 'Unknown';
|
|
}
|
|
}
|
|
|
|
export function registerSystemHandlers() {
|
|
ipcMain.handle('system:info', () => {
|
|
try {
|
|
return {
|
|
success: true,
|
|
data: {
|
|
app_version: app.getVersion(),
|
|
bios_id: getBiosId(),
|
|
os_version: getOsVersion(),
|
|
os_name: getOsName(),
|
|
},
|
|
error: null,
|
|
};
|
|
} catch (e: unknown) {
|
|
return { success: false, data: null, error: String(e) };
|
|
}
|
|
});
|
|
|
|
// 进程内存快照(资源/内存调试面板使用;纯读取,无副作用)
|
|
ipcMain.handle('system:memory', async () => {
|
|
try {
|
|
const metrics: ProcessMemorySample[] = app.getAppMetrics().map((m) => ({
|
|
type: String(m.type),
|
|
pid: m.pid,
|
|
workingSetSize: m.memory?.workingSetSize ?? 0,
|
|
peakWorkingSetSize: m.memory?.peakWorkingSetSize ?? 0,
|
|
}));
|
|
let mainProcess: { workingSetSize: number; privateBytes: number } | null = null;
|
|
try {
|
|
const info = await process.getProcessMemoryInfo();
|
|
mainProcess = {
|
|
workingSetSize: info.workingSetSize,
|
|
privateBytes: info.privateBytes,
|
|
};
|
|
} catch {
|
|
// 个别平台不支持 getProcessMemoryInfo,忽略
|
|
}
|
|
return {
|
|
success: true,
|
|
data: {
|
|
app_version: app.getVersion(),
|
|
timestamp: Date.now(),
|
|
metrics,
|
|
mainProcess,
|
|
},
|
|
error: null,
|
|
};
|
|
} catch (e: unknown) {
|
|
return { success: false, data: null, error: String(e) };
|
|
}
|
|
});
|
|
|
|
// 在系统文件管理器中打开指定路径(用于"打开游戏目录"等操作)
|
|
ipcMain.handle('system:open-path', async (_event, payload: { path: string }) => {
|
|
try {
|
|
const error = await shell.openPath(payload.path);
|
|
return { success: !error, data: { error }, error: error || null };
|
|
} catch (e: unknown) {
|
|
return { success: false, data: null, error: String(e) };
|
|
}
|
|
});
|
|
}
|