optimize(projects): optimize setupAppVersionNotification
This commit is contained in:
parent
79e85bc6b5
commit
b5a723cb5f
@ -3,10 +3,18 @@ import { NButton } from 'naive-ui';
|
||||
import { $t } from '../locales';
|
||||
|
||||
export function setupAppVersionNotification() {
|
||||
let isShow = false;
|
||||
|
||||
document.addEventListener('visibilitychange', async () => {
|
||||
const preConditions = [!isShow, document.visibilityState === 'visible', !import.meta.env.DEV];
|
||||
|
||||
if (!preConditions.every(Boolean)) return;
|
||||
|
||||
const buildTime = await getHtmlBuildTime();
|
||||
|
||||
if (!import.meta.env.DEV && buildTime !== BUILD_TIME && document.visibilityState === 'visible') {
|
||||
if (buildTime !== BUILD_TIME) {
|
||||
isShow = true;
|
||||
|
||||
const n = window.$notification?.create({
|
||||
title: $t('system.updateTitle'),
|
||||
content: $t('system.updateContent'),
|
||||
@ -32,6 +40,9 @@ export function setupAppVersionNotification() {
|
||||
() => $t('system.updateConfirm')
|
||||
)
|
||||
]);
|
||||
},
|
||||
onClose() {
|
||||
isShow = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user