optimize(projects): optimize setupAppVersionNotification

This commit is contained in:
Soybean 2024-06-13 23:44:20 +08:00
parent 79e85bc6b5
commit b5a723cb5f

View File

@ -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;
}
});
}