Feature: support auto update now

This commit is contained in:
萌萌哒赫萝 2023-04-05 22:55:35 +08:00
parent ca950dbd44
commit e39cac9f3b
14 changed files with 130 additions and 7 deletions

View File

@ -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 }}

View File

@ -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 }}

View File

@ -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",

View File

@ -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: >

View File

@ -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: >

View File

@ -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: >

View File

@ -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-',

View File

@ -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-'],

View File

@ -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
}
}

View File

@ -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()

View File

@ -151,6 +151,7 @@
</el-button>
</el-form-item>
<el-form-item
v-if="false"
:label="$T('SETTINGS_OPEN_UPDATE_HELPER')"
>
<el-switch

View File

@ -730,6 +730,8 @@ interface ILocales {
TIPS_SHORTCUT_MODIFIED_CONFLICT: string
TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: string
TIPS_FIND_NEW_VERSION: string
UPDATE_DOWNLOADED: string
TIPS_UPDATE_DOWNLOADED: string
PRIVACY: string
PRIVACY_TIPS: string
QUIT: string

View File

@ -42,6 +42,14 @@ const config = {
appId: 'com.kuingsmile.piclist',
afterSign: 'scripts/notarize.js',
publish: [
{
provider: 's3',
bucket: 'piclist-dl',
region: 'auto',
acl: 'private',
endpoint: 'https://7ab4ed5cb1f4052a13d3b573876ecf33.r2.cloudflarestorage.com',
path: '/latest'
},
{
provider: 'github',
owner: 'Kuingsmile',
@ -73,6 +81,7 @@ const config = {
target: [{
target: 'dmg',
arch: [
'universal',
'x64',
'arm64'
]

View File

@ -3174,7 +3174,7 @@
resolved "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==
"@types/semver@^7.3.12":
"@types/semver@^7.3.12", "@types/semver@^7.3.6":
version "7.3.13"
resolved "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91"
integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==
@ -4889,6 +4889,14 @@ builder-util-runtime@9.0.3:
debug "^4.3.4"
sax "^1.2.4"
builder-util-runtime@9.1.1:
version "9.1.1"
resolved "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-9.1.1.tgz#2da7b34e78a64ad14ccd070d6eed4662d893bd60"
integrity sha512-azRhYLEoDvRDR8Dhis4JatELC/jUvYjm4cVSj7n9dauGTOM2eeNn9KS0z6YA6oDsjI1xphjNbY6PZZeHPzzqaw==
dependencies:
debug "^4.3.4"
sax "^1.2.4"
builder-util@23.3.3:
version "23.3.3"
resolved "https://registry.npmjs.org/builder-util/-/builder-util-23.3.3.tgz#449ee57ec1ffc7e59f7a3a8a1a33d25cf5e39e43"
@ -6726,6 +6734,21 @@ electron-to-chromium@^1.4.251:
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.284.tgz#61046d1e4cab3a25238f6bf7413795270f125592"
integrity sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA==
electron-updater@^5.3.0:
version "5.3.0"
resolved "https://registry.npmjs.org/electron-updater/-/electron-updater-5.3.0.tgz#3ba0d20407911a2edc5a68bee45c5aa2023e9ff8"
integrity sha512-iKEr7yQBcvnQUPnSDYGSWC9t0eF2YbZWeYYYZzYxdl+HiRejXFENjYMnYjoOm2zxyD6Cr2JTHZhp9pqxiXuCOw==
dependencies:
"@types/semver" "^7.3.6"
builder-util-runtime "9.1.1"
fs-extra "^10.0.0"
js-yaml "^4.1.0"
lazy-val "^1.0.5"
lodash.escaperegexp "^4.1.2"
lodash.isequal "^4.5.0"
semver "^7.3.5"
typed-emitter "^2.1.0"
electron@^22.0.2:
version "22.0.2"
resolved "https://registry.npmmirror.com/electron/-/electron-22.0.2.tgz#256c3f7749bcab5d68dc0ba4ae86c1b60852f0b3"
@ -9675,6 +9698,16 @@ lodash.defaultsdeep@^4.6.1:
resolved "https://registry.npmjs.org/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.1.tgz#512e9bd721d272d94e3d3a63653fa17516741ca6"
integrity sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==
lodash.escaperegexp@^4.1.2:
version "4.1.2"
resolved "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz#64762c48618082518ac3df4ccf5d5886dae20347"
integrity sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==
lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
integrity sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==
lodash.ismatch@^4.4.0:
version "4.4.0"
resolved "https://registry.npmjs.org/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
@ -12129,6 +12162,13 @@ rxjs@^6.4.0:
dependencies:
tslib "^1.9.0"
rxjs@^7.5.2:
version "7.8.0"
resolved "https://registry.npmjs.org/rxjs/-/rxjs-7.8.0.tgz#90a938862a82888ff4c7359811a595e14e1e09a4"
integrity sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg==
dependencies:
tslib "^2.1.0"
safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
@ -13391,6 +13431,13 @@ type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"
typed-emitter@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/typed-emitter/-/typed-emitter-2.1.0.tgz#ca78e3d8ef1476f228f548d62e04e3d4d3fd77fb"
integrity sha512-g/KzbYKbH5C2vPkaXGu8DJlHrGKHLsM25Zg9WuC9pMGfuvT+X25tZQWo5fK1BjBm8+UrVE9LDCvaY0CQk+fXDA==
optionalDependencies:
rxjs "^7.5.2"
typedarray-to-buffer@^3.1.5:
version "3.1.5"
resolved "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080"