Skip to content

Commit

Permalink
feat: check update for ui (#57)
Browse files Browse the repository at this point in the history
* feat: check update for ui

* chore: use fetch

---------

Co-authored-by: Zephyruso <176294927+Zephyruso@users.noreply.github.com>
  • Loading branch information
lamprose and Zephyruso authored Dec 6, 2024
1 parent 6f2a6f6 commit ba16c7e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ axios.interceptors.request.use((config) => {
activeBackend.value?.host +
':' +
activeBackend.value?.port

config.headers['Authorization'] = 'Bearer ' + activeBackend.value?.password
return config
})
Expand Down Expand Up @@ -156,3 +157,10 @@ export const fetchMemoryAPI = <T>() => {
export const fetchTrafficAPI = <T>() => {
return createWebSocket<T>('traffic')
}

export const fetchIsUIUpdateAvailable = async () => {
const response = await fetch('https://api.github.com/repos/Zephyruso/zashboard/releases/latest')
const { tag_name } = await response.json()

return tag_name !== `v${zashboardVersion.value}`
}
27 changes: 21 additions & 6 deletions src/views/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
<div class="grid grid-cols-1 gap-2 overflow-y-auto p-2">
<div class="card card-compact bg-base-100 shadow-lg">
<div class="card-title px-4 pt-4 text-primary">
<a
href="https://github.com/Zephyruso/zashboard"
target="_blank"
>zashboard v{{ zashboardVersion }}</a
>
<div class="indicator">
<span
v-if="isUIUpdateAvailable"
class="indicator-item flex"
>
<span class="badge badge-xs absolute animate-ping bg-secondary"></span>
<span class="badge badge-xs bg-secondary"></span>
</span>
<a
href="https://github.com/Zephyruso/zashboard"
target="_blank"
>zashboard v{{ zashboardVersion }}</a
>
</div>
</div>
<div class="card-body gap-4">
<div class="flex items-center gap-2">
Expand Down Expand Up @@ -228,6 +237,7 @@

<script setup lang="ts">
import {
fetchIsUIUpdateAvailable,
flushFakeIPAPI,
isSingBox,
reloadConfigsAPI,
Expand Down Expand Up @@ -256,7 +266,7 @@ import {
useConnectionCard,
} from '@/store/settings'
import { twMerge } from 'tailwind-merge'
import { ref } from 'vue'
import { onMounted, ref } from 'vue'
const isCoreUpgrading = ref(false)
const handlerClickUpgradeCore = async () => {
Expand All @@ -270,6 +280,7 @@ const handlerClickUpgradeCore = async () => {
}
}
const isUIUpdateAvailable = ref(false)
const isUIUpgrading = ref(false)
const handlerClickUpgradeUI = async () => {
if (isUIUpgrading.value) return
Expand All @@ -282,6 +293,10 @@ const handlerClickUpgradeUI = async () => {
}
}
onMounted(async () => {
isUIUpdateAvailable.value = await fetchIsUIUpdateAvailable()
})
const isConfigReloading = ref(false)
const handlerClickReloadConfigs = async () => {
if (isConfigReloading.value) return
Expand Down

0 comments on commit ba16c7e

Please sign in to comment.