From d600ab88006a95bdd23e6cd3985581a7eeb3609d Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sun, 25 Dec 2022 17:39:12 +0100 Subject: [PATCH] Code cleanup in App --- IceCubesApp/App/IceCubesApp.swift | 35 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/IceCubesApp/App/IceCubesApp.swift b/IceCubesApp/App/IceCubesApp.swift index 12ebc4c8..6e01798f 100644 --- a/IceCubesApp/App/IceCubesApp.swift +++ b/IceCubesApp/App/IceCubesApp.swift @@ -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,16 +85,25 @@ struct IceCubesApp: App { .quickLookPreview($quickLook.url, in: quickLook.urls) } .onChange(of: scenePhase, perform: { scenePhase in - switch scenePhase { - case .background: - watcher.stopWatching() - case .active: - watcher.watch(stream: .user) - case .inactive: - break - default: - break - } + 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() + case .active: + watcher.watch(stream: .user) + case .inactive: + break + default: + break + } + } }