Skip to content

Commit

Permalink
Fix 8163: Notification asking to set Brave as the default browser is …
Browse files Browse the repository at this point in the history
…still shown after an external link opened via the 3P app (brave/brave-ios#8186)
  • Loading branch information
soner-yuksel authored Oct 3, 2023
1 parent d32ddff commit 6613060
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -890,15 +890,9 @@ public class BrowserViewController: UIViewController {
// Schedule Default Browser Local Notification
// If notification is not already scheduled or
// an external URL opened in Brave (which indicates Brave is set as default)
if !Preferences.DefaultBrowserIntro.defaultBrowserNotificationScheduled.value,
Preferences.DefaultBrowserIntro.defaultBrowserNotificationShouldBeShown.value {
if !Preferences.DefaultBrowserIntro.defaultBrowserNotificationScheduled.value {
scheduleDefaultBrowserNotification()
}

// Remove pending notification if default browser is already set
if !Preferences.DefaultBrowserIntro.defaultBrowserNotificationShouldBeShown.value {
cancelScheduleDefaultBrowserNotification()
}

privateModeCancellable = privateBrowsingManager
.$isPrivateBrowsing
Expand Down Expand Up @@ -988,6 +982,8 @@ public class BrowserViewController: UIViewController {
private func cancelScheduleDefaultBrowserNotification() {
let center = UNUserNotificationCenter.current()
center.removePendingNotificationRequests(withIdentifiers: [Self.defaultBrowserNotificationId])

Preferences.DefaultBrowserIntro.defaultBrowserNotificationIsCanceled.value = true
}

private func executeAfterSetup(_ block: @escaping () -> Void) {
Expand Down Expand Up @@ -3229,7 +3225,13 @@ extension BrowserViewController {
if case .url(let navigatedURL, _) = path {
if navigatedURL?.isWebPage(includeDataURIs: false) == true {
Preferences.General.defaultBrowserCalloutDismissed.value = true
Preferences.DefaultBrowserIntro.defaultBrowserNotificationShouldBeShown.value = false
Preferences.DefaultBrowserIntro.defaultBrowserNotificationScheduled.value = true

// Remove pending notification if default browser is set brave
// Recognized by external link is open
if !Preferences.DefaultBrowserIntro.defaultBrowserNotificationIsCanceled.value {
cancelScheduleDefaultBrowserNotification()
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Onboarding/OnboardingPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ extension Preferences {
default: false)

/// Whether a default browser local notification should be shown
public static let defaultBrowserNotificationShouldBeShown = Option<Bool>(
key: "general.default-browser-notification-shown",
default: true)
public static let defaultBrowserNotificationIsCanceled = Option<Bool>(
key: "general.default-browser-notification-canceled",
default: false)
}
}

0 comments on commit 6613060

Please sign in to comment.