Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8045: Default Browser Notification - Update (Text - Default Logic) #8067

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -872,9 +872,18 @@ public class BrowserViewController: UIViewController {
}
}

if !Preferences.DefaultBrowserIntro.defaultBrowserNotificationScheduled.value {
// 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 {
scheduleDefaultBrowserNotification()
}

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

privateModeCancellable = privateBrowsingManager
.$isPrivateBrowsing
Expand Down Expand Up @@ -943,7 +952,7 @@ public class BrowserViewController: UIViewController {

let content = UNMutableNotificationContent().then {
$0.title = Strings.DefaultBrowserCallout.notificationTitle
$0.body = String(format: Strings.DefaultBrowserCallout.notificationBody, String(ProcessInfo().operatingSystemVersion.majorVersion))
$0.body = Strings.DefaultBrowserCallout.notificationBody
}

let timeToShow = AppConstants.buildChannel.isPublic ? 2.hours : 2.minutes
Expand All @@ -966,6 +975,11 @@ public class BrowserViewController: UIViewController {
}
}

private func cancelScheduleDefaultBrowserNotification() {
let center = UNUserNotificationCenter.current()
center.removePendingNotificationRequests(withIdentifiers: [Self.defaultBrowserNotificationId])
}

private func executeAfterSetup(_ block: @escaping () -> Void) {
if setupTasksCompleted {
block()
Expand Down Expand Up @@ -3168,8 +3182,14 @@ extension BrowserViewController {
}

public func handleNavigationPath(path: NavigationPath) {
// Remove Default Browser Callout if an external url is triggered
Preferences.General.defaultBrowserCalloutDismissed.value = true
// Remove Default Browser Callout - Do not show scheduled notification
// in case an external url is triggered
if case .url(let navigatedURL, _) = path {
if navigatedURL?.isWebPage(includeDataURIs: false) == true {
Preferences.General.defaultBrowserCalloutDismissed.value = true
Preferences.DefaultBrowserIntro.defaultBrowserNotificationShouldBeShown.value = false
}
}

executeAfterSetup {
NavigationPath.handle(nav: path, with: self)
Expand Down
4 changes: 2 additions & 2 deletions Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ extension Strings {
NSLocalizedString(
"defaultBrowserCallout.notificationTitle",
tableName: "BraveShared", bundle: .module,
value: "Brave Web Browser",
value: "Get Brave protection, on every link",
comment: "Notification title to promote setting Brave app as default browser")

public static let notificationBody =
NSLocalizedString(
"defaultBrowserCallout.notificationBody",
tableName: "BraveShared", bundle: .module,
value: "Optimized for iOS %@. Make Brave your default browser today.",
value: "Set Brave as your default browser",
comment: "Notification body to promote setting Brave app as default browser")
}
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/Onboarding/OnboardingPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ extension Preferences {
key: "defaultBrowserIntro.intro-completed",
default: false)

/// Whether system notification showed or not
/// Whether system notification scheduled or not
public static let defaultBrowserNotificationScheduled = Option<Bool>(
key: "general.default-browser-notification-scheduled",
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)
}
}