mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-07 05:42:42 +08:00
fix(version): skip mismatch toast in dev and harden sw fallback
This commit is contained in:
@@ -12,7 +12,18 @@ declare let self: ServiceWorkerGlobalScope & {
|
||||
|
||||
// 缓存版本控制
|
||||
const RESOURCE_VERSION = 'V2'
|
||||
const CACHE_VERSION = `${__APP_VERSION__}-${__BUILD_TIME__}` // 开发环境下无法使用此环境变量,生产环境正常
|
||||
// 开发态 dev-sw 可能拿不到 Vite define 注入;仅在开发环境做 dev 兜底
|
||||
const hasAppVersion = typeof __APP_VERSION__ !== 'undefined'
|
||||
const hasBuildTime = typeof __BUILD_TIME__ !== 'undefined'
|
||||
const isDev = import.meta.env.DEV
|
||||
|
||||
if (!isDev && (!hasAppVersion || !hasBuildTime)) {
|
||||
throw new Error('[SW] Missing __APP_VERSION__ or __BUILD_TIME__ in production build')
|
||||
}
|
||||
|
||||
const appVersion = hasAppVersion ? __APP_VERSION__ : 'dev'
|
||||
const buildTime = hasBuildTime ? __BUILD_TIME__ : 'dev'
|
||||
const CACHE_VERSION = `${appVersion}-${buildTime}`
|
||||
|
||||
// 启用导航预载
|
||||
navigationPreload.enable()
|
||||
|
||||
@@ -23,6 +23,14 @@ export const useGlobalSettingsStore = defineStore('globalSettings', {
|
||||
|
||||
// 检查版本更新
|
||||
if (result.FRONTEND_VERSION) {
|
||||
const isBackendDev = Boolean(result.BACKEND_DEV)
|
||||
const skipVersionCheck = import.meta.env.DEV || isBackendDev
|
||||
|
||||
if (skipVersionCheck) {
|
||||
console.log('[VersionChecker] 开发环境下跳过版本一致性检查')
|
||||
return
|
||||
}
|
||||
|
||||
const { checkVersion } = useVersionChecker()
|
||||
await checkVersion(result.FRONTEND_VERSION)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user