Code cleanup in App

This commit is contained in:
Thomas Ricouard 2022-12-25 17:39:12 +01:00
parent b1f81dbe2f
commit d600ab8800

View file

@ -68,15 +68,13 @@ struct IceCubesApp: App {
} }
.tint(theme.tintColor) .tint(theme.tintColor)
.onChange(of: appAccountsManager.currentClient) { newClient in .onChange(of: appAccountsManager.currentClient) { newClient in
currentAccount.setClient(client: newClient) setNewClientsInEnv(client: newClient)
watcher.setClient(client: newClient)
if newClient.isAuth { if newClient.isAuth {
watcher.watch(stream: .user) watcher.watch(stream: .user)
} }
} }
.onAppear { .onAppear {
currentAccount.setClient(client: appAccountsManager.currentClient) setNewClientsInEnv(client: appAccountsManager.currentClient)
watcher.setClient(client: appAccountsManager.currentClient)
} }
.environmentObject(appAccountsManager) .environmentObject(appAccountsManager)
.environmentObject(appAccountsManager.currentClient) .environmentObject(appAccountsManager.currentClient)
@ -87,16 +85,25 @@ struct IceCubesApp: App {
.quickLookPreview($quickLook.url, in: quickLook.urls) .quickLookPreview($quickLook.url, in: quickLook.urls)
} }
.onChange(of: scenePhase, perform: { scenePhase in .onChange(of: scenePhase, perform: { scenePhase in
switch scenePhase { handleScenePhase(scenePhase: scenePhase)
case .background:
watcher.stopWatching()
case .active:
watcher.watch(stream: .user)
case .inactive:
break
default:
break
}
}) })
} }
private func setNewClientsInEnv(client: Client) {
currentAccount.setClient(client: client)
watcher.setClient(client: client)
}
private func handleScenePhase(scenePhase: ScenePhase) {
switch scenePhase {
case .background:
watcher.stopWatching()
case .active:
watcher.watch(stream: .user)
case .inactive:
break
default:
break
}
}
} }