Skip to content

Commit 107f875

Browse files
authored
Revert "Remove unecessary model updates from app lifecycle" (home-assistant#3546)
Reverts home-assistant#3531
1 parent 5f48bb2 commit 107f875

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

Sources/App/AppDelegate.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
388388
_ = Realm.live()
389389
Action.setupObserver()
390390
NotificationCategory.setupObserver()
391-
Current.modelManager.cleanup().cauterize()
392-
Current.modelManager.subscribe(isAppInForeground: {
393-
UIApplication.shared.applicationState == .active
394-
})
395391
}
396392

397393
private func setupMenus() {

Sources/App/Scenes/WebViewSceneDelegate.swift

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,38 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
104104
#if targetEnvironment(macCatalyst)
105105
WindowScenesManager.shared.didDiscardScene(scene)
106106
#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()
107120
}
108121

109122
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+
}
112139
}
113140

114141
func windowScene(
@@ -138,23 +165,3 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
138165
urlHandler?.handle(userActivity: userActivity)
139166
}
140167
}
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

Comments
 (0)