2019-09-19 14:43:26 -07:00
|
|
|
//
|
|
|
|
|
// TabBarController.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 9/19/19.
|
|
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
2019-09-27 17:39:36 -07:00
|
|
|
extension TabBarController
|
|
|
|
|
{
|
|
|
|
|
private enum Tab: Int, CaseIterable
|
|
|
|
|
{
|
|
|
|
|
case news
|
|
|
|
|
case browse
|
|
|
|
|
case myApps
|
|
|
|
|
case settings
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 14:43:26 -07:00
|
|
|
class TabBarController: UITabBarController
|
|
|
|
|
{
|
2020-08-28 12:15:15 -07:00
|
|
|
private var initialSegue: (identifier: String, sender: Any?)?
|
|
|
|
|
|
|
|
|
|
private var _viewDidAppear = false
|
|
|
|
|
|
2019-09-19 14:43:26 -07:00
|
|
|
required init?(coder aDecoder: NSCoder)
|
|
|
|
|
{
|
|
|
|
|
super.init(coder: aDecoder)
|
|
|
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.openPatreonSettings(_:)), name: AppDelegate.openPatreonSettingsDeepLinkNotification, object: nil)
|
2019-09-27 17:39:36 -07:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.importApp(_:)), name: AppDelegate.importAppDeepLinkNotification, object: nil)
|
2020-08-28 12:15:15 -07:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.presentSources(_:)), name: AppDelegate.addSourceDeepLinkNotification, object: nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func viewDidAppear(_ animated: Bool)
|
|
|
|
|
{
|
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
|
|
|
|
|
_viewDidAppear = true
|
|
|
|
|
|
|
|
|
|
if let (identifier, sender) = self.initialSegue
|
|
|
|
|
{
|
|
|
|
|
self.initialSegue = nil
|
|
|
|
|
self.performSegue(withIdentifier: identifier, sender: sender)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
|
|
|
|
|
{
|
|
|
|
|
guard segue.identifier == "presentSources",
|
|
|
|
|
let notification = sender as? Notification,
|
|
|
|
|
let sourceURL = notification.userInfo?[AppDelegate.addSourceDeepLinkURLKey] as? URL
|
|
|
|
|
else { return }
|
|
|
|
|
|
|
|
|
|
let navigationController = segue.destination as! UINavigationController
|
|
|
|
|
let sourcesViewController = navigationController.viewControllers.first as! SourcesViewController
|
|
|
|
|
sourcesViewController.deepLinkSourceURL = sourceURL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func performSegue(withIdentifier identifier: String, sender: Any?)
|
|
|
|
|
{
|
|
|
|
|
guard _viewDidAppear else {
|
|
|
|
|
self.initialSegue = (identifier, sender)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.performSegue(withIdentifier: identifier, sender: sender)
|
2019-09-19 14:43:26 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 16:39:03 -07:00
|
|
|
extension TabBarController
|
|
|
|
|
{
|
|
|
|
|
@objc func presentSources(_ sender: Any)
|
|
|
|
|
{
|
2020-08-28 12:15:15 -07:00
|
|
|
if let presentedViewController = self.presentedViewController
|
|
|
|
|
{
|
|
|
|
|
if let navigationController = presentedViewController as? UINavigationController,
|
|
|
|
|
let sourcesViewController = navigationController.viewControllers.first as? SourcesViewController
|
|
|
|
|
{
|
|
|
|
|
if let notification = (sender as? Notification),
|
|
|
|
|
let sourceURL = notification.userInfo?[AppDelegate.addSourceDeepLinkURLKey] as? URL
|
|
|
|
|
{
|
|
|
|
|
sourcesViewController.deepLinkSourceURL = sourceURL
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Don't dismiss SourcesViewController if it's already presented.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
presentedViewController.dismiss(animated: true) {
|
|
|
|
|
self.presentSources(sender)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 16:39:03 -07:00
|
|
|
self.performSegue(withIdentifier: "presentSources", sender: sender)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 14:43:26 -07:00
|
|
|
private extension TabBarController
|
|
|
|
|
{
|
|
|
|
|
@objc func openPatreonSettings(_ notification: Notification)
|
|
|
|
|
{
|
2019-09-27 17:39:36 -07:00
|
|
|
self.selectedIndex = Tab.settings.rawValue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func importApp(_ notification: Notification)
|
|
|
|
|
{
|
|
|
|
|
self.selectedIndex = Tab.myApps.rawValue
|
2019-09-19 14:43:26 -07:00
|
|
|
}
|
|
|
|
|
}
|