forked from shadowfacts/Tusker
Fix crash when using show timeline Siri Shortcut
This commit is contained in:
parent
93828830a9
commit
d638ff513b
|
@ -334,4 +334,18 @@ extension MainSplitViewController: TuskerRootViewController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getTabController(tab: MainTabBarViewController.Tab) -> UIViewController? {
|
||||
if traitCollection.horizontalSizeClass == .compact {
|
||||
return tabBarViewController?.getTabController(tab: tab)
|
||||
} else {
|
||||
if tab == .compose {
|
||||
return nil
|
||||
} else if case .tab(tab) = sidebar.selectedItem {
|
||||
return viewController(for: .secondary)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,5 @@ import UIKit
|
|||
protocol TuskerRootViewController: UIViewController {
|
||||
func presentCompose()
|
||||
func select(tab: MainTabBarViewController.Tab)
|
||||
func getTabController(tab: MainTabBarViewController.Tab) -> UIViewController?
|
||||
}
|
||||
|
|
|
@ -21,14 +21,14 @@ class UserActivityManager {
|
|||
return scene.session.mastodonController!
|
||||
}
|
||||
|
||||
private static func getMainTabBarController() -> MainTabBarViewController {
|
||||
private static func getMainViewController() -> TuskerRootViewController {
|
||||
let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first!
|
||||
let window = scene.windows.first { $0.isKeyWindow }!
|
||||
return window.rootViewController as! MainTabBarViewController
|
||||
return window.rootViewController as! TuskerRootViewController
|
||||
}
|
||||
|
||||
private static func present(_ vc: UIViewController, animated: Bool = true) {
|
||||
getMainTabBarController().present(vc, animated: animated)
|
||||
getMainViewController().present(vc, animated: animated)
|
||||
}
|
||||
|
||||
// MARK: - New Post
|
||||
|
@ -66,9 +66,9 @@ class UserActivityManager {
|
|||
}
|
||||
|
||||
static func handleCheckNotifications(activity: NSUserActivity) {
|
||||
let tabBarController = getMainTabBarController()
|
||||
tabBarController.select(tab: .notifications)
|
||||
if let navigationController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
|
||||
let mainViewController = getMainViewController()
|
||||
mainViewController.select(tab: .notifications)
|
||||
if let navigationController = mainViewController.getTabController(tab: .notifications) as? UINavigationController,
|
||||
let notificationsPageController = navigationController.viewControllers.first as? NotificationsPageViewController {
|
||||
navigationController.popToRootViewController(animated: false)
|
||||
notificationsPageController.loadViewIfNeeded()
|
||||
|
@ -86,9 +86,9 @@ class UserActivityManager {
|
|||
}
|
||||
|
||||
static func handleCheckMentions(activity: NSUserActivity) {
|
||||
let tabBarController = getMainTabBarController()
|
||||
tabBarController.select(tab: .notifications)
|
||||
if let navController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
|
||||
let mainViewController = getMainViewController()
|
||||
mainViewController.select(tab: .notifications)
|
||||
if let navController = mainViewController.getTabController(tab: .notifications) as? UINavigationController,
|
||||
let notificationsPageController = navController.viewControllers.first as? NotificationsPageViewController {
|
||||
navController.popToRootViewController(animated: false)
|
||||
notificationsPageController.loadViewIfNeeded()
|
||||
|
@ -133,9 +133,12 @@ class UserActivityManager {
|
|||
return
|
||||
}
|
||||
|
||||
let tabBarController = getMainTabBarController()
|
||||
tabBarController.select(tab: .timelines)
|
||||
let navigationController = tabBarController.viewControllers![0] as! UINavigationController
|
||||
let mainViewController = getMainViewController()
|
||||
mainViewController.select(tab: .timelines)
|
||||
guard let navigationController = mainViewController.getTabController(tab: .timelines) as? UINavigationController else {
|
||||
return
|
||||
}
|
||||
|
||||
switch timeline {
|
||||
case .home, .public(true), .public(false):
|
||||
navigationController.popToRootViewController(animated: false)
|
||||
|
@ -170,9 +173,9 @@ class UserActivityManager {
|
|||
}
|
||||
|
||||
static func handleSearch(activity: NSUserActivity) {
|
||||
let tabBarController = getMainTabBarController()
|
||||
tabBarController.select(tab: .explore)
|
||||
if let navigationController = tabBarController.getTabController(tab: .explore) as? UINavigationController,
|
||||
let mainViewController = getMainViewController()
|
||||
mainViewController.select(tab: .explore)
|
||||
if let navigationController = mainViewController.getTabController(tab: .explore) as? UINavigationController,
|
||||
let exploreController = navigationController.viewControllers.first as? ExploreViewController {
|
||||
navigationController.popToRootViewController(animated: false)
|
||||
exploreController.searchController.isActive = true
|
||||
|
@ -189,9 +192,9 @@ class UserActivityManager {
|
|||
}
|
||||
|
||||
static func handleBookmarks(activity: NSUserActivity) {
|
||||
let tabBarController = getMainTabBarController()
|
||||
tabBarController.select(tab: .explore)
|
||||
if let navigationController = tabBarController.getTabController(tab: .explore) as? UINavigationController {
|
||||
let mainViewController = getMainViewController()
|
||||
mainViewController.select(tab: .explore)
|
||||
if let navigationController = mainViewController.getTabController(tab: .explore) as? UINavigationController {
|
||||
navigationController.popToRootViewController(animated: false)
|
||||
navigationController.pushViewController(BookmarksTableViewController(mastodonController: mastodonController), animated: false)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue