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

Commit

Permalink
Fix #8228: Switch to UIScene notifications (#8249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T authored and iccub committed Oct 16, 2023
1 parent 986995e commit 4b72b64
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,11 @@ public class BrowserViewController: UIViewController {
displayedPopoverController?.dismiss(animated: true)
}

@objc func appDidEnterBackgroundNotification() {
@objc func sceneDidEnterBackgroundNotification(_ notification: NSNotification) {
guard let scene = notification.object as? UIScene, scene == currentScene else {
return
}

displayedPopoverController?.dismiss(animated: false) {
self.updateDisplayedPopoverProperties = nil
self.displayedPopoverController = nil
Expand All @@ -706,7 +710,11 @@ public class BrowserViewController: UIViewController {
toolbarVisibilityViewModel.toolbarState = .expanded
}

@objc func appWillResignActiveNotification() {
@objc func sceneWillResignActiveNotification(_ notification: NSNotification) {
guard let scene = notification.object as? UIScene, scene == currentScene else {
return
}

tabManager.saveAllTabs()

// Dismiss any popovers that might be visible
Expand Down Expand Up @@ -739,7 +747,11 @@ public class BrowserViewController: UIViewController {
}
}

@objc func appDidBecomeActiveNotification() {
@objc func sceneDidBecomeActiveNotification(_ notification: NSNotification) {
guard let scene = notification.object as? UIScene, scene == currentScene else {
return
}

guard let tab = tabManager.selectedTab, tab.isPrivate else {
return
}
Expand Down Expand Up @@ -823,14 +835,14 @@ public class BrowserViewController: UIViewController {

NotificationCenter.default.do {
$0.addObserver(
self, selector: #selector(appWillResignActiveNotification),
name: UIApplication.willResignActiveNotification, object: nil)
self, selector: #selector(sceneWillResignActiveNotification(_:)),
name: UIScene.willDeactivateNotification, object: nil)
$0.addObserver(
self, selector: #selector(appDidBecomeActiveNotification),
name: UIApplication.didBecomeActiveNotification, object: nil)
self, selector: #selector(sceneDidBecomeActiveNotification(_:)),
name: UIScene.didActivateNotification, object: nil)
$0.addObserver(
self, selector: #selector(appDidEnterBackgroundNotification),
name: UIApplication.didEnterBackgroundNotification, object: nil)
self, selector: #selector(sceneDidEnterBackgroundNotification),
name: UIScene.didEnterBackgroundNotification, object: nil)
$0.addObserver(
self, selector: #selector(appWillTerminateNotification),
name: UIApplication.willTerminateNotification, object: nil)
Expand Down

0 comments on commit 4b72b64

Please sign in to comment.