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 6b011a1..0000000 Binary files a/static/rocket-t.png and /dev/null differ diff --git a/static/rocket.png b/static/rocket.png index a4f4e6b..ae864a6 100644 Binary files a/static/rocket.png and b/static/rocket.png differ