稳定正式版

This commit is contained in:
2025-10-29 19:46:21 +08:00
parent 183feef2ea
commit 0a7aaa7508
2 changed files with 63 additions and 8 deletions

69
main.js
View File

@@ -29,6 +29,40 @@ let updateInProgress = false; // 有更新或正在下载 -> true
let updateDownloaded = false; // 已下载完成(通常会随即重启安装)
let pendingNavs = []; // 被延迟的跳转请求(函数队列)
let installingNow = false; // 正在静默安装(用户点击“立即重启安装”之后)
// --- 持久化兼容模式开关(仅影响本机) ---
const compatFile = path.join(app.getPath('userData'), 'compat.json');
function readCompat() { try { return JSON.parse(fs.readFileSync(compatFile, 'utf8')); } catch { return {}; } }
function writeCompat(obj) { try { fs.writeFileSync(compatFile, JSON.stringify(obj, null, 2)); } catch { } }
// 支持三种触发:环境变量、命令行、持久化标记
const SAFE_MODE =
process.env.YOLO_SAFE_MODE === '1' ||
process.argv.includes('--safe-mode') ||
readCompat().safeMode === true;
// (可选)允许命令行清除持久化标记:--clear-safe-mode
if (process.argv.includes('--clear-safe-mode')) {
const c = readCompat(); delete c.safeMode; writeCompat(c);
console.log('[Compat] cleared safeMode flag');
}
// === 兼容模式等价于 bat 里的那些开关(不含日志) ===
if (SAFE_MODE) {
app.disableHardwareAcceleration(); // --disable-gpu
app.commandLine.appendSwitch('disable-gpu');
app.commandLine.appendSwitch('in-process-gpu'); // --in-process-gpu
app.commandLine.appendSwitch('disable-direct-composition'); // --disable-direct-composition
// 如需更稳再关沙箱:默认开着更安全;若你确实要关,则解除注释
// app.commandLine.appendSwitch('no-sandbox'); // --no-sandbox
console.log('[SAFE_MODE] enabled');
}
function flushPendingNavs() {
const fns = pendingNavs.slice();
pendingNavs = [];
@@ -50,11 +84,26 @@ process.on('unhandledRejection', (reason, p) => {
console.error('[unhandledRejection未捕获异常]', reason);
});
// 渲染崩溃 → 持久化 safeMode=true下次自动以兼容模式启动
app.on('web-contents-created', (_, contents) => {
contents.on('render-process-gone', (event, details) => {
contents.on('render-process-gone', (_event, details) => {
console.error('⚠️ 渲染崩溃:', details);
if (['launch-failed', 'abnormal-exit'].includes(details.reason)) {
const c = readCompat(); c.safeMode = true; writeCompat(c);
console.warn('[Compat] set safeMode=true (persisted), will auto-use SAFE_MODE next launch');
}
});
});
//(可选)更广义的子进程异常也触发降级
app.on('child-process-gone', (_e, details) => {
if ((details.type === 'GPU' || details.type === 'Renderer') &&
['launch-failed', 'abnormal-exit'].includes(details.reason)) {
const c = readCompat(); c.safeMode = true; writeCompat(c);
console.warn('[Compat] GPU/Renderer gone, safeMode persisted');
}
});
app.on('ready', () => {
console.log('[App Ready] 当前版本:', app.getVersion());
@@ -270,17 +319,23 @@ function createWindow() {
frame: true,
fullscreenable: false,
webPreferences: {
preload: path.join(__dirname, 'js', 'preload.js'), // ✅ 这里必须配置
preload: path.join(__dirname, 'js', 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
// 推荐:默认 true只有 SAFE_MODE 才 false等价 --no-sandbox
sandbox: SAFE_MODE ? false : true,
webSecurity: true,
backgroundThrottling: false,
enableRemoteModule: false,
offscreen: false,
experimentalFeatures: true, // 保险
// 兼容模式更稳:关实验特性
experimentalFeatures: SAFE_MODE ? false : true,
autoplayPolicy: 'no-user-gesture-required',
devTools: true, // 开发者工具
devTools: true,
}
});
@@ -289,8 +344,8 @@ function createWindow() {
// 自动判断环境使用不同的页面地址
const isProd = app.isPackaged;
const targetURL = isProd ? 'iosaitest.yolozs.com' : 'http://192.168.1.128:8080';
// const targetURL = isProd ? 'https://iosai.yolozs.com' : 'http://192.168.1.128:8080';
// const targetURL = isProd ? 'https://iosaitest.yolozs.com' : 'http://192.168.1.128:8080';
const targetURL = isProd ? 'https://iosai.yolozs.com' : 'http://192.168.1.128:8080';
console.log('[页面加载] 使用地址:', targetURL);
let retryIntervalId = null;

View File

@@ -1,7 +1,7 @@
{
"name": "YOLO-ios-ai",
"productName": "YOLOAI助手ios",
"version": "2.5.3",
"version": "2.7.1",
"description": "Vue3 + WS 控制台",
"author": "yourname",
"main": "main.js",