@@ -294,6 +294,14 @@ export default function App() {
294294 setOpenworkServerSettings ( readOpenworkServerSettings ( ) ) ;
295295 } ) ;
296296
297+ createEffect ( ( ) => {
298+ if ( typeof document === "undefined" ) return ;
299+ const update = ( ) => setDocumentVisible ( document . visibilityState !== "hidden" ) ;
300+ update ( ) ;
301+ document . addEventListener ( "visibilitychange" , update ) ;
302+ onCleanup ( ( ) => document . removeEventListener ( "visibilitychange" , update ) ) ;
303+ } ) ;
304+
297305 createEffect ( ( ) => {
298306 const pref = startupPreference ( ) ;
299307 const info = openworkServerHostInfo ( ) ;
@@ -339,6 +347,7 @@ export default function App() {
339347
340348 createEffect ( ( ) => {
341349 if ( typeof window === "undefined" ) return ;
350+ if ( ! documentVisible ( ) ) return ;
342351 const url = openworkServerBaseUrl ( ) . trim ( ) ;
343352 const auth = openworkServerAuth ( ) ;
344353 const token = auth . token ;
@@ -353,6 +362,13 @@ export default function App() {
353362
354363 let active = true ;
355364 let busy = false ;
365+ let timeoutId : number | undefined ;
366+ let delayMs = 10_000 ;
367+
368+ const scheduleNext = ( ) => {
369+ if ( ! active ) return ;
370+ timeoutId = window . setTimeout ( run , delayMs ) ;
371+ } ;
356372
357373 const run = async ( ) => {
358374 if ( busy ) return ;
@@ -362,23 +378,30 @@ export default function App() {
362378 if ( ! active ) return ;
363379 setOpenworkServerStatus ( result . status ) ;
364380 setOpenworkServerCapabilities ( result . capabilities ) ;
381+ delayMs =
382+ result . status === "connected" || result . status === "limited"
383+ ? 10_000
384+ : Math . min ( delayMs * 2 , 60_000 ) ;
385+ } catch {
386+ delayMs = Math . min ( delayMs * 2 , 60_000 ) ;
365387 } finally {
366388 if ( ! active ) return ;
367389 setOpenworkServerCheckedAt ( Date . now ( ) ) ;
368390 busy = false ;
391+ scheduleNext ( ) ;
369392 }
370393 } ;
371394
372395 run ( ) ;
373- const interval = window . setInterval ( run , 10_000 ) ;
374396 onCleanup ( ( ) => {
375397 active = false ;
376- window . clearInterval ( interval ) ;
398+ if ( timeoutId ) window . clearTimeout ( timeoutId ) ;
377399 } ) ;
378400 } ) ;
379401
380402 createEffect ( ( ) => {
381403 if ( ! isTauriRuntime ( ) ) return ;
404+ if ( ! documentVisible ( ) ) return ;
382405 let active = true ;
383406
384407 const run = async ( ) => {
@@ -400,6 +423,7 @@ export default function App() {
400423
401424 createEffect ( ( ) => {
402425 if ( typeof window === "undefined" ) return ;
426+ if ( ! documentVisible ( ) ) return ;
403427 if ( ! developerMode ( ) ) {
404428 setOpenworkServerDiagnostics ( null ) ;
405429 return ;
@@ -438,6 +462,7 @@ export default function App() {
438462 createEffect ( ( ) => {
439463 if ( ! isTauriRuntime ( ) ) return ;
440464 if ( ! developerMode ( ) ) return ;
465+ if ( ! documentVisible ( ) ) return ;
441466
442467 let busy = false ;
443468
@@ -464,6 +489,7 @@ export default function App() {
464489 setOwpenbotInfoState ( null ) ;
465490 return ;
466491 }
492+ if ( ! documentVisible ( ) ) return ;
467493
468494 let active = true ;
469495
@@ -490,6 +516,7 @@ export default function App() {
490516 setOpenwrkStatusState ( null ) ;
491517 return ;
492518 }
519+ if ( ! documentVisible ( ) ) return ;
493520
494521 let active = true ;
495522
@@ -525,6 +552,7 @@ export default function App() {
525552 const mountTime = Date . now ( ) ;
526553 const [ lastKnownConfigSnapshot , setLastKnownConfigSnapshot ] = createSignal ( "" ) ;
527554 const [ developerMode , setDeveloperMode ] = createSignal ( false ) ;
555+ const [ documentVisible , setDocumentVisible ] = createSignal ( true ) ;
528556 let markReloadRequiredRef : ( reason : ReloadReason , trigger ?: ReloadTrigger ) => void = ( ) => { } ;
529557 let setReloadLastFinishedAtRef : ( value : number ) => void = ( ) => { } ;
530558
@@ -1392,6 +1420,7 @@ export default function App() {
13921420 setDevtoolsWorkspaceId ( null ) ;
13931421 return ;
13941422 }
1423+ if ( ! documentVisible ( ) ) return ;
13951424
13961425 const client = devtoolsOpenworkClient ( ) ;
13971426 if ( ! client ) {
@@ -1430,6 +1459,7 @@ export default function App() {
14301459 setOpenworkAuditError ( null ) ;
14311460 return ;
14321461 }
1462+ if ( ! documentVisible ( ) ) return ;
14331463
14341464 const client = devtoolsOpenworkClient ( ) ;
14351465 const workspaceId = devtoolsWorkspaceId ( ) ;
@@ -2100,6 +2130,7 @@ export default function App() {
21002130
21012131 createEffect ( ( ) => {
21022132 if ( typeof window === "undefined" ) return ;
2133+ if ( ! documentVisible ( ) ) return ;
21032134 if ( openworkReloadUnsupported ( ) ) return ;
21042135 const client = openworkServerClient ( ) ;
21052136 const workspaceId = openworkServerWorkspaceId ( ) ;
0 commit comments