// main/window.js const { app, BrowserWindow, dialog, ipcMain } = require('electron') const path = require('path') const fs = require('fs') const { isProcessRunningWin } = require('./services/iosai') function safeLoadURL(win, url, onFail) { if (!win || win.isDestroyed()) return win.loadURL(url).catch(err => { console.warn('[loadURL fail]', err); onFail?.(err) }) } function createMainWindow({ updaterState }) { const win = new BrowserWindow({ width: 1920, height: 1080, title: `YOLO(AI助手ios) v${app.getVersion()}`, frame: true, webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, nodeIntegration: false, sandbox: true, webSecurity: true, backgroundThrottling: false, enableRemoteModule: false, offscreen: false, experimentalFeatures: true, autoplayPolicy: 'no-user-gesture-required', devTools: true, } }) win.setMenu(null) win.maximize() const isProd = app.isPackaged const targetURL = isProd ? 'https://iosai.yolozs.com' : 'http://192.168.1.128:8080' console.log('[page] target:', targetURL) const tryNavigate = (reason = '') => { const ts = Date.now() const go = () => safeLoadURL(win, `${targetURL}?t=${ts}`) if (updaterState.updateInProgress) { console.log(`[Nav] blocked (${reason}): updating...`) updaterState.pendingNavs.push(go) return } go() } // 等待页 const loadingFile = path.join(__dirname, '..', 'waiting.html') if (process.platform === 'win32') { if (fs.existsSync(loadingFile)) { win.loadFile(loadingFile).catch(() => win.loadURL('data:text/html,