Skip to content

Commit

Permalink
Make the 'Clear all overrides' button only active when there are over…
Browse files Browse the repository at this point in the history
…rides
  • Loading branch information
Jon Petersson committed Mar 7, 2024
1 parent 1b1fd65 commit 7e0d268
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPOverrideStatus, Never>(.noImports)
var statusPublisher: AnyPublisher<IPOverrideStatus, Never> {
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

enum IPOverrideStatus: CustomStringConvertible {
enum IPOverrideStatus: Equatable, CustomStringConvertible {
case active, noImports, importSuccessful(Context), importFailed(Context)

enum Context {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 7e0d268

Please sign in to comment.