fix: unify location report state

This commit is contained in:
2026-07-07 16:24:26 +08:00
parent 9378748a4d
commit 97060c2a32
4 changed files with 143 additions and 10 deletions
@@ -37,7 +37,7 @@ final class HomeViewModel {
init(
appStore: AppStore = .shared,
locationStateStore: HomeLocationStateStore = HomeLocationStateStore(),
locationStateStore: HomeLocationStateStore = .shared,
commonMenuStore: HomeCommonMenuStore = HomeCommonMenuStore(),
locationProvider: any LocationProviding = LocationProvider.shared
) {
@@ -50,11 +50,15 @@ final class HomeViewModel {
locationProvider: locationProvider
)
self.commonMenuStore = commonMenuStore
self.locationStateStore.onStateChange = { [weak self] in
self.locationStateStore.observe(self) { [weak self] in
self?.notifyStateChange()
}
}
deinit {
locationStateStore.removeObserver(self)
}
var isOnline: Bool { locationStateStore.isOnline }
var countdownDisplayText: String { locationStateStore.countdownDisplayText }
var reminderMinutes: Int { locationStateStore.reminderMinutes }
@@ -73,6 +77,7 @@ final class HomeViewModel {
/// 按需重新拉取权限。
func reloadIfNeeded(api: HomeAPI) async {
locationStateStore.restoreStateIfNeeded()
guard needsPermissionReload else {
refreshLocalDisplayState()
rebuildCommonMenus()