Skip to content

Commit

Permalink
定时检查更新状态
Browse files Browse the repository at this point in the history
  • Loading branch information
hanaTsuk1 committed Sep 22, 2024
1 parent d57fe0c commit f5d3fcb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/components/statusBar/StatusBar.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<script setup lang="ts">
const timeStore = useTimerStore()
const historyStore = useHistoryStore()
const updateStore = useUpdateStore()
const { time, running, text } = storeToRefs(timeStore)
const { requesting, progress } = storeToRefs(historyStore)
const { needUpdate } = storeToRefs(updateStore)
const { start: startUpdate } = updateStore
const route = useRoute()
const { xs, sm } = useTailwindBreakpoints()
Expand All @@ -16,12 +20,21 @@ const timerText = computed(() => route.fullPath == '/timer' ? text.value : `#${t
function navigateTimer() {
router.push('/timer')
}
async function update() {
const open = await startUpdate(true)
open?.()
}
</script>

<template>
<div v-show="xs" id="status-bar-xs" px-4 flex h-full items-center relative />
<div v-show="sm" px-4 flex items-center>
<div v-show="sm" px-4 flex items-center space-x-1>
<div flex-1 />
<status-bar-button
v-if="needUpdate" :tooltip="$t('statusBar.update.tooltip')" :text="$t('statusBar.update.text')"
icon="i-mdi:new-box" color="info" variant="flat" @click="update"
/>
<status-bar-button v-if="requesting" :tooltip="$t('statusBar.timeline.history.tooltip')">
<div flex items-center space-x-1>
<div>{{ $t('statusBar.timeline.history.text') }}</div>
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ statusBar:
search:
text: Search
tooltip: Search
update:
text: New version released
tooltip: Click to update
gridCard:
move: Move
sync:
Expand Down
3 changes: 3 additions & 0 deletions src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ statusBar:
search:
text: 搜索
tooltip: 搜索
update:
text: 新版本已发布
tooltip: 点击更新
gridCard:
move: 移动
sync:
Expand Down
19 changes: 16 additions & 3 deletions src/stores/useUpdateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ export const useUpdateStore = defineStore('update', () => {
const { config } = storeToRefs(configStore)

const updating = ref(false)
const needUpdate = ref(false)

async function getUpdate() {
return await check({
timeout: 6,
})
}

async function start(showInfo = false) {
updating.value = true
let update: Update | null
try {
update = await check({
timeout: 6,
})
update = await getUpdate()
}
catch (e) {
updating.value = false
Expand All @@ -31,6 +36,7 @@ export const useUpdateStore = defineStore('update', () => {
}

if (update) {
needUpdate.value = true
const openModal = () => {
confirm.require({
title: t('updater.title'),
Expand Down Expand Up @@ -85,8 +91,15 @@ export const useUpdateStore = defineStore('update', () => {
}
})

const _timer = new Timer(async () => {
const update = await getUpdate()
if (update)
needUpdate.value = true
}, calcDuration(6, 'hour'))

return {
start,
updating,
needUpdate,
}
})

0 comments on commit f5d3fcb

Please sign in to comment.