mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-07 07:22:46 +08:00
✨ Feature(custom): optimize auto-upload pipeline
This commit is contained in:
@@ -4,6 +4,7 @@ import { BrowserWindow, shell } from 'electron'
|
||||
import updater from 'electron-updater'
|
||||
|
||||
import { RPCRouter } from '~/events/rpc/router'
|
||||
import { downloadAndInstallUpdate } from '~/lifeCycle/autoUpdater'
|
||||
import { configPaths } from '~/utils/configPaths'
|
||||
import { IRPCActionType } from '~/utils/enum'
|
||||
|
||||
@@ -15,6 +16,8 @@ const updaterRoutes = [
|
||||
handler: async () => {
|
||||
if (!isPortable()) {
|
||||
updater.autoUpdater.downloadUpdate()
|
||||
} else {
|
||||
downloadAndInstallUpdate()
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -130,24 +130,26 @@ export async function setupAutoUpdater() {
|
||||
}
|
||||
|
||||
export async function checkUpdateAndNotify(): Promise<void> {
|
||||
const url = 'https://release.piclist.cn/latest/latest.yml'
|
||||
const res = await axios.get(url, {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
responseType: 'text',
|
||||
})
|
||||
const latest = yaml.parseDocument(res.data).toJSON() as unknown as updater.UpdateInfo
|
||||
const currentVersion = pkg.version
|
||||
if (latest.version !== currentVersion) {
|
||||
newVersion = latest.version
|
||||
updateAvailableHandler(latest)
|
||||
if (isPortable()) {
|
||||
const url = 'https://release.piclist.cn/latest/latest.yml'
|
||||
const res = await axios.get(url, {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
responseType: 'text',
|
||||
})
|
||||
const latest = yaml.parseDocument(res.data).toJSON() as unknown as updater.UpdateInfo
|
||||
const currentVersion = pkg.version
|
||||
if (latest.version !== currentVersion) {
|
||||
newVersion = latest.version
|
||||
updateAvailableHandler(latest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadAndInstallUpdate(): Promise<void> {
|
||||
const baseUrl = 'https://release.piclist.cn/latest'
|
||||
const fileMap = {
|
||||
'win32-x64': `PicList-Setup-${newVersion.replace(/^v/, '')}-x64-portable.zip`,
|
||||
'win32-arm64': `PicList-Setup-${newVersion.replace(/^v/, '')}-arm64-portable.zip`,
|
||||
'win32-x64': `PicList-Setup-${newVersion.replace(/^v/, '')}-x64-portable.7z`,
|
||||
'win32-arm64': `PicList-Setup-${newVersion.replace(/^v/, '')}-arm64-portable.7z`,
|
||||
} as Record<string, string>
|
||||
const file = fileMap[`${process.platform}-${process.arch}`]
|
||||
if (!file) {
|
||||
@@ -191,8 +193,9 @@ export async function downloadAndInstallUpdate(): Promise<void> {
|
||||
return
|
||||
}
|
||||
progressHandler({ percent: 100 } as updater.ProgressInfo)
|
||||
const zipFilePath = path.join(dirname, '../../../resources/7za.exe').replace('app.asar', 'app.asar.unpacked')
|
||||
const zipFilePath = path.join(dirname, '../../resources/7za.exe').replace('app.asar', 'app.asar.unpacked')
|
||||
await fs.copyFile(zipFilePath, path.join(defaultDir(), '7za.exe'))
|
||||
logger.info('Starting update installation...')
|
||||
spawn(
|
||||
'cmd',
|
||||
[
|
||||
|
||||
@@ -2,7 +2,7 @@ import picgo from '@core/picgo'
|
||||
import updater from 'electron-updater'
|
||||
|
||||
import { isPortable } from '~/apis/core/datastore/dirs'
|
||||
import { downloadAndInstallUpdate } from '~/lifeCycle/autoUpdater'
|
||||
import { checkUpdateAndNotify } from '~/lifeCycle/autoUpdater'
|
||||
import { configPaths } from '~/utils/configPaths'
|
||||
|
||||
const updateChecker = async () => {
|
||||
@@ -16,7 +16,7 @@ const updateChecker = async () => {
|
||||
if (!isPortable()) {
|
||||
await updater.autoUpdater.checkForUpdatesAndNotify()
|
||||
} else {
|
||||
await downloadAndInstallUpdate()
|
||||
await checkUpdateAndNotify()
|
||||
}
|
||||
} catch (_err) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user