Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#8897 - Move to UISceneDelegate #9464

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@
DA3A4FE9254A781A00C4A9C9 /* TabTableViewHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA3A4FE8254A781A00C4A9C9 /* TabTableViewHeader.swift */; };
DA52E1DA25F5961F0092204C /* TabTrayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA52E1D925F5961F0092204C /* TabTrayViewController.swift */; };
DA9FD88424E213B500168D1E /* SmallQuickLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9FD88224E213B400168D1E /* SmallQuickLink.swift */; };
DA58976A26704308007F0784 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA58976926704308007F0784 /* SceneDelegate.swift */; };
DA9FD88624E213CD00168D1E /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9FD88524E213CC00168D1E /* Helpers.swift */; };
DA9FD88824E213DD00168D1E /* QuickLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9FD88724E213DC00168D1E /* QuickLink.swift */; };
DACDE996225E537900C8F37F /* VersionSettingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DACDE995225E537900C8F37F /* VersionSettingTests.swift */; };
Expand Down Expand Up @@ -4633,6 +4634,7 @@
DA3A4FE8254A781A00C4A9C9 /* TabTableViewHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabTableViewHeader.swift; sourceTree = "<group>"; };
DA4446B0870E847782CEFAF4 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/ErrorPages.strings; sourceTree = "<group>"; };
DA52E1D925F5961F0092204C /* TabTrayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabTrayViewController.swift; sourceTree = "<group>"; };
DA58976926704308007F0784 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
DA654F2582BF9863A719CB00 /* gu-IN */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "gu-IN"; path = "gu-IN.lproj/Shared.strings"; sourceTree = "<group>"; };
DA744D888927B768AD70ECF4 /* ml */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ml; path = ml.lproj/3DTouchActions.strings; sourceTree = "<group>"; };
DA9FD88224E213B400168D1E /* SmallQuickLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SmallQuickLink.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7794,6 +7796,7 @@
EB9854FD2422686F0040F24B /* AppDelegate+PushNotifications.swift */,
EB98550024226EF60040F24B /* AppDelegate+SyncSentTabs.swift */,
D3BE7B451B054F8600641031 /* UITestAppDelegate.swift */,
DA58976926704308007F0784 /* SceneDelegate.swift */,
);
name = Delegates;
sourceTree = "<group>";
Expand Down Expand Up @@ -10514,6 +10517,7 @@
8AD40FC727BADC3400672675 /* ToolbarTextField.swift in Sources */,
CA90753824929B22005B794D /* NoLoginsView.swift in Sources */,
E4B423BE1AB9FE6A007E66C8 /* ReaderModeCache.swift in Sources */,
DA58976A26704308007F0784 /* SceneDelegate.swift in Sources */,
396CDB55203C5B870034A3A3 /* TabTrayController+KeyCommands.swift in Sources */,
74E36D781B71323500D69DA1 /* SettingsContentViewController.swift in Sources */,
EBB8950C21939E4100EB91A0 /* FirefoxTabContentBlocker.swift in Sources */,
Expand Down
128 changes: 12 additions & 116 deletions Client/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// This is the easiest way to force a bootstrap that's guaranteed to happen on app launch
private var appContainer: ServiceProvider = AppContainer.shared
var window: UIWindow?
var browserViewController: BrowserViewController!
var rootViewController: UIViewController!
var tabManager: TabManager!
var receivedURLs = [URL]()
var orientationLock = UIInterfaceOrientationMask.all
Expand All @@ -35,22 +33,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
log.info("startApplication begin")

self.window = UIWindow(frame: UIScreen.main.bounds)

appLaunchUtil = AppLaunchUtil(profile: profile)
appLaunchUtil?.setUpPreLaunchDependencies()

// Set up a web server that serves us static content. Do this early so that it is ready when the UI is presented.
webServerUtil = WebServerUtil(profile: profile)
webServerUtil?.setUpWebServer()

let imageStore = DiskImageStore(files: profile.files, namespace: "TabManagerScreenshots", quality: UIConstants.ScreenshotQuality)
self.tabManager = TabManager(profile: profile, imageStore: imageStore)

menuBuilderHelper = MenuBuilderHelper()

setupRootViewController()

log.info("startApplication end")

return true
Expand All @@ -62,15 +53,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// Allow deinitializers to close our database connections.
tabManager = nil
browserViewController = nil
rootViewController = nil
}

