@@ -11,6 +11,12 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
1111
1212 private var updateDatabaseTask : Task < Void , Never > ?
1313
14+ /// Stores the timestamp when the app enters background, used to determine if auto-refresh is needed on reactivation
15+ var backgroundTimestamp : Date ?
16+
17+ /// Time threshold (in seconds) after which WebViewController should refresh when returning from background
18+ private let backgroundRefreshThreshold : TimeInterval = 5 * 60
19+
1420 // swiftlint:disable cyclomatic_complexity
1521 func scene(
1622 _ scene: UIScene ,
@@ -119,6 +125,9 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
119125 DataWidgetsUpdater . update ( )
120126 Current . modelManager. unsubscribe ( )
121127 Current . appDatabaseUpdater. stop ( )
128+
129+ // Record timestamp when app enters background
130+ backgroundTimestamp = Date ( )
122131 }
123132
124133 func sceneDidBecomeActive( _ scene: UIScene ) {
@@ -128,6 +137,22 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
128137 }
129138 cleanWidgetsCache ( )
130139 updateLocation ( )
140+
141+ // Check if app was in background for 5 minutes or more
142+ if let backgroundTimestamp {
143+ let timeInterval = Date ( ) . timeIntervalSince ( backgroundTimestamp)
144+
145+ if timeInterval >= backgroundRefreshThreshold, Current . settingsStore. refreshWebViewAfterInactive {
146+ // Refresh WebViewController if it exists
147+ // Note: webViewControllerPromise is a Guarantee, which cannot fail in PromiseKit
148+ windowController? . webViewControllerPromise. done { webViewController in
149+ webViewController. refresh ( )
150+ }
151+ }
152+
153+ // Clear the timestamp
154+ self . backgroundTimestamp = nil
155+ }
131156 }
132157
133158 func windowScene(
0 commit comments