mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user