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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 使用之前配置的私钥`
# 使用之前配置的私钥
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
# 使用之前配置的私钥密码
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
@@ -58,9 +58,4 @@ jobs:
releaseDraft: true
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.3](https://github.com/HuLaSpark/HuLa/compare/v2.4.2...v2.4.3) (2024-10-26)

View File

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

2
src-tauri/Cargo.lock generated
View File

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

View File

@@ -1,6 +1,6 @@
[package]
name = "hula"
version = "2.4.0"
version = "2.5.0"
description = "hula"
authors = ["nongyehong"]
license = ""
@@ -33,13 +33,13 @@ tauri-plugin-dialog = "2.0.1"
tauri-plugin-upload = "2.0.1"
tauri-plugin-global-shortcut = "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]
tauri-plugin-autostart = "2.0.1"
lazy_static = "1.4"
screenshots = "0.5.4"
base64 = "0.22.1"
rodio = "0.17.3"
tauri-plugin-updater = "2"
[features]
# by default Tauri runs in production mode

View File

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

View File

@@ -5,7 +5,11 @@
"windows",
"linux"
],
"windows":["home"],
"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,
Some(vec!["--flag1", "--flag2"]),
))
.plugin(tauri_plugin_updater::Builder::new().build())
}
// 初始化web窗口事件

View File

@@ -1,6 +1,6 @@
{
"productName": "HuLa",
"version": "2.4.4",
"version": "2.5.0",
"identifier": "com.tauri.build",
"build": {
"beforeDevCommand": "pnpm dev",
@@ -28,11 +28,14 @@
},
"plugins": {
"updater": {
"active": true,
"windows": {
"installMode": "passive"
},
"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",
"version": "2.4.4",
"version": "2.5.0",
"identifier": "com.tauri.build",
"build": {
"beforeDevCommand": "pnpm dev",
@@ -14,7 +14,7 @@
],
"active": true,
"targets": [
"dmg"
"app"
],
"icon": [
"icons/macos/32x32.png",

View File

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

View File

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

View File

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