diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 917a45b8..0eeaa971 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index f54178f4..42ee0df6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package.json b/package.json index a0e0dbec..30b4a07b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index efc6b331..cd76da4c 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2107,7 +2107,7 @@ checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "hula" -version = "2.4.0" +version = "2.5.0" dependencies = [ "base64 0.22.1", "lazy_static", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2750347e..88dada65 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -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 diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 8c938781..05ff8499 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -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": [ diff --git a/src-tauri/capabilities/desktop.json b/src-tauri/capabilities/desktop.json index 00ff1a69..067e7744 100644 --- a/src-tauri/capabilities/desktop.json +++ b/src-tauri/capabilities/desktop.json @@ -5,7 +5,11 @@ "windows", "linux" ], + "windows":["home"], "permissions": [ - "updater:default" + "updater:default", + "updater:allow-check", + "updater:allow-download", + "updater:allow-install" ] } \ No newline at end of file diff --git a/src-tauri/gen/schemas/capabilities.json b/src-tauri/gen/schemas/capabilities.json index 05a81610..3503f69e 100644 --- a/src-tauri/gen/schemas/capabilities.json +++ b/src-tauri/gen/schemas/capabilities.json @@ -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"]}} \ No newline at end of file +{"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"]}} \ No newline at end of file diff --git a/src-tauri/src/init.rs b/src-tauri/src/init.rs index e26d2ea9..96439f37 100644 --- a/src-tauri/src/init.rs +++ b/src-tauri/src/init.rs @@ -25,6 +25,7 @@ impl CustomInit for tauri::Builder { MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"]), )) + .plugin(tauri_plugin_updater::Builder::new().build()) } // 初始化web窗口事件 diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 6ba67602..5b8efe23 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -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" + ] } } } diff --git a/src-tauri/tauri.macos.conf.json b/src-tauri/tauri.macos.conf.json index 523c9b74..dc692035 100644 --- a/src-tauri/tauri.macos.conf.json +++ b/src-tauri/tauri.macos.conf.json @@ -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", diff --git a/src-tauri/tauri.windows.conf.json b/src-tauri/tauri.windows.conf.json index 2ec32089..b583a389 100644 --- a/src-tauri/tauri.windows.conf.json +++ b/src-tauri/tauri.windows.conf.json @@ -1,6 +1,6 @@ { "productName": "HuLa", - "version": "2.4.4", + "version": "2.5.0", "identifier": "com.tauri.build", "build": { "beforeDevCommand": "pnpm dev", diff --git a/src/layout/left/model.tsx b/src/layout/left/model.tsx index 824fe50b..73c4b8fb 100644 --- a/src/layout/left/model.tsx +++ b/src/layout/left/model.tsx @@ -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() 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 () => ( @@ -375,6 +394,15 @@ export const CheckUpdate = defineComponent(() => { {text.value} )} + {updating.value && ( + + )} )} diff --git a/src/typings/components.d.ts b/src/typings/components.d.ts index acfc2432..94ec2235 100644 --- a/src/typings/components.d.ts +++ b/src/typings/components.d.ts @@ -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']