function install (app, api) { const updateParams = app.$global.update = { fromUser: false, autoDownload: false, progress: 0, downloading: false, newVersion: false, isFullUpdate: true } api.ipc.on('update', (event, message) => { console.log('on message', event, message) handleUpdateMessage(message, app) }) api.update = { checkForUpdate (fromUser) { if (fromUser != null) { updateParams.fromUser = fromUser } api.ipc.send('update', { key: 'checkForUpdate' }) }, downloadUpdate () { api.ipc.send('update', { key: 'downloadUpdate' }) }, downloadPart (value) { // 增量更新 api.ipc.send('update', { key: 'downloadPart', value }) }, doUpdateNow () { api.ipc.send('update', { key: 'doUpdateNow' }) } } function handleUpdateMessage (message) { const type = message.key if (type === 'available') { foundNewVersion(message.value) } else if (type === 'notAvailable') { noNewVersion() } else if (type === 'downloaded') { // 更新包已下载完成,让用户确认是否更新 updateParams.downloading = false console.log('updateParams', updateParams) newUpdateIsReady(message.value) } else if (type === 'progress') { progressUpdate(message.value) } else if (type === 'error') { const error = message.error app.$message.error('Error: ' + (error == null ? '未知错误' : (error.stack || error).toString())) } } function noNewVersion (value) { updateParams.newVersion = false if (updateParams.fromUser) { app.$message.info('当前已经是最新版本') } } function progressUpdate (value) { updateParams.progress = value } function goManualUpdate (value) { app.$confirm({ title: '暂不支持自动升级', cancelText: '取消', okText: '确定', content: h => { function openGithubUrl () { api.ipc.openExternal('https://github.com/docmirror/dev-sidecar/releases') } function openGiteeUrl () { api.ipc.openExternal('https://gitee.com/docmirror/dev-sidecar/releases') } return