From cd327dcbaca3476df44b064e56b950dc054cbb87 Mon Sep 17 00:00:00 2001 From: he wei <858544502@qq.com> Date: 星期四, 17 十一月 2022 16:58:56 +0800 Subject: [PATCH] UA 添加自动升级检测功能 添加几种类型电池告警阀值 --- src/update.js | 54 ++++++++++++++++++++++++++++++++---------------------- 1 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/update.js b/src/update.js index 0bf8850..fe9a054 100644 --- a/src/update.js +++ b/src/update.js @@ -1,9 +1,16 @@ // 娉ㄦ剰杩欎釜autoUpdater涓嶆槸electron涓殑autoUpdater import { autoUpdater } from "electron-updater" -import { dialog } from 'electron' +// import { dialog } from 'electron' // import log from 'electron-log'; -function handleUpdate(sender) { +/** + * + * @param {*} sender + * @param {*} quiet 闈欓粯妯″紡 锛堢郴缁熻嚜鍔ㄦ娴嬫椂 涓嶆彁绀烘鍦ㄦ鏌ユ洿鏂帮級 + */ +function handleUpdate(sender, quiet) { + // log.info(autoUpdater); + const isTest = process.env.NODE_ENV == 'none'; const returnData = { error: { status: -1, msg: '妫�娴嬫洿鏂版煡璇㈠紓甯�' }, checking: { status: 0, msg: '姝e湪妫�鏌ュ簲鐢ㄧ▼搴忔洿鏂�' }, @@ -20,7 +27,7 @@ /* 閲嶇偣璇存槑鏈嶅姟鍣ㄧ殑鍦板潃鐨勫唴瀹癸紝鍐呭鏄墦鍖呬互鍚庣敓鎴愮殑latest.yml锛屾妸杩欎釜鏂囦欢鏀惧埌鏈嶅姟鍣ㄤ笂锛屽悓鏃跺拰浣犳墦鍖呬互鍚庣殑瀹夎鍖呭悓绾х洰褰曪紝杩欐牱latest.yml涓殑鍦板潃鎵嶈兘璇诲彇鍒� */ - let updataPath = 'http://118.89.139.230:9098/res-update' + let updataPath = isTest ? 'http://118.89.139.230:9098/res-update-test' : 'http://118.89.139.230:9098/res-update'; autoUpdater.setFeedURL({ provider: 'generic', url: updataPath @@ -30,37 +37,40 @@ //鏇存柊閿欒 autoUpdater.on('error', function (error) { - sendUpdateMessage(sender, returnData.error) + !quiet && sendUpdateMessage(sender, returnData.error) }); //妫�鏌ヤ腑 autoUpdater.on('checking-for-update', function () { - sendUpdateMessage(sender, returnData.checking); + !quiet && sendUpdateMessage(sender, returnData.checking); }); //鍙戠幇鏂扮増鏈� + // autoUpdater.on('update-available', function (info) { + // const options = { + // type: 'info', + // buttons: ['纭畾', '鍙栨秷'], + // title: '鏇存柊鎻愮ず', + // // ${info.version} Cannot read property 'version' of undefined + // message: `鍙戠幇鏈夋柊鐗堟湰'${info.version}'锛屾槸鍚︿笅杞斤紵`, + // cancelId: 1 + // } + // dialog.showMessageBox(options).then(res => { + // // log.info(JSON.stringify(res)); + // if (res.response === 0) { + // autoUpdater.downloadUpdate() + // } else { + // return; + // } + // }) + // }); autoUpdater.on('update-available', function (info) { - const options = { - type: 'info', - buttons: ['纭畾', '鍙栨秷'], - title: '鏇存柊鎻愮ず', - // ${info.version} Cannot read property 'version' of undefined - message: `鍙戠幇鏈夋柊鐗堟湰'${info.version}'锛屾槸鍚︿笅杞斤紵`, - cancelId: 1 - } - dialog.showMessageBox(options).then(res => { - // log.info(JSON.stringify(res)); - if (res.response === 0) { - autoUpdater.downloadUpdate() - } else { - return; - } - }) + sender.send('update-info', { info, updataPath, currentVersion: autoUpdater.currentVersion.version }); }); //褰撳墠鐗堟湰涓烘渶鏂扮増鏈� autoUpdater.on('update-not-available', function (info) { - setTimeout(function () { + !quiet && setTimeout(function () { sendUpdateMessage(sender, returnData.updateNotAva) }, 1000); }); -- Gitblit v1.9.1