Skip to content

Commit

Permalink
fix(projects): fix update notifications. fixed #691, fixed #692
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jan 19, 2025
1 parent c9433e1 commit ac86247
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/plugins/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ export function setupAppErrorHandle(app: App) {
const UPDATE_CHECK_INTERVAL = 3 * 60 * 1000;

export function setupAppVersionNotification() {
const canAutoUpdateApp = import.meta.env.VITE_AUTOMATICALLY_DETECT_UPDATE === 'Y';

const canAutoUpdateApp = import.meta.env.VITE_AUTOMATICALLY_DETECT_UPDATE === 'Y' && import.meta.env.PROD;
if (!canAutoUpdateApp) return;

let isShow = false;
let updateInterval: ReturnType<typeof setInterval> | undefined;

// Check if updates should be checked
const shouldCheckForUpdates = [!isShow, document.visibilityState === 'visible', !import.meta.env.DEV].every(Boolean);

const checkForUpdates = async () => {
if (!shouldCheckForUpdates) return;
if (isShow) return;

const buildTime = await getHtmlBuildTime();

Expand All @@ -47,6 +43,7 @@ export function setupAppVersionNotification() {
{
onClick() {
n?.destroy();
isShow = false;
}
},
() => $t('system.updateCancel')
Expand Down Expand Up @@ -77,7 +74,7 @@ export function setupAppVersionNotification() {
};

// If updates should be checked, set up the visibility change listener and start the update interval
if (shouldCheckForUpdates) {
if (!isShow && document.visibilityState === 'visible') {
// Check for updates when the document is visible
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
Expand Down

0 comments on commit ac86247

Please # to comment.