From 7341edb32f7e2045fd96f32678e8847f9da739d4 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Wed, 30 Jun 2021 16:57:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/main/common/autoUpdate.js | 48 ++++++++++++++++++++++++++++ src/main/index.js | 2 ++ src/main/tray.js | 2 +- src/renderer/assets/common/utils.js | 10 ++++-- static/rocket-t.png | Bin 494 -> 0 bytes static/rocket.png | Bin 857 -> 873 bytes 7 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/main/common/autoUpdate.js delete mode 100644 static/rocket-t.png diff --git a/package.json b/package.json index 44772a6..1c13ec5 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "puppeteer-in-electron": "^3.0.3", "query-string": "^7.0.0", "robotjs": "git+ssh://git@github.com/Toinane/robotjs.git", + "semver": "^7.3.5", "sudo-prompt": "^9.2.1", "unzip": "^0.1.11", "uuid": "^8.3.2", diff --git a/src/main/common/autoUpdate.js b/src/main/common/autoUpdate.js new file mode 100644 index 0000000..bac60ee --- /dev/null +++ b/src/main/common/autoUpdate.js @@ -0,0 +1,48 @@ +import axios from 'axios'; +import { lt } from 'semver'; +import { dialog, shell } from 'electron'; +import pkg from '../../../package.json'; +const os = require('os'); + +const version = pkg.version; +const releaseUrl = 'http://rubick-server.qa.91jkys.com/release/query'; + +export async function autoUpdate() { + let res; + try { + res = await axios.get(releaseUrl); + } catch (err) { + console.log(err); + } + if (res) { + const latest = res.data.result[0]; + const result = compareVersion2Update(version, latest.version); + if (result) { + const res = await dialog.showMessageBox({ + type: 'info', + title: '发现新版本', + buttons: ['Yes', 'No'], + message: `发现新版本${latest.version},更新了很多功能,${latest.msg}, 是否去下载最新的版本?`, + checkboxLabel: '以后不再提醒', + checkboxChecked: false + }); + if (res.response === 0) { + if (os.type() === 'Windows_NT') { + // windows + await shell.openExternal(latest.downloadUrl); + } else if (os.type() === 'Darwin') { + // mac + await shell.openExternal(latest.downloadUrl); + } else { + // 不支持提示 + dialog.showErrorBox('提示', '系统不支持'); + } + } + } + } +} + +// if true -> update else return false +const compareVersion2Update = (current, latest) => { + return lt(current, latest); +}; diff --git a/src/main/index.js b/src/main/index.js index a1353bd..a25a265 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,6 +1,7 @@ import { app, BrowserWindow, protocol } from 'electron' import '../renderer/store' import init from './common/common'; +import {autoUpdate} from './common/autoUpdate'; import createTray from './tray'; const {capture} = require("./browsers")(); /** @@ -55,6 +56,7 @@ function createWindow () { app.on('ready', () => { createWindow() createTray(mainWindow); + autoUpdate(); }) app.on('window-all-closed', () => { diff --git a/src/main/tray.js b/src/main/tray.js index 70981f5..97e1fbe 100644 --- a/src/main/tray.js +++ b/src/main/tray.js @@ -4,7 +4,7 @@ import pkg from '../../package.json'; function createTray(window) { return new Promise((resolve, reject) => { - const appIcon = new Tray(path.join(__static, './rocket-t.png')); + const appIcon = new Tray(path.join(__static, './rocket.png')); const contextMenu = Menu.buildFromTemplate([ { id: 3, diff --git a/src/renderer/assets/common/utils.js b/src/renderer/assets/common/utils.js index 7614da5..d233181 100644 --- a/src/renderer/assets/common/utils.js +++ b/src/renderer/assets/common/utils.js @@ -1,6 +1,7 @@ import {WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS} from './constans'; import path from 'path'; import fs from 'fs'; +import process from 'child_process'; import Store from 'electron-store'; import downloadFile from 'download'; import {nativeImage} from 'electron'; @@ -40,10 +41,15 @@ async function downloadZip(downloadRepoUrl, name) { try { const plugin_path = appPath; // 基础模版所在目录,如果是初始化,则是模板名称,否则是项目名称 - // const temp_dest = `${plugin_path}/${name}`; + const temp_dest = `${plugin_path}/${name}`; + // 下载模板 + if (await existOrNot(temp_dest)) { + await process.execSync(`rm -rf ${temp_dest}`); + } + await downloadFile(downloadRepoUrl, plugin_path,{extract: true}); - return `${plugin_path}/${name}` + return temp_dest; } catch (e) { console.log(e); } diff --git a/static/rocket-t.png b/static/rocket-t.png deleted file mode 100644 index 6b011a1ccef9e22dc32e612832bf6fe78cc55ee9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 494 zcmVp_)B!BvDiXvYy`nVQLuAcE4SFf#x|`*<~^p65Uac!Y|;fwQLwNUwApUa zU9hng6!E992rPt1c5-B*36tzjcJS5be)rsa?j!!=bvm6milVoYo;c@T<_K2dv|6om z^?H2=z!d-|iZ#x;DdSjB2;o(&R@=H_5y?zaY4>GUl3si7@6JJH_5;9rmBkk{B6%%I zl8+0^HnSmsGgShZ!DfjaO3lp1%kh@E%(CoOnx?z+eHMjgrYhr+e3m51gQ9jJwGhHj zk{4FR4dB2zcXGMm9Asu&0G^UuJ0|jP&bf=LKvl*%khJH$zr70d6+qtUH_1MLPm(qz zohNx?nhcqdTyHj;ze+*fZug<2JJVAp^Xs1Np$6dUzrxRwo|F6_X~%p2eIYe7yAR++ zmBfmgIF9R$MkBw!zrVlN>zy8rM)v@00JsU@dI@wNz^w{_Bstqorc@`~9*SCY9+znN?#)|?xRfMEm|Czw3uez;@ZDkeV9p6B3>#E-7W#R)1I4yL`iz5^M&oTDI({ zl(g*2gkaA}AeYC51a_!uXnwA3X=?==1Ogyu+qpPZWEGZ#PV8=5k8YTevZV2njr%8a z^YU6Qn?HNuxs%7AbWWWUyma35B`5~L3`~!S=}pYc37FX30yiu+(9=G@s&#^>n79GL zrT^bNe(>N@jDNpR@`Dc_9>86M?3MhKl!=jvDLx>>*qB&ul{Iw~^6>I%fYki``|rl- zV~3AjIe+%eibXS)gTe_Uj@2NLM0sBBl)&(4&-15GeRXvA(BMzQpKll)d@j`@hMnUay(E{aHC)7lC3ftEgyVSX@#FBO@ahNb#zL z)0gGi?FnGw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