内容优化。

pull/303/head
王良 2024-04-23 16:10:09 +08:00
parent 9d445e31fd
commit 178ac3c12b
2 changed files with 31 additions and 29 deletions

View File

@ -3,17 +3,16 @@ import { autoUpdater } from 'electron-updater'
import path from 'path'
import request from 'request'
import progress from 'request-progress'
// win是所有窗口的引用
import fs from 'fs'
import AdmZip from 'adm-zip'
import logger from '../../utils/util.log'
import log from '../../utils/util.log'
import appPathUtil from '../../utils/util.apppath'
// eslint-disable-next-line no-unused-vars
const isMac = process.platform === 'darwin'
const isLinux = process.platform === 'linux'
function downloadFile (uri, filePath, onProgress, onSuccess, onError) {
logger.info('download url', uri)
log.info('download url', uri)
progress(request(uri), {
// throttle: 2000, // Throttle the progress event to 2000ms, defaults to 1000ms
// delay: 1000, // Only start to emit after 1000ms delay, defaults to 0ms
@ -21,11 +20,11 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) {
})
.on('progress', function (state) {
onProgress(state.percent * 100)
logger.log('progress', state.percent)
log.log('progress', state.percent)
})
.on('error', function (err) {
// Do something with err
logger.error('下载升级包失败', err)
log.error('下载升级包失败', err)
onError(err)
})
.on('end', function () {
@ -35,7 +34,11 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) {
.pipe(fs.createWriteStream(filePath))
}
// 检测更新在你想要检查更新的时候执行renderer事件触发后的操作自行编写
/**
* 检测更新在你想要检查更新的时候执行renderer事件触发后的操作自行编写
*
* @param win win是所有窗口的引用
*/
function updateHandle (app, api, win, beforeQuit, quit, log) {
// // 更新前,删除本地安装包 ↓
// const updaterCacheDirName = 'dev-sidecar-updater'
@ -64,7 +67,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
}
}
logger.info('auto updater', autoUpdater.getFeedURL())
log.info('auto updater', autoUpdater.getFeedURL())
autoUpdater.autoDownload = false
let partPackagePath = null
@ -72,7 +75,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
function downloadPart (app, value) {
const appPath = appPathUtil.getAppRootPath(app)
const fileDir = path.join(appPath, 'update')
logger.info('download dir', fileDir)
log.info('download dir:', fileDir)
try {
fs.accessSync(fileDir, fs.constants.F_OK)
} catch (e) {
@ -85,7 +88,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
}, () => {
// 文件下载完成
win.webContents.send('update', { key: 'progress', value: 100 })
logger.info('升级包下载成功:', filePath)
log.info('升级包下载成功:', filePath)
partPackagePath = filePath
win.webContents.send('update', {
key: 'downloaded',
@ -177,7 +180,6 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
} else if (arg.key === 'downloadPart') {
// 下载增量更新版本
log.info('autoUpdater downloadPart')
// autoUpdater.downloadUpdate()
downloadPart(app, arg.value)
}
})

View File

@ -10,7 +10,7 @@ function install (app, api) {
if (fromUser != null) {
updateParams.fromUser = fromUser
}
api.ipc.send('update', { key: 'checkForUpdate' })
api.ipc.send('update', { key: 'checkForUpdate', fromUser })
},
downloadUpdate () {
api.ipc.send('update', { key: 'downloadUpdate' })
@ -38,12 +38,13 @@ function install (app, api) {
} else if (type === 'progress') {
progressUpdate(message.value)
} else if (type === 'error') {
updateParams.downloading = false
const error = message.error
app.$message.error('Error: ' + (error == null ? '未知错误' : (error.stack || error).toString()))
app.$message.error((error == null ? '未知错误' : (error.stack || error).toString()))
}
}
function noNewVersion (value) {
function noNewVersion () {
updateParams.newVersion = false
if (updateParams.fromUser) {
app.$message.info('当前已经是最新版本')
@ -55,6 +56,7 @@ function install (app, api) {
}
function goManualUpdate (value) {
updateParams.newVersion = false
app.$confirm({
title: '暂不支持自动升级',
cancelText: '取消',
@ -63,20 +65,14 @@ function install (app, api) {
function openGithubUrl () {
api.ipc.openExternal('https://github.com/docmirror/dev-sidecar/releases')
}
return <div>
<div>请前往github项目release页面下载新版本手动安装</div>
<ol>
<li><a onClick={openGithubUrl}>Github release</a></li>
</ol>
</div>
return <div>请前往 <a onClick={openGithubUrl}>github项目release页面</a> </div>
}
})
}
/**
* 是否小版本升级
* @param version1
* @param version2
* @param value
*/
async function isSupportPartUpdate (value) {
const info = await api.info.get()
@ -91,9 +87,9 @@ function install (app, api) {
async function downloadNewVersion (value) {
const platform = await api.shell.getSystemPlatform()
console.log('download new version platform', platform)
console.log(`download new version: ${JSON.stringify(value)}, platform: ${platform}`)
if (platform === 'linux') {
goManualUpdate(app, value)
goManualUpdate(value)
return
}
const partUpdate = await isSupportPartUpdate(value)
@ -118,18 +114,22 @@ function install (app, api) {
downloadNewVersion(value)
return
}
console.log(value)
app.$confirm({
title: '发现新版本',
title: '发现新版本' + value.version,
cancelText: '暂不升级',
okText: '升级',
content: h => {
console.log(value)
if (value.releaseNotes) {
const notes = []
for (const note of value.releaseNotes) {
notes.push(<li>{note}</li>)
if (typeof value.releaseNotes === 'string') {
return <div><div>更新内容</div><div>{value.releaseNotes}</div></div>
} else {
const notes = []
for (const note of value.releaseNotes) {
notes.push(<li>{note}</li>)
}
return <div><div>更新内容</div><ol>{notes}</ol></div>
}
return <div><div>更新内容</div><ol>{notes}</ol></div>
}
},
onOk () {