@@ -104,11 +104,38 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
104
104
#if targetEnvironment(macCatalyst)
105
105
WindowScenesManager . shared. didDiscardScene ( scene)
106
106
#endif
107
+
108
+ DataWidgetsUpdater . update ( )
109
+ }
110
+
111
+ func sceneDidEnterBackground( _ scene: UIScene ) {
112
+ if #available( iOS 17 . 0 , * ) {
113
+ // if a widget is pending confirmation to execute it's action
114
+ // this will reset that and the widget will be restored to default state
115
+ _ = ResetAllCustomWidgetConfirmationAppIntent ( )
116
+ }
117
+ DataWidgetsUpdater . update ( )
118
+ Current . modelManager. unsubscribe ( )
119
+ Current . appDatabaseUpdater. stop ( )
107
120
}
108
121
109
122
func sceneDidBecomeActive( _ scene: UIScene ) {
110
- updateAppDatabase ( )
111
- removeWidgetsCache ( )
123
+ Current . modelManager. cleanup ( ) . cauterize ( )
124
+ Current . modelManager. subscribe ( isAppInForeground: {
125
+ UIApplication . shared. applicationState == . active
126
+ } )
127
+
128
+ Current . appDatabaseUpdater. update ( )
129
+ Current . panelsUpdater. update ( )
130
+
131
+ let widgetsCacheFile = AppConstants . widgetsCacheURL
132
+
133
+ // Clean up widgets cache file
134
+ do {
135
+ try FileManager . default. removeItem ( at: widgetsCacheFile)
136
+ } catch {
137
+ Current . Log. error ( " Failed to remove widgets cache file: \( error) " )
138
+ }
112
139
}
113
140
114
141
func windowScene(
@@ -138,23 +165,3 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
138
165
urlHandler? . handle ( userActivity: userActivity)
139
166
}
140
167
}
141
-
142
- // MARK: - App database & cache
143
-
144
- extension WebViewSceneDelegate {
145
- private func updateAppDatabase( ) {
146
- Current . appDatabaseUpdater. update ( )
147
- Current . panelsUpdater. update ( )
148
- }
149
-
150
- private func removeWidgetsCache( ) {
151
- let widgetsCacheFile = AppConstants . widgetsCacheURL
152
-
153
- // Clean up widgets cache file
154
- do {
155
- try FileManager . default. removeItem ( at: widgetsCacheFile)
156
- } catch {
157
- Current . Log. info ( " Did not remove widgets cache file: \( error) " )
158
- }
159
- }
160
- }
0 commit comments