From e39cac9f3b5d2f3fbb594d04b6637d174bcae90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92=E8=B5=AB=E8=90=9D?= Date: Wed, 5 Apr 2023 22:55:35 +0800 Subject: [PATCH] :sparkles: Feature: support auto update now --- .github/workflows/main.yml | 2 ++ .github/workflows/manually.yml | 2 ++ package.json | 1 + public/i18n/en.yml | 3 +- public/i18n/zh-CN.yml | 2 ++ public/i18n/zh-TW.yml | 3 +- scripts/config.js | 8 ++++- scripts/link.js | 3 +- scripts/upload-dist-to-r2.js | 7 ++++- src/main/lifeCycle/index.ts | 45 +++++++++++++++++++++++++- src/renderer/pages/PicGoSetting.vue | 1 + src/universal/types/i18n.d.ts | 2 ++ vue.config.js | 9 ++++++ yarn.lock | 49 ++++++++++++++++++++++++++++- 14 files changed, 130 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9194172d..df4407a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,6 +81,8 @@ jobs: yarn upload-dist env: GH_TOKEN: ${{ secrets.GH_TOKEN }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} R2_SECRET_ID: ${{ secrets.R2_SECRET_ID }} R2_SECRET_KEY: ${{ secrets.R2_SECRET_KEY }} R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }} diff --git a/.github/workflows/manually.yml b/.github/workflows/manually.yml index afb88b42..30ef4803 100644 --- a/.github/workflows/manually.yml +++ b/.github/workflows/manually.yml @@ -51,6 +51,8 @@ jobs: yarn upload-dist env: GH_TOKEN: ${{ secrets.GH_TOKEN }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} R2_SECRET_ID: ${{ secrets.R2_SECRET_ID }} R2_SECRET_KEY: ${{ secrets.R2_SECRET_KEY }} R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }} diff --git a/package.json b/package.json index fb473d6e..662c3764 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "cos-nodejs-sdk-v5": "^2.11.19", "custom-electron-titlebar": "^4.1.5", "dexie": "^3.2.3", + "electron-updater": "^5.3.0", "element-plus": "^2.2.32", "fast-xml-parser": "^4.1.1", "form-data": "^4.0.0", diff --git a/public/i18n/en.yml b/public/i18n/en.yml index e794d3ae..bc439d0b 100644 --- a/public/i18n/en.yml +++ b/public/i18n/en.yml @@ -780,7 +780,8 @@ TIPS_SHORTCUT_MODIFIED_SUCCEED: Shortcut modified successfully TIPS_SHORTCUT_MODIFIED_CONFLICT: Shortcut conflict, please reset TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: Custom link style modified successfully TIPS_FIND_NEW_VERSION: Find new version ${v}, update many new features, do you want to download the latest version? - +UPDATE_DOWNLOADED: Update downloaded +TIPS_UPDATE_DOWNLOADED: The update has been downloaded and will be installed on the next app restart. Would you like to restart now? # privacy PRIVACY: > diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml index a953a6ad..5e94d47c 100644 --- a/public/i18n/zh-CN.yml +++ b/public/i18n/zh-CN.yml @@ -781,6 +781,8 @@ TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷键已经修改成功 TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷键冲突,请重新设置 TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: 自定义链接格式已经修改成功 TIPS_FIND_NEW_VERSION: 发现新版本${v},更新了很多功能,是否去下载最新的版本? +UPDATE_DOWNLOADED: 更新已下载 +TIPS_UPDATE_DOWNLOADED: 更新已下载,将在下次启动时安装,是否现在重启? # privacy PRIVACY: > diff --git a/public/i18n/zh-TW.yml b/public/i18n/zh-TW.yml index e4be84e0..d25feb42 100644 --- a/public/i18n/zh-TW.yml +++ b/public/i18n/zh-TW.yml @@ -779,7 +779,8 @@ TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷鍵已經修改成功 TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷鍵衝突,請重新設定 TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: 自訂連結格式已經修改成功 TIPS_FIND_NEW_VERSION: 發現新版本${v},更新了很多功能,是否去下載最新的版本? - +UPDATE_DOWNLOADED: 更新已下載 +TIPS_UPDATE_DOWNLOADED: 更新已下載,将在下次啟動時安裝,是否立即重啟? # privacy PRIVACY: > diff --git a/scripts/config.js b/scripts/config.js index f1b6d6ce..83183636 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -11,7 +11,13 @@ const darwin = [{ ext: '.dmg', arch: '-x64', 'version-file': 'latest-mac.yml' -}] +}, { + appNameWithPrefix: 'PicList-', + ext: '.dmg', + arch: '-universal', + 'version-file': 'latest-mac.yml' +} +] const linux = [{ appNameWithPrefix: 'PicList-', diff --git a/scripts/link.js b/scripts/link.js index 667c254f..af759dd3 100644 --- a/scripts/link.js +++ b/scripts/link.js @@ -2,12 +2,13 @@ const pkg = require('../package.json') const version = pkg.version // TODO: use the same name format const generateURL = (platform, ext, prefix = 'PicList-') => { - return `https://release.piclist.cn/${version}/${prefix}${version}${platform}${ext}` + return `https://release.piclist.cn/latest/${prefix}${version}${platform}${ext}` } const platformExtList = [ ['-arm64', '.dmg', 'PicList-'], ['-x64', '.dmg', 'PicList-'], + ['-universal', '.dmg', 'PicList-'], ['', '.AppImage', 'PicList-'], ['-ia32', '.exe', 'PicList-Setup-'], ['-x64', '.exe', 'PicList-Setup-'], diff --git a/scripts/upload-dist-to-r2.js b/scripts/upload-dist-to-r2.js index f16e7f05..41013886 100644 --- a/scripts/upload-dist-to-r2.js +++ b/scripts/upload-dist-to-r2.js @@ -10,7 +10,7 @@ const path = require('path') const BUCKET = 'piclist-dl' const VERSION = pkg.version -const FILE_PATH = `${VERSION}/` +const FILE_PATH = `latest/` const ACCOUNT_ID = process.env.R2_ACCOUNT_ID const SECRET_ID = process.env.R2_SECRET_ID const SECRET_KEY = process.env.R2_SECRET_KEY @@ -78,6 +78,11 @@ const uploadFile = async () => { Key: `${versionFileName}`, Body: versionFileBuffer }).promise() + await s3.upload({ + Bucket: BUCKET, + Key: `${FILE_PATH}${versionFileName}`, + Body: versionFileBuffer + }).promise() versionFileHasUploaded = true } } diff --git a/src/main/lifeCycle/index.ts b/src/main/lifeCycle/index.ts index 254bd36a..fbd9a7c5 100644 --- a/src/main/lifeCycle/index.ts +++ b/src/main/lifeCycle/index.ts @@ -4,7 +4,8 @@ import { globalShortcut, protocol, Notification, - Menu + Menu, + dialog } from 'electron' import { createProtocol @@ -42,6 +43,7 @@ import { manageIpcList } from '../manage/events/ipcList' import getManageApi from '../manage/Main' import UpDownTaskQueue from '../manage/datastore/upDownTaskQueue' import { T } from '~/main/i18n' +import { UpdateInfo, autoUpdater } from 'electron-updater' const isDevelopment = process.env.NODE_ENV !== 'production' const handleStartUpFiles = (argv: string[], cwd: string) => { @@ -61,6 +63,46 @@ const handleStartUpFiles = (argv: string[], cwd: string) => { } } +autoUpdater.setFeedURL({ + provider: 'generic', + url: 'https://release.piclist.cn/latest', + channel: 'latest' +}) + +autoUpdater.autoDownload = false + +autoUpdater.on('update-available', (info: UpdateInfo) => { + dialog.showMessageBox({ + type: 'info', + title: T('FIND_NEW_VERSION'), + buttons: ['Yes', 'No'], + message: T('TIPS_FIND_NEW_VERSION', { + v: info.version + }) + }).then((result) => { + if (result.response === 0) { + autoUpdater.downloadUpdate() + } + }) +}) + +autoUpdater.on('update-downloaded', () => { + dialog.showMessageBox({ + type: 'info', + title: T('UPDATE_DOWNLOADED'), + buttons: ['Yes', 'No'], + message: T('TIPS_UPDATE_DOWNLOADED') + }).then((result) => { + if (result.response === 0) { + autoUpdater.quitAndInstall() + } + }) +}) + +autoUpdater.on('error', (err) => { + dialog.showErrorBox('error', err.message) +}) + class LifeCycle { private async beforeReady () { protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }]) @@ -111,6 +153,7 @@ class LifeCycle { createTray() db.set('needReload', false) updateChecker() + autoUpdater.checkForUpdatesAndNotify() // 不需要阻塞 process.nextTick(() => { shortKeyHandler.init() diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index aabe1e33..d6f63dad 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -151,6 +151,7 @@