Skip to content

Commit a25785d

Browse files
committed
feat!: automatic update check
1 parent cf53bd8 commit a25785d

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

app.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ locale.value = $settings.lang
1414
1515
useHead({
1616
title: $settings.title,
17+
bodyAttrs: {
18+
class: 'relative',
19+
},
1720
})
1821
</script>

components/Update.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<Teleport v-if="data && data.available" to="body">
3+
<div class="fixed z-20 bottom-[30px] right-[30px] opacity-80 hover:opacity-100 transition-all">
4+
<div class="w-[160px] h-[160px] -z-1 rounded-full bg-brand-600 blur-3xl right-0 -bottom-20 absolute" />
5+
<div class="z-1 relative text-end text-fg-dimmed">
6+
A new version is available <strong>{{ data.version }}</strong><br>
7+
<a :href="`https://github.com/hywax/mafl/releases/tag/v${data.version}`" class="border-b border-dashed" target="_blank">Visit on github →</a>
8+
</div>
9+
</div>
10+
</Teleport>
11+
</template>
12+
13+
<script setup lang="ts">
14+
const { data } = await useFetch('/api/update')
15+
</script>

pages/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
</p>
1717
</template>
1818
</Message>
19+
<Update v-if="$settings.checkUpdates" />
1920
</template>
2021

2122
<script setup lang="ts">
22-
const { $services } = useNuxtApp()
23+
const { $services, $settings } = useNuxtApp()
2324
</script>

server/api/update.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import currentPackage from '~/package.json'
2+
3+
export default defineEventHandler(async () => {
4+
const latestPackage = await $fetch<typeof currentPackage>('https://raw.githubusercontent.com/hywax/mafl/main/package.json', {
5+
parseResponse: (json) => JSON.parse(json),
6+
})
7+
8+
const parseVersion = (version: string): number => Number.parseInt(version.replace(/\./g, ''), 10)
9+
const difference = parseVersion(latestPackage.version) - parseVersion(currentPackage.version)
10+
11+
return {
12+
available: difference > 0,
13+
version: latestPackage.version,
14+
}
15+
})

server/utils/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function getDefaultConfig(): CompleteConfig {
1818
lang: 'en',
1919
theme: 'system',
2020
services: [],
21+
checkUpdates: true,
2122
}
2223
}
2324

types/config.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface Config {
1010
lang: 'en' | 'ru'
1111
theme?: 'system' | 'light' | 'dark' | 'deep'
1212
services: ServicesGroup[]
13+
checkUpdates: boolean
1314
}
1415

1516
export type CompleteConfig = Required<Config>

0 commit comments

Comments
 (0)