Skip to content

Commit 4dd754a

Browse files
authored
Revert changes for database updater and move call to scene become active (#3437)
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
1 parent 4cbae34 commit 4dd754a

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

Sources/App/Scenes/WebViewSceneDelegate.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,14 @@ final class WebViewSceneDelegate: NSObject, UIWindowSceneDelegate {
119119
Current.appDatabaseUpdater.stop()
120120
}
121121

122-
func sceneWillEnterForeground(_ scene: UIScene) {
123-
DataWidgetsUpdater.update()
122+
func sceneDidBecomeActive(_ scene: UIScene) {
124123
Current.modelManager.cleanup().cauterize()
125124
Current.modelManager.subscribe(isAppInForeground: {
126125
UIApplication.shared.applicationState == .active
127126
})
128127

129-
Current.appDatabaseUpdater.update {
130-
UIApplication.shared.applicationState
131-
}
132-
Current.panelsUpdater.update {
133-
UIApplication.shared.applicationState
134-
}
128+
Current.appDatabaseUpdater.update()
129+
Current.panelsUpdater.update()
135130

136131
let widgetsCacheFile = AppConstants.widgetsCacheURL
137132

Sources/App/Settings/SettingsViewController.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ class SettingsViewController: HAFormViewController {
165165

166166
override func viewDidAppear(_ animated: Bool) {
167167
super.viewDidAppear(animated)
168-
Current.appDatabaseUpdater.update {
169-
UIApplication.shared.applicationState
170-
}
168+
Current.appDatabaseUpdater.update()
171169
}
172170

173171
@objc func openAbout(_ sender: UIButton) {

Sources/Shared/Environment/AppDatabaseUpdater.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import UIKit
55

66
public protocol AppDatabaseUpdaterProtocol {
77
func stop()
8-
func update(uiApplicationState: @escaping () -> UIApplication.State)
8+
func update()
99
}
1010

1111
final class AppDatabaseUpdater: AppDatabaseUpdaterProtocol {
@@ -18,7 +18,7 @@ final class AppDatabaseUpdater: AppDatabaseUpdaterProtocol {
1818
cancelOnGoingRequests()
1919
}
2020

21-
func update(uiApplicationState: @escaping () -> UIApplication.State) {
21+
func update() {
2222
cancelOnGoingRequests()
2323

2424
if let lastUpdate, lastUpdate.timeIntervalSinceNow > -5 {
@@ -37,7 +37,6 @@ final class AppDatabaseUpdater: AppDatabaseUpdaterProtocol {
3737
completion: { result in
3838
switch result {
3939
case let .success(entities):
40-
guard uiApplicationState() == .active else { return }
4140
Current.appEntitiesModel().updateModel(Set(entities), server: server)
4241
case let .failure(error):
4342
Current.Log.error("Failed to fetch states: \(error)")
@@ -59,7 +58,6 @@ final class AppDatabaseUpdater: AppDatabaseUpdaterProtocol {
5958
completion: { [weak self] result in
6059
switch result {
6160
case let .success(response):
62-
guard uiApplicationState() == .active else { return }
6361
self?.saveEntityRegistryListForDisplay(response, serverId: server.identifier.rawValue)
6462
case let .failure(error):
6563
Current.Log.error("Failed to fetch EntityRegistryListForDisplay: \(error)")

Sources/Shared/Panels/PanelsUpdater.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PromiseKit
44
import UIKit
55

66
public protocol PanelsUpdaterProtocol {
7-
func update(uiApplicationState: () -> UIApplication.State)
7+
func update()
88
}
99

1010
final class PanelsUpdater: PanelsUpdaterProtocol {
@@ -13,7 +13,7 @@ final class PanelsUpdater: PanelsUpdaterProtocol {
1313
private var tokens: [(promise: Promise<HAPanels>, cancel: () -> Void)?] = []
1414
private var lastUpdate: Date?
1515

16-
public func update(uiApplicationState: () -> UIApplication.State) {
16+
public func update() {
1717
if let lastUpdate, lastUpdate.timeIntervalSinceNow > -5 {
1818
Current.Log.verbose("Skipping panels update, last update was \(lastUpdate)")
1919
return
@@ -28,7 +28,6 @@ final class PanelsUpdater: PanelsUpdaterProtocol {
2828
let request = Current.api(for: server)?.connection.send(.panels())
2929
tokens.append(request)
3030

31-
guard uiApplicationState() == .active else { return }
3231
request?.promise.done({ [weak self] panels in
3332
self?.saveInDatabase(panels, server: server)
3433
}).cauterize()

0 commit comments

Comments
 (0)