Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Fix/dont show allready running alert #1510

Merged
merged 7 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/xcode/ENA/ENA/Source/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension AppDelegate {
switch didEndPrematurelyReason {
case let .noSummary(error):
return makeAlertController(
enError: error,
noSummaryError: error,
localizedDescription: didEndPrematurelyReason.localizedDescription,
rootController: rootController
)
Expand All @@ -83,11 +83,11 @@ extension AppDelegate {
}
}

private func makeAlertController(enError: Error?, localizedDescription: String, rootController: UIViewController) -> UIAlertController {
switch enError {
case let error as ENError:
private func makeAlertController(noSummaryError: Error?, localizedDescription: String, rootController: UIViewController) -> UIAlertController? {

if let enError = noSummaryError as? ENError {
let openFAQ: (() -> Void)? = {
guard let url = error.faqURL else { return nil }
guard let url = enError.faqURL else { return nil }
return {
UIApplication.shared.open(url, options: [:])
}
Expand All @@ -97,7 +97,12 @@ extension AppDelegate {
secondaryActionTitle: AppStrings.Common.errorAlertActionMoreInfo,
secondaryActionCompletion: openFAQ
)
default:
} else if let exposureDetectionError = noSummaryError as? ExposureDetectionError {
switch exposureDetectionError {
case .isAlreadyRunning:
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the error also trigger a different cell on the home view? Should we throw this error at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point!
Currently it cannot happen, because RiskProvider "guards" this case for the key download and the risk detection.
But I think it is still a valid point from the perspective of code readability.
I have added error handling to HomeInteractor which explicitly ignores the allready running errors.

}
} else {
return rootController.setupErrorAlert(
message: localizedDescription
)
Expand Down
31 changes: 28 additions & 3 deletions src/xcode/ENA/ENA/Source/Scenes/Home/HomeInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ final class HomeInteractor: RequiresAppDependencies {
self?.reloadActionSection()
}

riskConsumer.didFailCalculateRisk = { [weak self] _ in
self?.state.riskDetectionFailed = true
self?.reloadActionSection()
riskConsumer.didFailCalculateRisk = { [weak self] error in
guard let self = self else { return }

// Don't show already running errors.
guard !self.errorIsAlreadyRunningError(error) else {
return
}
self.state.riskDetectionFailed = true
self.reloadActionSection()
}

riskProvider.observeRisk(riskConsumer)
Expand Down Expand Up @@ -171,6 +177,25 @@ final class HomeInteractor: RequiresAppDependencies {

return sections
}

private func errorIsAlreadyRunningError(_ error: RiskProviderError) -> Bool {
switch error {
case .riskProviderIsRunning:
return true
case .failedKeyPackageDownload(let keyPackageDownloadError):
return keyPackageDownloadError == .downloadIsRunning
case .failedRiskDetection(let didEndPrematuralyReason):
if case let .noSummary(summaryError) = didEndPrematuralyReason {
if let exposureDetectionError = summaryError as? ExposureDetectionError {
return exposureDetectionError == .isAlreadyRunning
}
}
default:
break
}

return false
}
}

// MARK: - Test result cell methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ extension RiskProvider: RiskProviding {
return true
}

// Here we are in automatic mode and thus we have to check the validity of the current summary.
let enoughTimeHasPassed = riskProvidingConfiguration.shouldPerformExposureDetection(
activeTracingHours: store.tracingStatusHistory.activeTracing().inHours,
lastExposureDetectionDate: store.summary?.date
Expand Down