2022-04-30 14:05:02 +00:00
|
|
|
import compareVersions from 'compare-versions'
|
|
|
|
import { computed, toRef } from 'vue'
|
2022-07-07 18:05:46 +00:00
|
|
|
import { commonStore } from '@/stores'
|
|
|
|
import { useAuthorization } from '@/composables/useAuthorization'
|
2022-04-30 14:05:02 +00:00
|
|
|
|
|
|
|
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')
|
2022-04-30 14:05:02 +00:00
|
|
|
|
|
|
|
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,
|
2024-10-13 17:37:01 +00:00
|
|
|
latestVersionReleaseUrl,
|
2022-04-30 14:05:02 +00:00
|
|
|
}
|
|
|
|
}
|