@@ -10,20 +10,26 @@ export function setupAppErrorHandle(app: App) {
10
10
} ;
11
11
}
12
12
13
+ // Update check interval in milliseconds
14
+ const UPDATE_CHECK_INTERVAL = 3 * 60 * 1000 ;
15
+
13
16
export function setupAppVersionNotification ( ) {
14
17
const canAutoUpdateApp = import . meta. env . VITE_AUTOMATICALLY_DETECT_UPDATE === 'Y' ;
15
18
16
19
if ( ! canAutoUpdateApp ) return ;
17
20
18
21
let isShow = false ;
22
+ let updateInterval : ReturnType < typeof setInterval > | undefined ;
19
23
20
- document . addEventListener ( 'visibilitychange' , async ( ) => {
21
- const preConditions = [ ! isShow , document . visibilityState === 'visible' , ! import . meta. env . DEV ] ;
24
+ // Check if updates should be checked
25
+ const shouldCheckForUpdates = [ ! isShow , document . visibilityState === 'visible' , ! import . meta. env . DEV ] . every ( Boolean ) ;
22
26
23
- if ( ! preConditions . every ( Boolean ) ) return ;
27
+ const checkForUpdates = async ( ) => {
28
+ if ( ! shouldCheckForUpdates ) return ;
24
29
25
30
const buildTime = await getHtmlBuildTime ( ) ;
26
31
32
+ // If build time hasn't changed, no update is needed
27
33
if ( buildTime === BUILD_TIME ) {
28
34
return ;
29
35
}
@@ -63,7 +69,28 @@ export function setupAppVersionNotification() {
63
69
isShow = false ;
64
70
}
65
71
} ) ;
66
- } ) ;
72
+ } ;
73
+
74
+ const startUpdateInterval = ( ) => {
75
+ if ( updateInterval ) {
76
+ clearInterval ( updateInterval ) ;
77
+ }
78
+ updateInterval = setInterval ( checkForUpdates , UPDATE_CHECK_INTERVAL ) ;
79
+ } ;
80
+
81
+ // If updates should be checked, set up the visibility change listener and start the update interval
82
+ if ( shouldCheckForUpdates ) {
83
+ // Check for updates when the document is visible
84
+ document . addEventListener ( 'visibilitychange' , ( ) => {
85
+ if ( document . visibilityState === 'visible' ) {
86
+ checkForUpdates ( ) ;
87
+ startUpdateInterval ( ) ;
88
+ }
89
+ } ) ;
90
+
91
+ // Start the update interval
92
+ startUpdateInterval ( ) ;
93
+ }
67
94
}
68
95
69
96
async function getHtmlBuildTime ( ) {
0 commit comments