diff --git a/services/update.js b/services/update.js index 198d7c9..d6fc0cd 100644 --- a/services/update.js +++ b/services/update.js @@ -197,6 +197,19 @@ class UpdateService extends service { updatedAt: new Date().toISOString() }; + // 下载中状态每个网络 chunk 触发一次(60MB 包约 4000 次), + // 节流到 300ms 一次,避免消息洪泛消耗主进程/渲染进程内存; + // 其他状态(starting/downloaded/installing/failed)立即发送,保证终态不丢。 + if (patch.status === 'downloading') { + const now = Date.now(); + if (this._lastProgressEmitAt && now - this._lastProgressEmitAt < 300) { + return; + } + this._lastProgressEmitAt = now; + } else { + this._lastProgressEmitAt = 0; + } + this.app.emit('updateDownloadProgress', this._downloadState); } @@ -338,14 +351,6 @@ class UpdateService extends service { throw new Error('当前系统不支持自动启动安装程序'); } - if (process.argv.includes('--service-runner')) { - throw new Error('服务模式无法弹出安装向导,请在前台模式下重试'); - } - - if (this.app?.config?.isService) { - throw new Error('当前处于服务模式,无法直接弹出安装向导,请先注销服务后再更新'); - } - const escapedPath = installerPath.replace(/'/g, "''"); const psArgs = [ '-NoProfile', diff --git a/views/index.html b/views/index.html index 55f70e2..3f047a1 100644 --- a/views/index.html +++ b/views/index.html @@ -1321,7 +1321,8 @@ }; } } else { - alert(data.message || '获取绑定状态失败!'); + // 每 10 秒轮询调用:失败静默处理,避免模态弹窗阻塞页面,状态会自动恢复 + console.warn('[UI] 获取绑定状态失败:', data.message || ''); } }); }, @@ -1738,30 +1739,46 @@ var ws = mainApp.wsStatus; var items = statusEl.querySelectorAll('.status-item'); + var html0 = '', html1 = '', html2 = ''; if (items[0]) { var c = ws[mainApp.wsClientStatus] || ws.connected; - items[0].innerHTML = '' + + html0 = '' + '本地服务:' + c.title + ''; } if (items[1]) { var s = ws[mainApp.wsServerStatus] || ws.disconnected; - items[1].innerHTML = '' + + html1 = '' + '服务器连接:' + s.title + ''; } if (items[2]) { var bindC = mainApp.isBind ? '#107c10' : '#c42b1c'; var bindT = mainApp.isBind ? '已绑定' : '未绑定'; var clickable = mainApp.isBind ? 'cursor:pointer;text-decoration:underline' : ''; - items[2].innerHTML = '' + + html2 = '' + '打印服务绑定:' + bindT + ''; } + // 仅在内容变化时写 DOM,避免每 500ms 全量重建节点 + if (!lastSbHtml) lastSbHtml = {}; + if (lastSbHtml[0] !== html0) { lastSbHtml[0] = html0; if (items[0]) items[0].innerHTML = html0; } + if (lastSbHtml[1] !== html1) { lastSbHtml[1] = html1; if (items[1]) items[1].innerHTML = html1; } + if (lastSbHtml[2] !== html2) { lastSbHtml[2] = html2; if (items[2]) items[2].innerHTML = html2; } + var btns = statusEl.querySelectorAll('button'); - if (btns[0]) btns[0].textContent = mainApp.updateChecking ? '检查中...' : '检查更新'; - if (btns[1]) { btns[1].textContent = mainApp.restartingBackend ? '重启中...' : '重启服务'; btns[1].disabled = mainApp.restartingBackend; } + if (btns[0]) { + var btn0Text = mainApp.updateChecking ? '检查中...' : '检查更新'; + if (btns[0].textContent !== btn0Text) btns[0].textContent = btn0Text; + } + if (btns[1]) { + var btn1Text = mainApp.restartingBackend ? '重启中...' : '重启服务'; + if (btns[1].textContent !== btn1Text) btns[1].textContent = btn1Text; + btns[1].disabled = mainApp.restartingBackend; + } } + var lastSbHtml = null; + // 绑定按钮事件 var btnCheck = document.getElementById('btnCheckUpdate'); if (btnCheck) {