From db8dd19eae6a8d06de6209323e16c666eea8317a Mon Sep 17 00:00:00 2001 From: Kuingsmile <96409857+Kuingsmile@users.noreply.github.com> Date: Thu, 15 Jan 2026 20:49:57 +0800 Subject: [PATCH] :sparkles: Feature(custom): optimize auto-upload pipeline --- .github/workflows/buid_arch.yml | 17 ++++++++++++ scripts/afterPack.cjs | 12 --------- src/main/events/rpc/routes/updater/index.ts | 3 +++ src/main/lifeCycle/autoUpdater.ts | 29 ++++++++++++--------- src/main/utils/updateChecker.ts | 4 +-- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/.github/workflows/buid_arch.yml b/.github/workflows/buid_arch.yml index 39c0480c..69e896c0 100644 --- a/.github/workflows/buid_arch.yml +++ b/.github/workflows/buid_arch.yml @@ -183,10 +183,27 @@ jobs: fi echo "Publishing argument: $PUBLISH_ARG" if [[ "${{ matrix.os }}" == windows* ]]; then + if [[ "${{ matrix.format }}" == "nsis" ]]; then + rm -f ./resources/7za.exe + if [ -f ./resources/7za.exe ]; then + echo "Error: 7za.exe was not removed from resources." + exit 1 + fi + fi yarn run build:win ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG elif [[ "${{ matrix.os }}" == macos* ]]; then + rm -f ./resources/7za.exe + if [ -f ./resources/7za.exe ]; then + echo "Error: 7za.exe was not removed from resources." + exit 1 + fi yarn run build:mac ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG elif [[ "${{ matrix.os }}" == ubuntu* ]]; then + rm -f ./resources/7za.exe + if [ -f ./resources/7za.exe ]; then + echo "Error: 7za.exe was not removed from resources." + exit 1 + fi yarn run build:linux ${{ matrix.format}} --${{ matrix.arch }} --publish $PUBLISH_ARG else echo "Unsupported OS: ${{ matrix.os }}" diff --git a/scripts/afterPack.cjs b/scripts/afterPack.cjs index 31133098..767a4845 100644 --- a/scripts/afterPack.cjs +++ b/scripts/afterPack.cjs @@ -18,21 +18,9 @@ async function main(context) { const portablePath = path.join(appOutDir, 'PORTABLE') try { fs.writeFileSync(portablePath, '') - console.log('Created portable marker file at', portablePath) } catch (err) { console.error('Error creating portable marker file:', err) } - } else { - const fileToRemave = path.join(appOutDir, 'resources/7za.exe') - console.log('Checking for unnecessary 7za.exe at', fileToRemave) - if (fs.existsSync(fileToRemave)) { - try { - fs.unlinkSync(fileToRemave) - console.log('Removed unnecessary 7za.exe from', fileToRemave) - } catch (err) { - console.error('Error removing 7za.exe:', err) - } - } } } diff --git a/src/main/events/rpc/routes/updater/index.ts b/src/main/events/rpc/routes/updater/index.ts index 58c280f6..a17ac3fa 100644 --- a/src/main/events/rpc/routes/updater/index.ts +++ b/src/main/events/rpc/routes/updater/index.ts @@ -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() } }, }, diff --git a/src/main/lifeCycle/autoUpdater.ts b/src/main/lifeCycle/autoUpdater.ts index d57d26f7..683ea9d9 100644 --- a/src/main/lifeCycle/autoUpdater.ts +++ b/src/main/lifeCycle/autoUpdater.ts @@ -130,24 +130,26 @@ export async function setupAutoUpdater() { } export async function checkUpdateAndNotify(): Promise { - 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 { 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 const file = fileMap[`${process.platform}-${process.arch}`] if (!file) { @@ -191,8 +193,9 @@ export async function downloadAndInstallUpdate(): Promise { 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', [ diff --git a/src/main/utils/updateChecker.ts b/src/main/utils/updateChecker.ts index 95019875..ded80ad3 100644 --- a/src/main/utils/updateChecker.ts +++ b/src/main/utils/updateChecker.ts @@ -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) {} }