-
-
Save zazk/613efe6c0df4d58c50c9ac58ecfb3e91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func startApp() { | |
onMainDo({ | |
self.activityIndicator.startAnimating() | |
}, onBackgroundDo: { | |
let storage = PersistentSecureStorage.shared() | |
guard let savedToken == storage.token { | |
return .goToAuth | |
} | |
let tokenIsValid = authService.isValidToken(savedToken) | |
if !tokenIsValid { | |
let newToken = authService.updateToken() | |
networking.set(token: newToken) | |
storage.token = newToken | |
} | |
let updatedProfile = profileService.getProfile() | |
user.profile = updatedProfile | |
let prefetchedThings = thingsService.getThings() | |
return .goToHome(prefetchedThings) | |
}, thenOnMainDo: { | |
self.activityIndicator.stopAnimating() | |
switch $0 { | |
case .goToAuth: presentAuth() | |
case .goToHome(let prefetchedThings): presentHome(prefetchedThings) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment