From 73c44c5e291b0f6b96fae53f686c5fe87c29eef5 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 19 Sep 2019 14:43:26 -0700 Subject: [PATCH] Supports deep linking to Patreon settings --- AltStore.xcodeproj/project.pbxproj | 4 +++ AltStore/AppDelegate.swift | 22 +++++++++++++++ AltStore/Base.lproj/Main.storyboard | 2 +- .../Settings/SettingsViewController.swift | 20 +++++++++++++ AltStore/TabBarController.swift | 28 +++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 AltStore/TabBarController.swift diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 600f7833..231f403a 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ BF3D64A222E8031100E9056B /* MergePolicy.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3D64A122E8031100E9056B /* MergePolicy.swift */; }; BF3D64B022E8D4B800E9056B /* AppContentViewControllerCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3D64AF22E8D4B800E9056B /* AppContentViewControllerCells.swift */; }; BF3F786422CAA41E008FBD20 /* ALTDeviceManager+Installation.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF3F786322CAA41E008FBD20 /* ALTDeviceManager+Installation.swift */; }; + BF41B806233423AE00C593A3 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF41B805233423AE00C593A3 /* TabBarController.swift */; }; BF43002E22A714AF0051E2BC /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF43002D22A714AF0051E2BC /* Keychain.swift */; }; BF43003022A71C960051E2BC /* UserDefaults+AltStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF43002F22A71C960051E2BC /* UserDefaults+AltStore.swift */; }; BF44CC6C232AEB90004DA9C3 /* LaunchAtLogin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF44CC6A232AEB74004DA9C3 /* LaunchAtLogin.framework */; }; @@ -311,6 +312,7 @@ BF3D64A122E8031100E9056B /* MergePolicy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MergePolicy.swift; sourceTree = ""; }; BF3D64AF22E8D4B800E9056B /* AppContentViewControllerCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppContentViewControllerCells.swift; sourceTree = ""; }; BF3F786322CAA41E008FBD20 /* ALTDeviceManager+Installation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ALTDeviceManager+Installation.swift"; sourceTree = ""; }; + BF41B805233423AE00C593A3 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = ""; }; BF43002D22A714AF0051E2BC /* Keychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = ""; }; BF43002F22A71C960051E2BC /* UserDefaults+AltStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+AltStore.swift"; sourceTree = ""; }; BF44CC6A232AEB74004DA9C3 /* LaunchAtLogin.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LaunchAtLogin.framework; path = Carthage/Build/Mac/LaunchAtLogin.framework; sourceTree = ""; }; @@ -865,6 +867,7 @@ BFD2476D2284B9A500981D42 /* AppDelegate.swift */, BFD247732284B9A500981D42 /* Main.storyboard */, BFE338E722F10E56002E24B9 /* LaunchViewController.swift */, + BF41B805233423AE00C593A3 /* TabBarController.swift */, BFE6325822A83BA800F30809 /* Authentication */, BFB6B21C2318700D0022A802 /* News */, BF9ABA4322DCFF33008935CF /* Browse */, @@ -1463,6 +1466,7 @@ BFE6326822A858F300F30809 /* Account.swift in Sources */, BFE6326622A857C200F30809 /* Team.swift in Sources */, BFD2476E2284B9A500981D42 /* AppDelegate.swift in Sources */, + BF41B806233423AE00C593A3 /* TabBarController.swift in Sources */, BFDB6A0B22AAEDB7007EA6D6 /* Operation.swift in Sources */, BF770E6722BD57C4002A40FE /* BackgroundTaskManager.swift in Sources */, BF100C54232D7DAE006A8926 /* StoreAppPolicy.swift in Sources */, diff --git a/AltStore/AppDelegate.swift b/AltStore/AppDelegate.swift index 8ab9548d..39142f9c 100644 --- a/AltStore/AppDelegate.swift +++ b/AltStore/AppDelegate.swift @@ -50,6 +50,11 @@ private let ReceivedApplicationState: @convention(c) (CFNotificationCenter?, Uns appDelegate.receivedApplicationState(notification: name) } +extension AppDelegate +{ + static let openPatreonSettingsDeepLinkNotification = Notification.Name("openPatreonSettingsDeepLinkNotification") +} + @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { @@ -90,6 +95,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { PatreonAPI.shared.refreshPatreonAccount() } + + func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool + { + return self.open(url) + } } private extension AppDelegate @@ -98,6 +108,18 @@ private extension AppDelegate { self.window?.tintColor = .altPrimary } + + func open(_ url: URL) -> Bool + { + guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return false } + guard let host = components.host, host.lowercased() == "patreon" else { return false } + + DispatchQueue.main.async { + NotificationCenter.default.post(name: AppDelegate.openPatreonSettingsDeepLinkNotification, object: nil) + } + + return true + } } extension AppDelegate diff --git a/AltStore/Base.lproj/Main.storyboard b/AltStore/Base.lproj/Main.storyboard index fb2a841e..46d7379a 100644 --- a/AltStore/Base.lproj/Main.storyboard +++ b/AltStore/Base.lproj/Main.storyboard @@ -32,7 +32,7 @@ - + diff --git a/AltStore/Settings/SettingsViewController.swift b/AltStore/Settings/SettingsViewController.swift index 5e66b571..05cd30a5 100644 --- a/AltStore/Settings/SettingsViewController.swift +++ b/AltStore/Settings/SettingsViewController.swift @@ -49,6 +49,13 @@ class SettingsViewController: UITableViewController @IBOutlet private var backgroundRefreshSwitch: UISwitch! + required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + + NotificationCenter.default.addObserver(self, selector: #selector(SettingsViewController.openPatreonSettings(_:)), name: AppDelegate.openPatreonSettingsDeepLinkNotification, object: nil) + } + override func viewDidLoad() { super.viewDidLoad() @@ -191,6 +198,19 @@ private extension SettingsViewController } } +private extension SettingsViewController +{ + @objc func openPatreonSettings(_ notification: Notification) + { + guard self.presentedViewController == nil else { return } + + UIView.performWithoutAnimation { + self.navigationController?.popViewController(animated: false) + self.performSegue(withIdentifier: "showPatreon", sender: nil) + } + } +} + extension SettingsViewController { override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int diff --git a/AltStore/TabBarController.swift b/AltStore/TabBarController.swift new file mode 100644 index 00000000..80d92f43 --- /dev/null +++ b/AltStore/TabBarController.swift @@ -0,0 +1,28 @@ +// +// TabBarController.swift +// AltStore +// +// Created by Riley Testut on 9/19/19. +// Copyright © 2019 Riley Testut. All rights reserved. +// + +import UIKit + +class TabBarController: UITabBarController +{ + required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + + NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.openPatreonSettings(_:)), name: AppDelegate.openPatreonSettingsDeepLinkNotification, object: nil) + } +} + +private extension TabBarController +{ + @objc func openPatreonSettings(_ notification: Notification) + { + guard let items = self.tabBar.items else { return } + self.selectedIndex = items.count - 1 + } +}