Skip to content

Commit

Permalink
Avoid dismissing and re-presenting the settings VC unnecessarily.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Oct 23, 2023
1 parent fd214dd commit 6e48e92
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private func handleShortCutItem(_ shortcutItem: UIApplicationShortcutItem) {
os_log("Handling shortcut item: %s", log: .generalLog, type: .debug, shortcutItem.type)

mainViewController?.clearNavigationStack()
autoClear?.applicationWillMoveToForeground()

if shortcutItem.type == ShortcutKey.clipboard, let query = UIPasteboard.general.string {
mainViewController?.clearNavigationStack()
mainViewController?.loadQueryInNewTab(query)
return
}
Expand Down Expand Up @@ -749,6 +749,19 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
private func presentSettings(with viewController: UIViewController) {
guard let window = window, let rootViewController = window.rootViewController as? MainViewController else { return }

if let navigationController = rootViewController.presentedViewController as? UINavigationController {
if let lastViewController = navigationController.viewControllers.last, lastViewController.isKind(of: type(of: viewController)) {
// Avoid presenting dismissing and re-presenting the view controller if it's already visible:
return
} else {
// Otherwise, replace existing view controllers with the presented one:
navigationController.popToRootViewController(animated: false)
navigationController.pushViewController(viewController, animated: false)
return
}
}

// If the previous checks failed, make sure the nav stack is reset and present the view controller from scratch:
rootViewController.clearNavigationStack()

// Give the `clearNavigationStack` call time to complete.
Expand Down

0 comments on commit 6e48e92

Please sign in to comment.