提交 ed7b7039 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

fix issues

上级 d3e7e32a
......@@ -2,7 +2,7 @@ import {app, BrowserWindow, ipcMain, Menu, shell, dialog, globalShortcut} from '
import {
DEBUG,
electronMsg,
electronMsg, electronMsgReboot,
electronMsgReplay,
electronMsgUpdate,
minimumSizeHeight,
......@@ -15,7 +15,7 @@ import Lang, {initLang} from './core/lang';
import {startUIService} from "./core/ui";
import {startZdServer, killZdServer} from "./core/zd";
import {getCurrVersion} from "./utils/comm";
import {checkUpdate, updateApp} from "./utils/hot-update";
import {checkUpdate, downLoadAndUpdateApp, reboot} from "./utils/hot-update";
const cp = require('child_process');
const fs = require('fs');
......@@ -160,7 +160,12 @@ export class ZdApp {
logInfo('update confirm from renderer', arg)
const mainWin = this._windows.get('main');
updateApp(arg.newVersion, mainWin)
downLoadAndUpdateApp(arg.newVersion, mainWin)
});
ipcMain.on(electronMsgReboot, (event, arg) => {
logInfo('reboot from renderer', arg)
reboot()
});
setInterval(async () => {
......
......@@ -67,7 +67,7 @@ export function changeVersion(newVersion) {
let json = {}
if (fs.existsSync(pth)) {
const content = fs.readFileSync(pth)
const content = fs.readFileSync(pth).toString()
json = JSON.parse(content);
}
......@@ -75,13 +75,6 @@ export function changeVersion(newVersion) {
fs.writeFileSync(pth, JSON.stringify(json));
}
export function restart() {
app.relaunch({
args: process.argv.slice(1)
});
app.exit(0);
}
export function getResPath() {
const versionPath = path.resolve(ResDir, 'version.json')
const uiPath = path.resolve(ResDir, 'ui');
......
......@@ -11,7 +11,10 @@ export const uuid = 'ZENDATA@1CF17A46-B136-4AEB-96B4-F21C8200EF5A~'
export const electronMsg = 'electronMsg'
export const electronMsgReplay = 'electronMsgReplay'
export const electronMsgUpdate = 'electronMsgUpdate'
export const electronMsgReboot = 'electronMsgReboot'
export const electronMsgDownloading = 'electronMsgDownloading'
export const electronMsgDownloadSuccess = 'electronMsgDownloadSuccess'
export const electronMsgUpdateFail = 'electronMsgUpdateFail'
export const minimumSizeWidth = 1024
export const minimumSizeHeight = 640
......
......@@ -7,13 +7,29 @@ import {
getResPath, mkdir,
restart
} from "./comm";
import {electronMsgDownloading, electronMsgUpdate, WorkDir} from "./consts";
import {
electronMsgDownloading,
electronMsgDownloadSuccess,
electronMsgUpdate,
electronMsgUpdateFail,
} from "./consts";
import path from "path";
import {execSync} from 'child_process';
import {IS_WINDOWS_OS} from "../utils/env";
import fse from 'fs-extra'
import {logErr, logInfo} from "./log";
const admZip = require('adm-zip');
import {promisify} from 'node:util';
import stream from 'node:stream';
import fs from 'node:fs';
import got from 'got';
import os from "os";
import {killZdServer} from "../core/zd";
const pipeline = promisify(stream.pipeline);
mkdir(path.join('tmp', 'download'))
export async function checkUpdate(mainWin) {
logInfo('checkUpdate ...')
......@@ -33,31 +49,7 @@ export async function checkUpdate(mainWin) {
}
}
export const updateApp = (version, mainWin) => {
downLoadApp(version, mainWin, doUpdate)
}
const doUpdate = async (downloadPath, version) => {
await copyFiles(downloadPath);
changeVersion(version);
restart();
}
const admZip = require('adm-zip');
import {promisify} from 'node:util';
import stream from 'node:stream';
import fs from 'node:fs';
import got from 'got';
import {cpSync} from "fs";
import os from "os";
import {killZdServer} from "../core/zd";
const pipeline = promisify(stream.pipeline);
mkdir(path.join('tmp', 'download'))
const downLoadApp = (version, mainWin, cb) => {
export const downLoadAndUpdateApp = (version, mainWin) => {
const downloadUrl = getAppUrl(version)
const downloadPath = getDownloadPath(version)
......@@ -75,13 +67,17 @@ const downLoadApp = (version, mainWin, cb) => {
const md5Pass = await checkMd5(version, downloadPath)
if (md5Pass) {
cb(downloadPath, version)
await copyFiles(downloadPath);
changeVersion(version);
mainWin.webContents.send(electronMsgDownloadSuccess, {})
} else {
logInfo('check md5 failed')
throw new Error('check md5 failed')
}
}).catch((err) => {
logErr(`update failed: ${err}`)
logErr(`upgrade app failed: ${err}`)
mainWin.webContents.send(electronMsgUpdateFail, {err: err.message})
});
}
......@@ -116,4 +112,11 @@ const copyFiles = async (downloadPath) => {
const cmd = `chmod +x ${serverDist}`
execSync(cmd, {windowsHide: true})
}
}
export function reboot() {
app.relaunch({
args: process.argv.slice(1)
});
app.exit(0);
}
\ No newline at end of file
export const electronMsg = 'electronMsg'
export const electronMsgReplay = 'electronMsgReplay'
export const electronMsgUpdate = 'electronMsgUpdate'
export const electronMsgReboot = 'electronMsgReboot'
export const electronMsgDownloading = 'electronMsgDownloading'
export const electronMsgDownloadSuccess = 'electronMsgDownloadSuccess'
export const electronMsgUpdateFail = 'electronMsgUpdateFail'
export const skippedVersion = 'skippedVersion'
export const ignoreUtil = 'ignoreUtil'
\ No newline at end of file
......@@ -15,9 +15,15 @@
</div>
<template #footer>
<a-button @click="update" type="primary">立即升级</a-button>
<a-button @click="defer">明天提醒我</a-button>
<a-button @click="skip">跳过这个版本</a-button>
<div v-if="!updateSuccess">
<a-button @click="update" type="primary">立即升级</a-button>
<a-button @click="defer">明天提醒我</a-button>
<a-button @click="skip">跳过这个版本</a-button>
</div>
<div v-if="updateSuccess">
<a-button @click="reboot" type="primary">立即重启</a-button>
</div>
</template>
</a-modal>
</div>
......@@ -27,7 +33,7 @@
import {
electronMsgUpdate,
electronMsgDownloading,
skippedVersion, ignoreUtil,
skippedVersion, ignoreUtil, electronMsgDownloadSuccess, electronMsgUpdateFail, electronMsgReboot,
} from "../config/settings.js";
import {getCache, setCache} from "../utils/localCache.js";
......@@ -44,6 +50,7 @@ export default {
let isElectron = false
let ipcRenderer = undefined
let version = null
let updateSuccess = false
return {
isVisible,
......@@ -54,6 +61,7 @@ export default {
ipcRenderer,
isElectron,
version,
updateSuccess,
}
},
......@@ -87,6 +95,12 @@ export default {
console.log('downloading msg from electron', data);
this.downloadingPercent = Math.round(data.percent * 100);
})
this.ipcRenderer.on(electronMsgDownloadSuccess, async (event, data) => {
console.log('md5 checking success msg from electron', data);
})
this.ipcRenderer.on(electronMsgUpdateFail, async (event, data) => {
console.log('downloading fail msg from electron', data);
})
}
},
mounted() {
......@@ -101,6 +115,10 @@ export default {
forceUpdate: this.forceUpdate
})
},
reboot() {
console.log('reboot')
this.ipcRenderer.send(electronMsgReboot, {})
},
defer() {
console.log('defer')
setCache(ignoreUtil, Date.now() + 24 * 3600);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册