From 1a0eb95631893518a37d6327b554305d8967417e Mon Sep 17 00:00:00 2001 From: Tomas Strba Date: Sun, 25 Feb 2024 16:01:09 +0100 Subject: [PATCH] Fix of default browser status in case the DDG is set --- .../Model/DefaultBrowserPreferences.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift b/DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift index bf0fdc106f..c7e75ced54 100644 --- a/DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift +++ b/DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift @@ -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 }