feat: check on startup, prompt before applying update

This commit is contained in:
Timi
2026-11-07 17:42:46 +08:00
parent b76b745e0d
commit 9d28a5c6cb
4 changed files with 277 additions and 205 deletions
+80 -83
View File
@@ -1,5 +1,5 @@
<template>
<div class="tui-page-layout tui-navbar">
<div class="tui-page-layout settings-page tui-navbar">
<t-navbar
fixed
:z-index="20"
@@ -8,90 +8,90 @@
@left-click="$router.back()"
/>
<main class="tui-page-content scroll column">
<div class="settings-page">
<t-cell-group title="显示" theme="card" v-entrance-transition>
<t-cell class="theme" title="显示模式">
<template #right-icon>
<segmented-slider
class="theme-slider"
:model-value="globalUIStore.themeMode"
:options="themeOptions"
@change="handleThemeChange"
<t-cell-group title="显示" theme="card" v-entrance-transition>
<t-cell class="theme" title="显示模式">
<template #right-icon>
<segmented-slider
class="theme-slider"
:model-value="globalUIStore.themeMode"
:options="themeOptions"
@change="handleThemeChange"
/>
</template>
</t-cell>
</t-cell-group>
<t-cell-group title="声音" theme="card" v-entrance-transition>
<t-cell title="扫码成功">
<template #right-icon>
<t-switch :model-value="settingStore.sound.scanSuccess" @change="value => handleScanSuccessChange(value === true)" />
</template>
</t-cell>
<t-cell title="登记成功">
<template #right-icon>
<t-switch :model-value="settingStore.sound.registerSuccess" @change="value => handleRegisterSuccessChange(value === true)" />
</template>
</t-cell>
<t-cell title="音量">
<template #right-icon>
<div class="volume-field">
<t-slider
:model-value="settingStore.sound.volume"
:min="0"
:max="100"
:step="1"
@change="handleVolumeChange"
/>
</template>
</t-cell>
</t-cell-group>
<t-cell-group title="声音" theme="card" v-entrance-transition>
<t-cell title="扫码成功">
<template #right-icon>
<t-switch :model-value="settingStore.sound.scanSuccess" @change="value => handleScanSuccessChange(value === true)" />
</template>
</t-cell>
<t-cell title="登记成功">
<template #right-icon>
<t-switch :model-value="settingStore.sound.registerSuccess" @change="value => handleRegisterSuccessChange(value === true)" />
</template>
</t-cell>
<t-cell title="音量">
<template #right-icon>
<div class="volume-field">
<t-slider
:model-value="settingStore.sound.volume"
:min="0"
:max="100"
:step="1"
@change="handleVolumeChange"
/>
<span v-text="`${settingStore.sound.volume}%`" />
</div>
</template>
</t-cell>
</t-cell-group>
<span v-text="`${settingStore.sound.volume}%`" />
</div>
</template>
</t-cell>
</t-cell-group>
<t-cell-group v-if="updateSupported" title="版本更新" theme="card" v-entrance-transition>
<t-cell title="外壳版本" :note="nativeVersion || '—'" />
<t-cell title="系统版本" :note="currentVersion || '—'" />
<t-cell title="自动检查更新">
<t-cell v-if="latestVersionText" title="最新版本" :note="latestVersionText" />
<t-cell title="自动更新">
<template #right-icon>
<t-switch :model-value="autoUpdate" @change="handleAutoUpdateChange" />
</template>
</t-cell>
</t-cell-group>
<div v-if="updateSupported" class="update-panel" v-entrance-transition>
<center-tips v-if="updateHint" v-text="updateHint" />
<t-button
v-if="updateStage === 'check'"
class="cell-button"
theme="primary"
size="large"
:loading="checking"
@click="handleCheck"
>
检查更新
<!-- <div v-if="updateSupported" class="update-panel" v-entrance-transition>-->
<div class="update-panel" v-entrance-transition>
<center-tips v-if="updateHint" v-text="updateHint" />
<t-button
v-if="updateStage === 'check'"
class="cell-button"
theme="primary"
size="large"
:loading="checking"
@click="handleCheck"
>
检查更新
</t-button>
<t-button
v-else-if="updateStage === 'download'"
class="cell-button"
theme="primary"
size="large"
@click="handleDownload"
>
下载更新
</t-button>
<template v-else-if="updateStage === 'downloading'">
<t-progress class="progress" stroke-width=".5rem" :percentage="percent" /> <t-button theme="primary" size="large" block disabled>
下载中 {{ percent }}%
</t-button>
<t-button
v-else-if="updateStage === 'download'"
class="cell-button"
theme="primary"
size="large"
@click="handleDownload"
>
下载更新
</t-button>
<template v-else-if="updateStage === 'downloading'">
<t-progress class="progress" stroke-width=".5rem" :percentage="percent" /> <t-button theme="primary" size="large" block disabled>
下载中 {{ percent }}%
</t-button>
</template>
<t-button
v-else-if="updateStage === 'apply'"
class="cell-button"
theme="primary"
size="large"
@click="handleApply"
>
现在更新
</t-button>
</div>
</template>
<t-button
v-else-if="updateStage === 'apply'"
class="cell-button"
theme="primary"
size="large"
@click="handleApply"
>
现在更新
</t-button>
</div>
</main>
</div>
@@ -102,7 +102,7 @@ import type { ThemeMode } from "@/store/globalUI";
import { useGlobalUIStore } from "@/store/globalUI";
import SegmentedSlider from "@/components/SegmentedSlider.vue";
import { useSettingStore } from "@/store/settingStore";
import { AUTO_UPDATE_KEY, isAutoUpdateEnabled, useAppUpdate } from "@/composables/useAppUpdate";
import { setAutoUpdate, useAppUpdate } from "@/composables/useAppUpdate";
import { Message } from "@/utils/message";
defineOptions({
@@ -172,6 +172,7 @@ const {
percent,
ready,
error: updateError,
autoUpdate,
loadCurrent,
check,
hasUpdate,
@@ -180,7 +181,8 @@ const {
restorePending
} = useAppUpdate();
const autoUpdate = ref(isAutoUpdateEnabled());
/** 有更新时展示目标版本号 */
const latestVersionText = computed<string>(() => (hasUpdate() ? `v${latest.value?.version ?? ""}` : ""));
/** 当前所处的更新阶段 */
const updateStage = computed<"check" | "download" | "downloading" | "apply">(() => {
@@ -219,9 +221,7 @@ onMounted(async () => {
});
function handleAutoUpdateChange(value: boolean | string | number): void {
const enabled = value === true;
autoUpdate.value = enabled;
localStorage.setItem(AUTO_UPDATE_KEY, enabled ? "1" : "0");
setAutoUpdate(value === true);
}
async function handleCheck(): Promise<void> {
@@ -255,9 +255,6 @@ async function handleApply(): Promise<void> {
<style scoped lang="less">
.settings-page {
padding: 0 0 1rem 0;
display: flex;
flex-direction: column;
.theme {