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 {
|
protocol TuskerRootViewController: UIViewController {
|
||||||
func presentCompose()
|
func presentCompose()
|
||||||
func select(tab: MainTabBarViewController.Tab)
|
func select(tab: MainTabBarViewController.Tab)
|
||||||
|
func getTabController(tab: MainTabBarViewController.Tab) -> UIViewController?
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,14 @@ class UserActivityManager {
|
||||||
return scene.session.mastodonController!
|
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 scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first!
|
||||||
let window = scene.windows.first { $0.isKeyWindow }!
|
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) {
|
private static func present(_ vc: UIViewController, animated: Bool = true) {
|
||||||
getMainTabBarController().present(vc, animated: animated)
|
getMainViewController().present(vc, animated: animated)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - New Post
|
// MARK: - New Post
|
||||||
|
@ -66,9 +66,9 @@ class UserActivityManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func handleCheckNotifications(activity: NSUserActivity) {
|
static func handleCheckNotifications(activity: NSUserActivity) {
|
||||||
let tabBarController = getMainTabBarController()
|
let mainViewController = getMainViewController()
|
||||||
tabBarController.select(tab: .notifications)
|
mainViewController.select(tab: .notifications)
|
||||||
if let navigationController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
|
if let navigationController = mainViewController.getTabController(tab: .notifications) as? UINavigationController,
|
||||||
let notificationsPageController = navigationController.viewControllers.first as? NotificationsPageViewController {
|
let notificationsPageController = navigationController.viewControllers.first as? NotificationsPageViewController {
|
||||||
navigationController.popToRootViewController(animated: false)
|
navigationController.popToRootViewController(animated: false)
|
||||||
notificationsPageController.loadViewIfNeeded()
|
notificationsPageController.loadViewIfNeeded()
|
||||||
|
@ -86,9 +86,9 @@ class UserActivityManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func handleCheckMentions(activity: NSUserActivity) {
|
static func handleCheckMentions(activity: NSUserActivity) {
|
||||||
let tabBarController = getMainTabBarController()
|
let mainViewController = getMainViewController()
|
||||||
tabBarController.select(tab: .notifications)
|
mainViewController.select(tab: .notifications)
|
||||||
if let navController = tabBarController.getTabController(tab: .notifications) as? UINavigationController,
|
if let navController = mainViewController.getTabController(tab: .notifications) as? UINavigationController,
|
||||||
let notificationsPageController = navController.viewControllers.first as? NotificationsPageViewController {
|
let notificationsPageController = navController.viewControllers.first as? NotificationsPageViewController {
|
||||||
navController.popToRootViewController(animated: false)
|
navController.popToRootViewController(animated: false)
|
||||||
notificationsPageController.loadViewIfNeeded()
|
notificationsPageController.loadViewIfNeeded()
|
||||||
|
@ -133,9 +133,12 @@ class UserActivityManager {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let tabBarController = getMainTabBarController()
|
let mainViewController = getMainViewController()
|
||||||
tabBarController.select(tab: .timelines)
|
mainViewController.select(tab: .timelines)
|
||||||
let navigationController = tabBarController.viewControllers![0] as! UINavigationController
|
guard let navigationController = mainViewController.getTabController(tab: .timelines) as? UINavigationController else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch timeline {
|
switch timeline {
|
||||||
case .home, .public(true), .public(false):
|
case .home, .public(true), .public(false):
|
||||||
navigationController.popToRootViewController(animated: false)
|
navigationController.popToRootViewController(animated: false)
|
||||||
|
@ -170,9 +173,9 @@ class UserActivityManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func handleSearch(activity: NSUserActivity) {
|
static func handleSearch(activity: NSUserActivity) {
|
||||||
let tabBarController = getMainTabBarController()
|
let mainViewController = getMainViewController()
|
||||||
tabBarController.select(tab: .explore)
|
mainViewController.select(tab: .explore)
|
||||||
if let navigationController = tabBarController.getTabController(tab: .explore) as? UINavigationController,
|
if let navigationController = mainViewController.getTabController(tab: .explore) as? UINavigationController,
|
||||||
let exploreController = navigationController.viewControllers.first as? ExploreViewController {
|
let exploreController = navigationController.viewControllers.first as? ExploreViewController {
|
||||||
navigationController.popToRootViewController(animated: false)
|
navigationController.popToRootViewController(animated: false)
|
||||||
exploreController.searchController.isActive = true
|
exploreController.searchController.isActive = true
|
||||||
|
@ -189,9 +192,9 @@ class UserActivityManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func handleBookmarks(activity: NSUserActivity) {
|
static func handleBookmarks(activity: NSUserActivity) {
|
||||||
let tabBarController = getMainTabBarController()
|
let mainViewController = getMainViewController()
|
||||||
tabBarController.select(tab: .explore)
|
mainViewController.select(tab: .explore)
|
||||||
if let navigationController = tabBarController.getTabController(tab: .explore) as? UINavigationController {
|
if let navigationController = mainViewController.getTabController(tab: .explore) as? UINavigationController {
|
||||||
navigationController.popToRootViewController(animated: false)
|
navigationController.popToRootViewController(animated: false)
|
||||||
navigationController.pushViewController(BookmarksTableViewController(mastodonController: mastodonController), animated: false)
|
navigationController.pushViewController(BookmarksTableViewController(mastodonController: mastodonController), animated: false)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue