Skip to content

Commit

Permalink
Fix of default browser status in case the DDG is set
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstrba committed Feb 25, 2024
1 parent 2e368be commit 1a0eb95
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,36 @@ final class DefaultBrowserPreferences: ObservableObject {

do {
try defaultBrowserProvider.presentDefaultBrowserPrompt()
repeatCheckIfDefault()
} catch {
defaultBrowserProvider.openSystemPreferences()
}
}

var executionCount = 0
let maxNumberOfExecutions = 60
var timer: Timer?

// Monitors for changes in default browser setting over the next minute
private func repeatCheckIfDefault() {
timer?.invalidate()
executionCount = 0
timer = Timer.scheduledTimer(timeInterval: 1.0,
target: self,
selector: #selector(timerFired),
userInfo: nil,
repeats: true)
}

@objc private func timerFired() {
checkIfDefault()

executionCount += 1
if executionCount >= maxNumberOfExecutions {
timer?.invalidate()
}
}

private var appDidBecomeActiveCancellable: AnyCancellable?
private let defaultBrowserProvider: DefaultBrowserProvider
}

0 comments on commit 1a0eb95

Please sign in to comment.