|
| 1 | +<script setup lang="ts"> |
| 2 | +import { getVersion } from '@tauri-apps/api/app' |
| 3 | +import { computed, onMounted, ref } from 'vue' |
| 4 | +import { useI18n } from 'vue-i18n' |
| 5 | +import { SettingsFeedback } from '@/components/settings' |
| 6 | +import { Button } from '@/components/ui/button' |
| 7 | +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' |
| 8 | +import { useAppUpdater } from '@/composables/useAppUpdater' |
| 9 | +import { version as buildVersion } from '../../../../package.json' |
| 10 | +
|
| 11 | +const { t } = useI18n() |
| 12 | +const version = ref(buildVersion) |
| 13 | +const { |
| 14 | + checkForUpdates, |
| 15 | + downloadAndInstall, |
| 16 | + isChecking, |
| 17 | + isDownloading, |
| 18 | + isInstalling, |
| 19 | + updateAvailable, |
| 20 | + updateInfo, |
| 21 | + downloadProgress, |
| 22 | + updateError, |
| 23 | + isRestarting, |
| 24 | + isUpToDate, |
| 25 | +} = useAppUpdater() |
| 26 | +
|
| 27 | +const busy = computed(() => isChecking.value || isDownloading.value || isInstalling.value || isRestarting.value) |
| 28 | +const updateLabel = computed(() => { |
| 29 | + if (isRestarting.value) |
| 30 | + return t('updater.restarting') |
| 31 | + if (isInstalling.value) |
| 32 | + return t('pages.settings.updates.installing') |
| 33 | + if (isDownloading.value) |
| 34 | + return downloadProgress.value === null ? t('updater.downloading') : t('updater.downloadingPercent', { percent: downloadProgress.value }) |
| 35 | + if (isChecking.value) |
| 36 | + return t('pages.settings.updates.checking') |
| 37 | + return updateAvailable.value ? t('updater.updateNow') : t('pages.settings.updates.check') |
| 38 | +}) |
| 39 | +const feedbackLabel = computed(() => { |
| 40 | + if (updateError.value) |
| 41 | + return t('pages.settings.feedback.failed') |
| 42 | + if (busy.value) |
| 43 | + return updateLabel.value |
| 44 | + return updateAvailable.value |
| 45 | + ? t('updater.newVersion', { version: updateInfo.value?.version }) |
| 46 | + : t('updater.upToDate') |
| 47 | +}) |
| 48 | +
|
| 49 | +const handleUpdate = async () => { |
| 50 | + if (updateAvailable.value) |
| 51 | + await downloadAndInstall() |
| 52 | + else |
| 53 | + await checkForUpdates(true, { includeSkipped: true }) |
| 54 | +} |
| 55 | +
|
| 56 | +onMounted(() => { |
| 57 | + getVersion().then(value => version.value = value).catch(() => {}) |
| 58 | + void checkForUpdates(false, { includeSkipped: true }) |
| 59 | +}) |
| 60 | +</script> |
| 61 | + |
| 62 | +<template> |
| 63 | + <Card> |
| 64 | + <CardHeader> |
| 65 | + <CardTitle>{{ t('pages.settings.about.title') }}</CardTitle> |
| 66 | + <CardDescription>{{ t('pages.settings.about.description') }}</CardDescription> |
| 67 | + </CardHeader> |
| 68 | + <CardContent class="space-y-5"> |
| 69 | + <div class="flex flex-wrap gap-3 items-center justify-between"> |
| 70 | + <div class="space-y-1"> |
| 71 | + <p class="text-sm font-medium flex gap-2 items-center"> |
| 72 | + {{ t('pages.settings.about.version') }} |
| 73 | + <span class="text-muted-foreground font-mono">{{ version }}</span> |
| 74 | + </p> |
| 75 | + <p class="text-xs text-muted-foreground max-w-lg"> |
| 76 | + {{ t('pages.settings.updates.checkForUpdatesHelp') }} |
| 77 | + </p> |
| 78 | + </div> |
| 79 | + <Button variant="outline" size="sm" :disabled="busy" @click="handleUpdate"> |
| 80 | + <span v-if="busy" class="i-carbon-circle-dash mr-2 shrink-0 h-4 w-4 animate-spin" aria-hidden="true" /> |
| 81 | + {{ updateLabel }} |
| 82 | + </Button> |
| 83 | + </div> |
| 84 | + <SettingsFeedback |
| 85 | + v-if="busy || updateError || (isUpToDate && !updateAvailable)" |
| 86 | + :state="updateError ? 'error' : busy ? 'pending' : 'success'" |
| 87 | + :label="feedbackLabel" |
| 88 | + :detail="updateError" |
| 89 | + :progress="isDownloading ? downloadProgress : null" |
| 90 | + /> |
| 91 | + <p v-if="updateAvailable && !busy && !updateError" class="text-sm text-primary-text" role="status"> |
| 92 | + {{ feedbackLabel }} |
| 93 | + </p> |
| 94 | + <div class="text-sm flex gap-3 items-center justify-between"> |
| 95 | + <span class="font-medium">{{ t('pages.settings.about.license') }}</span> |
| 96 | + <span class="text-muted-foreground">{{ t('pages.settings.about.licenseName') }}</span> |
| 97 | + </div> |
| 98 | + <div class="border-t border-border/40" /> |
| 99 | + <a |
| 100 | + href="https://github.com/geek-fun/sqlkit" target="_blank" rel="noopener noreferrer" |
| 101 | + class="text-sm p-2 rounded-md flex flex-wrap gap-2 transition-colors items-center justify-between -mx-2 hover:bg-muted/50" |
| 102 | + > |
| 103 | + <span class="font-medium">{{ t('pages.settings.about.repository') }}</span> |
| 104 | + <span class="text-muted-foreground flex gap-2 items-center"> |
| 105 | + geek-fun/sqlkit <span class="i-carbon-launch h-4 w-4" aria-hidden="true" /> |
| 106 | + </span> |
| 107 | + </a> |
| 108 | + <a |
| 109 | + href="https://www.geekfun.club" target="_blank" rel="noopener noreferrer" |
| 110 | + class="text-sm p-2 rounded-md flex flex-wrap gap-2 transition-colors items-center justify-between -mx-2 hover:bg-muted/50" |
| 111 | + > |
| 112 | + <span class="font-medium">{{ t('pages.settings.about.website') }}</span> |
| 113 | + <span class="text-muted-foreground flex gap-2 items-center"> |
| 114 | + geekfun.club <span class="i-carbon-launch h-4 w-4" aria-hidden="true" /> |
| 115 | + </span> |
| 116 | + </a> |
| 117 | + <p class="text-xs text-muted-foreground pt-2 text-center border-t border-border/40"> |
| 118 | + {{ t('pages.settings.about.copyright', { year: new Date().getFullYear() }) }} |
| 119 | + </p> |
| 120 | + </CardContent> |
| 121 | + </Card> |
| 122 | +</template> |
0 commit comments