diff --git a/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideInteractor.swift b/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideInteractor.swift index 75264eaf3010..6d044d7de24c 100644 --- a/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideInteractor.swift +++ b/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideInteractor.swift @@ -11,10 +11,11 @@ import MullvadLogging import MullvadSettings import MullvadTypes -struct IPOverrideInteractor { +final class IPOverrideInteractor { private let logger = Logger(label: "IPOverrideInteractor") private let repository: IPOverrideRepositoryProtocol private let tunnelManager: TunnelManager + private var statusWorkItem: DispatchWorkItem? private let statusSubject = CurrentValueSubject(.noImports) var statusPublisher: AnyPublisher { @@ -87,8 +88,16 @@ struct IPOverrideInteractor { } private func resetToDefaultStatus(delay: Duration = .zero) { - DispatchQueue.main.asyncAfter(deadline: .now() + delay.timeInterval) { - statusSubject.send(defaultStatus) + statusWorkItem?.cancel() + + let statusWorkItem = DispatchWorkItem { [weak self] in + let isCancelled = self?.statusWorkItem?.isCancelled ?? false + guard let self, !isCancelled else { return } + + self.statusSubject.send(self.defaultStatus) } + self.statusWorkItem = statusWorkItem + + DispatchQueue.main.asyncAfter(deadline: .now() + delay.timeInterval, execute: statusWorkItem) } } diff --git a/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideStatus.swift b/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideStatus.swift index 85cc8d3fc5b6..42e03e8c768c 100644 --- a/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideStatus.swift +++ b/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideStatus.swift @@ -8,7 +8,7 @@ import UIKit -enum IPOverrideStatus: CustomStringConvertible { +enum IPOverrideStatus: Equatable, CustomStringConvertible { case active, noImports, importSuccessful(Context), importFailed(Context) enum Context { diff --git a/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideViewController.swift b/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideViewController.swift index 8bce36d45061..5f8021d4e049 100644 --- a/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideViewController.swift +++ b/ios/MullvadVPN/Coordinators/Settings/IPOverride/IPOverrideViewController.swift @@ -66,6 +66,7 @@ class IPOverrideViewController: UIViewController { interactor.statusPublisher.sink { [weak self] status in self?.statusView.setStatus(status) + self?.clearButton.isEnabled = self?.interactor.defaultStatus == .active }.store(in: &cancellables) }