func application(_ application: UIApplication,
didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

window!.makeKeyAndVisible()
pushNotificationSetup()
appLaunchUtil?.setUpPostLaunchDependencies()
backgroundSyncUtil = BackgroundSyncUtil(profile: profile, application: application)
Expand Down Expand Up @@ -102,19 +90,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
webServerUtil?.setUpWebServer()

/// When transitioning to scenes, each scene's BVC needs to resume its file download queue.
browserViewController.downloadQueue.resumeAll()
for session in application.openSessions {
(session.scene?.delegate as? SceneDelegate)?.browserViewController.downloadQueue.resumeAll()
}

TelemetryWrapper.recordEvent(category: .action, method: .foreground, object: .app)

// Delay these operations until after UIKit/UIApp init is complete
// - loadQueuedTabs accesses the DB and shows up as a hot path in profiling
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
// We could load these here, but then we have to futz with the tab counter
// and making NSURLRequests.
self.browserViewController.loadQueuedTabs(receivedURLs: self.receivedURLs)
self.receivedURLs.removeAll()
application.applicationIconBadgeNumber = 0
}
// Create fx favicon cache directory
FaviconFetcher.createWebImageCacheDirectory()
// update top sites widget
Expand All @@ -123,7 +104,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Cleanup can be a heavy operation, take it out of the startup path. Instead check after a few seconds.
DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
self.profile.cleanupHistoryIfNeeded()
self.browserViewController.ratingPromptManager.updateData()
BrowserViewController.foregroundBVC().ratingPromptManager.updateData()
}
}

Expand All @@ -134,8 +115,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func applicationDidEnterBackground(_ application: UIApplication) {
// Pause file downloads.
// TODO: iOS 13 needs to iterate all the BVCs.
browserViewController.downloadQueue.pauseAll()
for session in application.openSessions {
(session.scene?.delegate as? SceneDelegate)?.browserViewController.downloadQueue.pauseAll()
}

TelemetryWrapper.recordEvent(category: .action, method: .background, object: .app)
TabsQuantityTelemetry.trackTabsQuantity(tabManager: tabManager)
Expand Down Expand Up @@ -166,19 +148,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
widgetManager?.writeWidgetKitTopSites()
}
}

/// When a user presses and holds the app icon from the Home Screen, we present quick actions / shortcut items (see QuickActions).
///
/// This method can handle a quick action from both app launch and when the app becomes active. However, the system calls launch methods first if the app `launches`
/// and gives you a chance to handle the shortcut there. If it's not handled there, this method is called in the activation process with the shortcut item.
///
/// Quick actions / shortcut items are handled here as long as our two launch methods return `true`. If either of them return `false`, this method
/// won't be called to handle shortcut items.
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let handledShortCutItem = QuickActions.sharedInstance.handleShortCutItem(shortcutItem, withBrowserViewController: browserViewController)

completionHandler(handledShortCutItem)
}
}

// This functionality will need to be moved to the SceneDelegate when the time comes
Expand All @@ -189,86 +158,13 @@ extension AppDelegate {
supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return self.orientationLock
}
}

extension AppDelegate {
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if userActivity.activityType == SiriShortcuts.activityType.openURL.rawValue {
browserViewController.openBlankNewTab(focusLocationField: false)
return true
}

// If the `NSUserActivity` has a `webpageURL`, it is either a deep link or an old history item
// reached via a "Spotlight" search before we began indexing visited pages via CoreSpotlight.
if let url = userActivity.webpageURL {
let query = url.getQuery()

// Check for fxa sign-in code and launch the login screen directly
if query["signin"] != nil {
// bvc.launchFxAFromDeeplinkURL(url) // Was using Adjust. Consider hooking up again when replacement system in-place.
return true
}

// Per Adjust documentation, https://docs.adjust.com/en/universal-links/#running-campaigns-through-universal-links,
// it is recommended that links contain the `deep_link` query parameter. This link will also
// be url encoded.
if let deepLink = query["deep_link"]?.removingPercentEncoding, let url = URL(string: deepLink) {
browserViewController.switchToTabForURLOrOpen(url)
return true
}

browserViewController.switchToTabForURLOrOpen(url)
return true
}

// Otherwise, check if the `NSUserActivity` is a CoreSpotlight item and switch to its tab or
// open a new one.
if userActivity.activityType == CSSearchableItemActionType {
if let userInfo = userActivity.userInfo,
let urlString = userInfo[CSSearchableItemActivityIdentifier] as? String,
let url = URL(string: urlString) {
browserViewController.switchToTabForURLOrOpen(url)
return true
}
}

return false
}

func application(_ application: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
guard let routerpath = NavigationPath(url: url) else { return false }

if let _ = profile.prefs.boolForKey(PrefsKeys.AppExtensionTelemetryOpenUrl) {
profile.prefs.removeObjectForKey(PrefsKeys.AppExtensionTelemetryOpenUrl)
var object = TelemetryWrapper.EventObject.url
if case .text = routerpath {
object = .searchText
}
TelemetryWrapper.recordEvent(category: .appExtensionAction, method: .applicationOpenUrl, object: object)
}

DispatchQueue.main.async {
NavigationPath.handle(nav: routerpath, with: self.browserViewController)
}
return true
}

private func setupRootViewController() {
if !LegacyThemeManager.instance.systemThemeIsOn {
window?.overrideUserInterfaceStyle = LegacyThemeManager.instance.userInterfaceStyle
}

browserViewController = BrowserViewController(profile: profile, tabManager: tabManager)
browserViewController.edgesForExtendedLayout = []

let navigationController = UINavigationController(rootViewController: browserViewController)
navigationController.isNavigationBarHidden = true
navigationController.edgesForExtendedLayout = UIRectEdge(rawValue: 0)
rootViewController = navigationController

window!.rootViewController = rootViewController
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
}

Expand Down
Loading