Skip to content

Commit

Permalink
Merge pull request #1533 from minvws/chore/porting-infinite-loading-f…
Browse files Browse the repository at this point in the history
…ixes

Backport infinite loading state fix to verifier
  • Loading branch information
iandundas authored Feb 20, 2022
2 parents 5c17f75 + a525ad7 commit 96ec5bc
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class CryptoLibUtilityTests: XCTestCase {

// Arrange
expect(self.networkSpy.invokedGetPublicKeysCount) == 0
sut.registerTriggers()

// Act
reachabilitySpy.invokedWhenReachable?(try! Reachability()) // swiftlint:disable:this force_try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ class RemoteConfigManagerTests: XCTestCase {

// Arrange
expect(self.networkSpy.invokedGetRemoteConfigurationCount) == 0
sut.registerTriggers()

// Act
reachabilitySpy.invokedWhenReachable?(try! Reachability()) // swiftlint:disable:this force_try
Expand Down
8 changes: 8 additions & 0 deletions CTRTests/Utils/Services/CryptoLibUtilitySpy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,12 @@ final class CryptoLibUtilitySpy: CryptoLibUtilityProtocol {
invokedWipePersistedData = true
invokedWipePersistedDataCount += 1
}

var invokedRegisterTriggers = false
var invokedRegisterTriggersCount = 0

func registerTriggers() {
invokedRegisterTriggers = true
invokedRegisterTriggersCount += 1
}
}
8 changes: 8 additions & 0 deletions CTRTests/Utils/Services/RemoteConfigManagingSpy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@ class RemoteConfigManagingSpy: RemoteConfigManaging {
invokedWipePersistedData = true
invokedWipePersistedDataCount += 1
}

var invokedRegisterTriggers = false
var invokedRegisterTriggersCount = 0

func registerTriggers() {
invokedRegisterTriggers = true
invokedRegisterTriggersCount += 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ protocol CryptoLibUtilityProtocol: AnyObject {

/// Reset to default
func wipePersistedData()

func registerTriggers()
}

final class CryptoLibUtility: CryptoLibUtilityProtocol, Logging {
Expand Down Expand Up @@ -102,7 +104,6 @@ final class CryptoLibUtility: CryptoLibUtilityProtocol, Logging {
self.remoteConfigManager = remoteConfigManager
self.shouldInitialize = .empty
self.reachability = reachability
registerTriggers()
}

func registerTriggers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ protocol RemoteConfigManaging: AnyObject {
completion: @escaping (Result<(Bool, RemoteConfiguration), ServerError>) -> Void)

func wipePersistedData()

func registerTriggers()
}

/// The remote configuration manager
Expand Down Expand Up @@ -75,11 +77,9 @@ class RemoteConfigManager: RemoteConfigManaging, Logging {
logInfo("Updating from stored json")
storedConfiguration = configFromStoredData
}

registerTriggers()
}

private func registerTriggers() {
func registerTriggers() {

NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: .main) { [weak self] _ in
self?.update(isAppLaunching: false, immediateCallbackIfWithinTTL: {}, completion: { _ in })
Expand Down
24 changes: 14 additions & 10 deletions Sources/CTR/Interface/Coordinator/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,20 @@ class AppCoordinator: Coordinator, Logging {
navigationController.viewControllers = [destination]
}

/// Start the real application
private func startApplication() {

switch flavor {
case .holder:
startAsHolder()
default:
startAsVerifier()
}
}
/// Start the real application
private func startApplication() {

// Start listeners after launching is done (willEnterForegroundNotification will mess up launch)
Current.remoteConfigManager.registerTriggers()
Current.cryptoLibUtility.registerTriggers()

switch flavor {
case .holder:
startAsHolder()
default:
startAsVerifier()
}
}

/// Start the app as a holder
private func startAsHolder() {
Expand Down
43 changes: 21 additions & 22 deletions Sources/CTR/Interface/Coordinator/LaunchStateManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,33 @@ final class LaunchStateManager: LaunchStateManaging {
// MARK: - Launch State -

func handleLaunchState(_ state: LaunchState) {


if CommandLine.arguments.contains("-skipOnboarding") {
self.startApplication()
return
}

guard Current.cryptoLibUtility.isInitialized else {
delegate?.cryptoLibDidNotInitialize()

return
}

switch state {
case .finished:
checkRemoteConfiguration(Current.remoteConfigManager.storedConfiguration) {
self.startApplication()
}

case .serverError(let serviceErrors):
// Deactivated or update trumps no internet or error
checkRemoteConfiguration(Current.remoteConfigManager.storedConfiguration) {
self.delegate?.errorWhileLoading(errors: serviceErrors)
}

case .withinTTL:
// If within the TTL, and the firstUseDate is nil, that means an existing installation.
// Use the documents directory creation date.
Current.appInstalledSinceManager.update(dateProvider: FileManager.default)

checkRemoteConfiguration(Current.remoteConfigManager.storedConfiguration) {

if state == .withinTTL {
// If within the TTL, and the firstUseDate is nil, that means an existing installation.
// Use the documents directory creation date.
Current.appInstalledSinceManager.update(dateProvider: FileManager.default)
}

checkRemoteConfiguration(Current.remoteConfigManager.storedConfiguration) {
switch state {
case .finished, .withinTTL:
self.startApplication()
}
case .serverError(let serviceErrors):
if !self.applicationHasStarted {
self.delegate?.errorWhileLoading(errors: serviceErrors)
}
}
}
}

private func startApplication() {
Expand Down

0 comments on commit 96ec5bc

Please sign in to comment.