feat(layout): 自动更新增加进度条

This commit is contained in:
ZOL4789
2024-10-26 18:14:22 +08:00
committed by nongyehong
parent 62407c4c98
commit 4ee3e2b8a3
14 changed files with 97 additions and 61 deletions

View File

@@ -47,7 +47,7 @@ jobs:
uses: tauri-apps/tauri-action@v0 uses: tauri-apps/tauri-action@v0
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 使用之前配置的私钥` # 使用之前配置的私钥
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
# 使用之前配置的私钥密码 # 使用之前配置的私钥密码
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
@@ -58,9 +58,4 @@ jobs:
releaseDraft: true releaseDraft: true
prerelease: false prerelease: false
- name: Upload assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 运行脚本上传latest.json文件
run: node build/config/updater.mjs

View File

@@ -1,5 +1,7 @@
## [2.4.5](https://github.com/HuLaSpark/HuLa/compare/v2.4.4...v2.4.5) (2024-10-26)
## [2.4.4](https://github.com/HuLaSpark/HuLa/compare/v2.4.3...v2.4.4) (2024-10-26) ## [2.4.4](https://github.com/HuLaSpark/HuLa/compare/v2.4.3...v2.4.4) (2024-10-26)
## [2.4.3](https://github.com/HuLaSpark/HuLa/compare/v2.4.2...v2.4.3) (2024-10-26) ## [2.4.3](https://github.com/HuLaSpark/HuLa/compare/v2.4.2...v2.4.3) (2024-10-26)

View File

@@ -1,7 +1,7 @@
{ {
"name": "hula", "name": "hula",
"type": "module", "type": "module",
"version": "2.4.4", "version": "2.4.0",
"license": "Apache-2.0", "license": "Apache-2.0",
"engines": { "engines": {
"node": ">=18.12.0", "node": ">=18.12.0",

2
src-tauri/Cargo.lock generated
View File

@@ -2107,7 +2107,7 @@ checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9"
[[package]] [[package]]
name = "hula" name = "hula"
version = "2.4.0" version = "2.5.0"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"lazy_static", "lazy_static",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "hula" name = "hula"
version = "2.4.0" version = "2.5.0"
description = "hula" description = "hula"
authors = ["nongyehong"] authors = ["nongyehong"]
license = "" license = ""
@@ -33,13 +33,13 @@ tauri-plugin-dialog = "2.0.1"
tauri-plugin-upload = "2.0.1" tauri-plugin-upload = "2.0.1"
tauri-plugin-global-shortcut = "2.0.1" tauri-plugin-global-shortcut = "2.0.1"
tauri-plugin-clipboard-manager = "2.0.1" tauri-plugin-clipboard-manager = "2.0.1"
tauri-plugin-updater = "2"
[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies] [target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
tauri-plugin-autostart = "2.0.1" tauri-plugin-autostart = "2.0.1"
lazy_static = "1.4" lazy_static = "1.4"
screenshots = "0.5.4" screenshots = "0.5.4"
base64 = "0.22.1" base64 = "0.22.1"
rodio = "0.17.3" rodio = "0.17.3"
tauri-plugin-updater = "2"
[features] [features]
# by default Tauri runs in production mode # by default Tauri runs in production mode

View File

@@ -52,6 +52,8 @@
"autostart:allow-enable", "autostart:allow-enable",
"autostart:allow-disable", "autostart:allow-disable",
"autostart:allow-is-enabled", "autostart:allow-is-enabled",
"dialog:allow-confirm",
"core:resources:allow-close",
{ {
"identifier": "http:default", "identifier": "http:default",
"allow": [ "allow": [

View File

@@ -5,7 +5,11 @@
"windows", "windows",
"linux" "linux"
], ],
"windows":["home"],
"permissions": [ "permissions": [
"updater:default" "updater:default",
"updater:allow-check",
"updater:allow-download",
"updater:allow-install"
] ]
} }

View File

@@ -1 +1 @@
{"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["*"],"permissions":["core:window:default","core:window:allow-create","core:window:allow-start-dragging","core:window:allow-close","core:window:allow-hide","core:window:allow-center","core:window:allow-show","core:window:allow-maximize","core:window:allow-minimize","core:window:allow-destroy","core:window:allow-is-focused","core:window:allow-is-fullscreen","core:window:allow-set-focus","core:window:allow-set-position","core:window:allow-scale-factor","core:window:allow-unminimize","core:window:allow-set-always-on-top","core:window:allow-set-size","core:window:allow-set-min-size","core:window:allow-unmaximize","core:window:allow-set-fullscreen","core:webview:allow-create-webview","core:webview:allow-create-webview-window","core:webview:allow-internal-toggle-devtools","core:webview:allow-set-webview-size","core:webview:allow-webview-size","core:event:default","core:event:allow-listen","os:default","os:allow-os-type","os:allow-arch","os:allow-version","os:allow-hostname","process:default","process:allow-exit","clipboard-manager:allow-clear","clipboard-manager:allow-write-image","http:allow-fetch","http:allow-fetch-cancel","http:allow-fetch-read-body","http:allow-fetch-send","core:tray:default","core:tray:allow-get-by-id","shell:default","shell:allow-open","autostart:allow-enable","autostart:allow-disable","autostart:allow-is-enabled",{"identifier":"http:default","allow":[{"url":"http://**"},{"url":"https://**"},{"url":"http://*:*"},{"url":"https://*:*"}]}]},"desktop-capability":{"identifier":"desktop-capability","description":"","local":true,"permissions":["updater:default"],"platforms":["macOS","windows","linux"]}} {"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["*"],"permissions":["core:window:default","core:window:allow-create","core:window:allow-start-dragging","core:window:allow-close","core:window:allow-hide","core:window:allow-center","core:window:allow-show","core:window:allow-maximize","core:window:allow-minimize","core:window:allow-destroy","core:window:allow-is-focused","core:window:allow-is-fullscreen","core:window:allow-set-focus","core:window:allow-set-position","core:window:allow-scale-factor","core:window:allow-unminimize","core:window:allow-set-always-on-top","core:window:allow-set-size","core:window:allow-set-min-size","core:window:allow-unmaximize","core:window:allow-set-fullscreen","core:webview:allow-create-webview","core:webview:allow-create-webview-window","core:webview:allow-internal-toggle-devtools","core:webview:allow-set-webview-size","core:webview:allow-webview-size","core:event:default","core:event:allow-listen","os:default","os:allow-os-type","os:allow-arch","os:allow-version","os:allow-hostname","process:default","process:allow-exit","clipboard-manager:allow-clear","clipboard-manager:allow-write-image","http:allow-fetch","http:allow-fetch-cancel","http:allow-fetch-read-body","http:allow-fetch-send","core:tray:default","core:tray:allow-get-by-id","shell:default","shell:allow-open","autostart:allow-enable","autostart:allow-disable","autostart:allow-is-enabled","dialog:allow-confirm","core:resources:allow-close",{"identifier":"http:default","allow":[{"url":"http://**"},{"url":"https://**"},{"url":"http://*:*"},{"url":"https://*:*"}]}]},"desktop-capability":{"identifier":"desktop-capability","description":"","local":true,"windows":["home"],"permissions":["updater:default","updater:allow-check","updater:allow-download","updater:allow-install"],"platforms":["macOS","windows","linux"]}}

View File

@@ -25,6 +25,7 @@ impl<R: Runtime> CustomInit for tauri::Builder<R> {
MacosLauncher::LaunchAgent, MacosLauncher::LaunchAgent,
Some(vec!["--flag1", "--flag2"]), Some(vec!["--flag1", "--flag2"]),
)) ))
.plugin(tauri_plugin_updater::Builder::new().build())
} }
// 初始化web窗口事件 // 初始化web窗口事件

View File

@@ -1,6 +1,6 @@
{ {
"productName": "HuLa", "productName": "HuLa",
"version": "2.4.4", "version": "2.5.0",
"identifier": "com.tauri.build", "identifier": "com.tauri.build",
"build": { "build": {
"beforeDevCommand": "pnpm dev", "beforeDevCommand": "pnpm dev",
@@ -28,11 +28,14 @@
}, },
"plugins": { "plugins": {
"updater": { "updater": {
"active": true,
"windows": { "windows": {
"installMode": "passive" "installMode": "passive"
}, },
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDk1NkNENEZFNzg1MjVFMEEKUldRS1hsSjQvdFJzbGJXcnNPNXBYZ2RlTmlRRFZYYVI3YXhiWGpYZXFwVUtucThZUnJHUGw5dVUK", "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDk1NkNENEZFNzg1MjVFMEEKUldRS1hsSjQvdFJzbGJXcnNPNXBYZ2RlTmlRRFZYYVI3YXhiWGpYZXFwVUtucThZUnJHUGw5dVUK",
"endpoint": "https://github.com/HuLaSpark/HuLa/releases/latest/download//latest.json" "endpoints": [
"https://github.com/HuLaSpark/HuLa/releases/latest/download/latest.json"
]
} }
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"productName": "HuLa", "productName": "HuLa",
"version": "2.4.4", "version": "2.5.0",
"identifier": "com.tauri.build", "identifier": "com.tauri.build",
"build": { "build": {
"beforeDevCommand": "pnpm dev", "beforeDevCommand": "pnpm dev",
@@ -14,7 +14,7 @@
], ],
"active": true, "active": true,
"targets": [ "targets": [
"dmg" "app"
], ],
"icon": [ "icon": [
"icons/macos/32x32.png", "icons/macos/32x32.png",

View File

@@ -1,6 +1,6 @@
{ {
"productName": "HuLa", "productName": "HuLa",
"version": "2.4.4", "version": "2.5.0",
"identifier": "com.tauri.build", "identifier": "com.tauri.build",
"build": { "build": {
"beforeDevCommand": "pnpm dev", "beforeDevCommand": "pnpm dev",

View File

@@ -10,7 +10,8 @@ import {
NTimeline, NTimeline,
NScrollbar, NScrollbar,
NSkeleton, NSkeleton,
NIcon NIcon,
NProgress
} from 'naive-ui' } from 'naive-ui'
import { FormInst } from 'naive-ui' import { FormInst } from 'naive-ui'
import { useSettingStore } from '@/stores/setting.ts' import { useSettingStore } from '@/stores/setting.ts'
@@ -20,6 +21,8 @@ import pkg from '~/package.json'
import { handRelativeTime } from '@/utils/Day.ts' import { handRelativeTime } from '@/utils/Day.ts'
import './style.scss' import './style.scss'
import { type } from '@tauri-apps/plugin-os' import { type } from '@tauri-apps/plugin-os'
import { check } from '@tauri-apps/plugin-updater'
import { relaunch } from '@tauri-apps/plugin-process'
const formRef = ref<FormInst | null>() const formRef = ref<FormInst | null>()
const formValue = ref({ const formValue = ref({
@@ -120,9 +123,11 @@ export const CheckUpdate = defineComponent(() => {
const newVersion = ref() const newVersion = ref()
const loading = ref(false) const loading = ref(false)
const checkLoading = ref(false) const checkLoading = ref(false)
const updating = ref(false)
/** 版本更新日期 */ /** 版本更新日期 */
const versionTime = ref('') const versionTime = ref('')
const newVersionTime = ref('') const newVersionTime = ref('')
const percentage = ref(0)
// const commitTypeMap: { [key: string]: string } = { // const commitTypeMap: { [key: string]: string } = {
// feat: 'feat', // feat: 'feat',
@@ -161,7 +166,7 @@ export const CheckUpdate = defineComponent(() => {
} }
/* 记录检测更新的版本 */ /* 记录检测更新的版本 */
let lastVersion: string | null = null //let lastVersion: string | null = null
const getCommitLog = (url: string, isNew = false) => { const getCommitLog = (url: string, isNew = false) => {
fetch(url).then((res) => { fetch(url).then((res) => {
@@ -197,54 +202,67 @@ export const CheckUpdate = defineComponent(() => {
}) })
} }
const handleUpdate = () => { const handleUpdate = async () => {
window.$message.warning('更新功能暂未开放,敬请期待, 请到github或gitee下载最新版本') updating.value = true
} if (!(await window.confirm('确定更新吗'))) {
const checkUpdate = () => {
const url = `https://gitee.com/api/v5/repos/HuLaSpark/HuLa/tags?access_token=${import.meta.env.VITE_GITEE_TOKEN}&sort=name&direction=desc&page=1&per_page=1`
if (lastVersion && lastVersion === `v${pkg.version}`) {
window.$message.success('当前已是最新版本')
return return
} }
checkLoading.value = true checkLoading.value = true
fetch(url).then((res) => { await check()
res .then(async (e) => {
.json() if (!e?.available) {
.then(async (data) => { return
if (data[0].name === `v${pkg.version}`) { }
setTimeout(() => { let contentLength = 0
window.$message.success('当前已是最新版本') let downloaded = 0
lastVersion = `v${pkg.version}`
checkLoading.value = false await e.downloadAndInstall((event) => {
}, 600) switch (event.event) {
} else { case 'Started':
setTimeout(() => { contentLength = event.data.contentLength ? event.data.contentLength : 0
let url = `https://gitee.com/api/v5/repos/HuLaSpark/HuLa/tags?access_token=${import.meta.env.VITE_GITEE_TOKEN}&sort=name&direction=asc&page=1` console.log(`started downloading ${event.data.contentLength} bytes`)
fetch(url).then((res) => { break
res.json().then(async (data) => { case 'Progress':
const allVersion = [] as number[] downloaded += event.data.chunkLength
data.forEach((item: any) => { //console.log(`downloaded ${downloaded} from ${contentLength}`);
// 只获取item.name中[1,4]的内容 percentage.value = contentLength / downloaded
allVersion.push(Number(item.name.slice(1, 4))) break
}) case 'Finished':
newVersion.value = `v${Math.max(...allVersion)}.0` console.log('download finished')
url = `https://gitee.com/api/v5/repos/HuLaSpark/HuLa/releases/tags/${newVersion.value}?access_token=${import.meta.env.VITE_GITEE_TOKEN}` break
getCommitLog(url, true)
text.value = '立即更新'
checkLoading.value = false
})
})
window.$message.success('有新版本发布,请下载最新版本')
// TODO 获取最新版本的提交日志,并且更换按钮文字为下载最新版本 (nyh -> 2024-07-11 22:20:33)
}, 1200)
} }
}) })
.catch(() => { window.$message.success('安装包下载成功3s后重启并安装')
setTimeout(() => {
updating.value = false
relaunch()
}, 3000)
})
.catch(() => {
window.$message.error('检查更新错误,请稍后再试')
})
.finally(() => {
checkLoading.value = false
updating.value = false
})
}
const checkUpdate = async () => {
checkLoading.value = true
await check()
.then((e) => {
if (!e?.available) {
checkLoading.value = false checkLoading.value = false
window.$message.error('请检查配置配置好token后再试') return
}) }
}) newVersion.value = e?.version
text.value = '立即更新'
checkLoading.value = false
})
.catch(() => {
checkLoading.value = false
window.$message.error('检查更新错误,请稍后再试')
})
} }
const init = () => { const init = () => {
@@ -254,6 +272,7 @@ export const CheckUpdate = defineComponent(() => {
onMounted(() => { onMounted(() => {
init() init()
getCommitLog(url.value) getCommitLog(url.value)
checkUpdate()
}) })
return () => ( return () => (
<NModal v-model:show={lock.value.modalShow} maskClosable={false} class="w-350px border-rd-8px"> <NModal v-model:show={lock.value.modalShow} maskClosable={false} class="w-350px border-rd-8px">
@@ -375,6 +394,15 @@ export const CheckUpdate = defineComponent(() => {
{text.value} {text.value}
</NButton> </NButton>
)} )}
{updating.value && (
<NProgress
type="line"
color="#13987f"
indicator-placement="inside"
percentage={percentage.value}
processing
/>
)}
</NFlex> </NFlex>
</NFlex> </NFlex>
)} )}

View File

@@ -47,6 +47,7 @@ declare module 'vue' {
NPopconfirm: typeof import('naive-ui')['NPopconfirm'] NPopconfirm: typeof import('naive-ui')['NPopconfirm']
NPopover: typeof import('naive-ui')['NPopover'] NPopover: typeof import('naive-ui')['NPopover']
NPopselect: typeof import('naive-ui')['NPopselect'] NPopselect: typeof import('naive-ui')['NPopselect']
NProgress: typeof import('naive-ui')['NProgress']
NQrCode: typeof import('naive-ui')['NQrCode'] NQrCode: typeof import('naive-ui')['NQrCode']
NRadio: typeof import('naive-ui')['NRadio'] NRadio: typeof import('naive-ui')['NRadio']
NScrollbar: typeof import('naive-ui')['NScrollbar'] NScrollbar: typeof import('naive-ui')['NScrollbar']