稳定测试版

This commit is contained in:
2025-10-28 19:40:13 +08:00
commit 183feef2ea
24 changed files with 11631 additions and 0 deletions

61
main/index.js Normal file
View File

@@ -0,0 +1,61 @@
// main/index.js
const { app, globalShortcut, BrowserWindow } = require('electron')
const path = require('path')
const { registerUpdater, updaterState } = require('./updater')
const { createMainWindow } = require('./window')
const { registerSystemIpc } = require('./ipc/system')
const { registerFileIpc } = require('./ipc/files')
const { registerMqIpc } = require('./ipc/mq')
const { startIOSAIExecutable, killIOSAI } = require('./services/iosai')
const { startSSE } = require('./services/sse')
const { setupGuards } = require('./utils/guard')
const { dumpAllMem } = require('./utils/mem')
setupGuards()
app.commandLine.appendSwitch('enable-precise-memory-info')
app.commandLine.appendSwitch('js-flags', '--expose-gc --max-old-space-size=4096')
app.commandLine.appendSwitch('enable-experimental-web-platform-features')
app.commandLine.appendSwitch('enable-features', 'WebCodecs,MediaStreamInsertableStreams')
let sse = null
app.on('ready', async () => {
// 更新
registerUpdater()
// 启动外部服务
startIOSAIExecutable()
// IPC
registerSystemIpc()
registerFileIpc()
registerMqIpc((payload) => sse?.broadcast('message', payload)) // 渲染用
// SSE
sse = startSSE()
// 窗口
const win = createMainWindow({ updaterState })
// 快捷键
globalShortcut.register('Control+Shift+I', () => {
const w = BrowserWindow.getFocusedWindow()
if (!w) return
const wc = w.webContents
wc.isDevToolsOpened() ? wc.closeDevTools() : wc.openDevTools({ mode: 'detach' })
})
// 内存Dump可选
setInterval(dumpAllMem, 5000)
})
app.on('will-quit', () => globalShortcut.unregisterAll())
app.on('before-quit', async () => { await killIOSAI() })
app.on('window-all-closed', async () => {
await killIOSAI()
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createMainWindow({ updaterState })
})