mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-17 17:16:57 +08:00
feat: 支持自动更新
This commit is contained in:
parent
96268de9d8
commit
7341edb32f
@ -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",
|
||||
|
48
src/main/common/autoUpdate.js
Normal file
48
src/main/common/autoUpdate.js
Normal file
@ -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);
|
||||
};
|
@ -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', () => {
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 494 B |
Binary file not shown.
Before Width: | Height: | Size: 857 B After Width: | Height: | Size: 873 B |
Loading…
x
Reference in New Issue
Block a user