2023-09-19 21:31:18 +00:00
|
|
|
import type { NuxtAppManifestMeta } from '#app'
|
2023-10-21 18:17:53 +00:00
|
|
|
import { defineNuxtPlugin, getAppManifest, onNuxtReady } from '#app'
|
|
|
|
// @ts-expect-error virtual file
|
|
|
|
import { buildAssetsURL } from '#build/paths.mjs'
|
2023-09-19 21:31:18 +00:00
|
|
|
|
|
|
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
|
|
if (import.meta.test) { return }
|
|
|
|
|
|
|
|
let timeout: NodeJS.Timeout
|
|
|
|
|
|
|
|
async function getLatestManifest () {
|
|
|
|
const currentManifest = await getAppManifest()
|
|
|
|
if (timeout) { clearTimeout(timeout) }
|
|
|
|
timeout = setTimeout(getLatestManifest, 1000 * 60 * 60)
|
2023-10-21 18:17:53 +00:00
|
|
|
const meta = await $fetch<NuxtAppManifestMeta>(buildAssetsURL('builds/latest.json'))
|
2023-09-19 21:31:18 +00:00
|
|
|
if (meta.id !== currentManifest.id) {
|
|
|
|
// There is a newer build which we will let the user handle
|
|
|
|
nuxtApp.hooks.callHook('app:manifest:update', meta)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onNuxtReady(() => { timeout = setTimeout(getLatestManifest, 1000 * 60 * 60) })
|
|
|
|
})
|