Revert "Remove unecessary model updates from app lifecycle" (#3546)

Reverts home-assistant/iOS#3531
This commit is contained in:
Bruno Pantaleão Gonçalves
2025-04-16 00:22:32 +02:00
committed by GitHub
parent 5f48bb222a
commit 107f875a91
2 changed files with 29 additions and 26 deletions

View File

@@ -388,10 +388,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
_ = Realm.live()
Action.setupObserver()
NotificationCategory.setupObserver()
Current.modelManager.cleanup().cauterize()
Current.modelManager.subscribe(isAppInForeground: {
UIApplication.shared.applicationState == .active
})
}
private func setupMenus() {

View File

@@ -104,11 +104,38 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
#if targetEnvironment(macCatalyst)
WindowScenesManager.shared.didDiscardScene(scene)
#endif
DataWidgetsUpdater.update()
}
func sceneDidEnterBackground(_ scene: UIScene) {
if #available(iOS 17.0, *) {
// if a widget is pending confirmation to execute it's action
// this will reset that and the widget will be restored to default state
_ = ResetAllCustomWidgetConfirmationAppIntent()
}
DataWidgetsUpdater.update()
Current.modelManager.unsubscribe()
Current.appDatabaseUpdater.stop()
}
func sceneDidBecomeActive(_ scene: UIScene) {
updateAppDatabase()
removeWidgetsCache()
Current.modelManager.cleanup().cauterize()
Current.modelManager.subscribe(isAppInForeground: {
UIApplication.shared.applicationState == .active
})
Current.appDatabaseUpdater.update()
Current.panelsUpdater.update()
let widgetsCacheFile = AppConstants.widgetsCacheURL
// Clean up widgets cache file
do {
try FileManager.default.removeItem(at: widgetsCacheFile)
} catch {
Current.Log.error("Failed to remove widgets cache file: \(error)")
}
}
func windowScene(
@@ -138,23 +165,3 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
urlHandler?.handle(userActivity: userActivity)
}
}
// MARK: - App database & cache
extension WebViewSceneDelegate {
private func updateAppDatabase() {
Current.appDatabaseUpdater.update()
Current.panelsUpdater.update()
}
private func removeWidgetsCache() {
let widgetsCacheFile = AppConstants.widgetsCacheURL
// Clean up widgets cache file
do {
try FileManager.default.removeItem(at: widgetsCacheFile)
} catch {
Current.Log.info("Did not remove widgets cache file: \(error)")
}
}
}