Add developer option for clearing the application cache (#852)

* Add developer option for clearing the application cache

* Tweaks following code review
This commit is contained in:
Stefan Ceriu
2023-05-05 19:41:21 +03:00
committed by GitHub
parent f679c0ca2a
commit 574424024c
10 changed files with 93 additions and 7 deletions
@@ -159,6 +159,8 @@ class AppCoordinator: AppCoordinatorProtocol {
self.logout(isSoft: isSoft)
case (.signingOut, .completedSigningOut(let isSoft), .signedOut):
self.presentSplashScreen(isSoftLogout: isSoft)
case (.signedIn, .clearCache, .initial):
clearCache()
default:
fatalError("Unknown transition: \(context)")
}
@@ -238,6 +240,8 @@ class AppCoordinator: AppCoordinatorProtocol {
switch action {
case .signOut:
self?.stateMachine.processEvent(.signOut(isSoft: false))
case .clearCache:
self?.stateMachine.processEvent(.clearCache)
}
}
@@ -428,6 +432,25 @@ class AppCoordinator: AppCoordinatorProtocol {
storedAppRoute = appRoute
}
}
private func clearCache() {
showLoadingIndicator()
defer {
hideLoadingIndicator()
}
navigationRootCoordinator.setRootCoordinator(SplashScreenCoordinator())
userSession.clientProxy.stopSync()
userSessionFlowCoordinator?.stop()
userSessionStore.clearCacheFor(userSession: userSession)
tearDownUserSession()
stateMachine.processEvent(.startWithExistingSession)
}
}
// MARK: - AuthenticationCoordinatorDelegate
@@ -52,6 +52,9 @@ class AppCoordinatorStateMachine {
case signOut(isSoft: Bool)
/// Signing out completed
case completedSigningOut(isSoft: Bool)
/// Request cache clearing
case clearCache
}
private let stateMachine: StateMachine<State, Event>
@@ -71,6 +74,8 @@ class AppCoordinatorStateMachine {
stateMachine.addRoutes(event: .startWithExistingSession, transitions: [.initial => .restoringSession])
stateMachine.addRoutes(event: .createdUserSession, transitions: [.restoringSession => .signedIn])
stateMachine.addRoutes(event: .failedRestoringSession, transitions: [.restoringSession => .signedOut])
stateMachine.addRoutes(event: .clearCache, transitions: [.signedIn => .initial])
// Transitions with associated values need to be handled through `addRouteMapping`
stateMachine.addRouteMapping { event, fromState, _ in