2026-06-28 03:37:07 +08:00
|
|
|
import electron from 'electron';
|
|
|
|
|
import { execSync } from 'child_process';
|
|
|
|
|
import * as os from 'os';
|
|
|
|
|
|
2026-08-04 01:28:16 +08:00
|
|
|
const { ipcMain, app, shell } = electron;
|
2026-06-28 03:37:07 +08:00
|
|
|
|
|
|
|
|
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) };
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-08-04 01:28:16 +08:00
|
|
|
|
|
|
|
|
// 在系统文件管理器中打开指定路径(用于"打开游戏目录"等操作)
|
|
|
|
|
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) };
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-06-28 03:37:07 +08:00
|
|
|
}
|