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)
.onChange(of: appAccountsManager.currentClient) { newClient in
currentAccount.setClient(client: newClient)
watcher.setClient(client: newClient)
setNewClientsInEnv(client: newClient)
if newClient.isAuth {
watcher.watch(stream: .user)
}
}
.onAppear {
currentAccount.setClient(client: appAccountsManager.currentClient)
watcher.setClient(client: appAccountsManager.currentClient)
setNewClientsInEnv(client: appAccountsManager.currentClient)
}
.environmentObject(appAccountsManager)
.environmentObject(appAccountsManager.currentClient)
@ -87,6 +85,16 @@ struct IceCubesApp: App {
.quickLookPreview($quickLook.url, in: quickLook.urls)
}
.onChange(of: scenePhase, perform: { scenePhase in
handleScenePhase(scenePhase: scenePhase)
})
}
private func setNewClientsInEnv(client: Client) {
currentAccount.setClient(client: client)
watcher.setClient(client: client)
}
private func handleScenePhase(scenePhase: ScenePhase) {
switch scenePhase {
case .background:
watcher.stopWatching()
@ -97,6 +105,5 @@ struct IceCubesApp: App {
default:
break
}
})
}
}