koel/resources/assets/js/composables/useNewVersionNotification.ts

26 lines
865 B
TypeScript
Raw Normal View History

import { useAuthorization } from '@/composables/useAuthorization'
import compareVersions from 'compare-versions'
import { commonStore } from '@/stores'
import { computed, toRef } from 'vue'
export const useNewVersionNotification = () => {
const { isAdmin } = useAuthorization()
2022-06-10 10:47:46 +00:00
const latestVersion = toRef(commonStore.state, 'latest_version')
const currentVersion = toRef(commonStore.state, 'current_version')
const hasNewVersion = computed(() => compareVersions.compare(latestVersion.value, currentVersion.value, '>'))
const shouldNotifyNewVersion = computed(() => isAdmin.value && hasNewVersion.value)
const latestVersionReleaseUrl = computed(() => {
return `https://github.com/koel/koel/releases/tag/${latestVersion.value}`
})
return {
shouldNotifyNewVersion,
currentVersion,
latestVersion,
latestVersionReleaseUrl
}
}