fix: unify location report state
This commit is contained in:
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user