Skip to content

Commit

Permalink
optimize(projects): optimize setupAppVersionNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jun 13, 2024
1 parent 79e85bc commit b5a723c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/plugins/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -32,6 +40,9 @@ export function setupAppVersionNotification() {
() => $t('system.updateConfirm')
)
]);
},
onClose() {
isShow = false;
}
});
}
Expand Down

0 comments on commit b5a723c

Please sign in to comment.