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
|
2021-10-25 22:27:30 -07:00
|
|
|
import AltStoreCore
|
2019-09-19 14:43:26 -07:00
|
|
|
|
2019-09-27 17:39:36 -07:00
|
|
|
extension TabBarController
|
|
|
|
|
{
|
|
|
|
|
private enum Tab: Int, CaseIterable
|
|
|
|
|
{
|
|
|
|
|
case news
|
2023-10-17 14:49:13 -05:00
|
|
|
case sources
|
2019-09-27 17:39:36 -07:00
|
|
|
case browse
|
|
|
|
|
case myApps
|
|
|
|
|
case settings
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 09:52:12 -05:00
|
|
|
final class TabBarController: UITabBarController
|
2019-09-19 14:43:26 -07:00
|
|
|
{
|
2020-08-28 12:15:15 -07:00
|
|
|
private var initialSegue: (identifier: String, sender: Any?)?
|
|
|
|
|
|
|
|
|
|
private var _viewDidAppear = false
|
|
|
|
|
|
2023-10-17 14:49:13 -05:00
|
|
|
private var sourcesViewController: SourcesViewController!
|
|
|
|
|
|
2019-09-19 14:43:26 -07:00
|
|
|
required init?(coder aDecoder: NSCoder)
|
|
|
|
|
{
|
|
|
|
|
super.init(coder: aDecoder)
|
|
|
|
|
|
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)
|
2025-04-24 15:48:29 +10:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.exportFiles(_:)), name: AppDelegate.exportCertificateNotification, object: nil)
|
2024-08-06 10:43:52 +09:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.openErrorLog(_:)), name: ToastView.openErrorLogNotification, object: nil)
|
2020-08-28 12:15:15 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-17 14:49:13 -05:00
|
|
|
override func viewDidLoad()
|
|
|
|
|
{
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
2023-10-18 17:18:03 -05:00
|
|
|
let browseNavigationController = self.viewControllers![Tab.browse.rawValue] as! UINavigationController
|
|
|
|
|
browseNavigationController.tabBarItem.image = UIImage(systemName: "bag")
|
|
|
|
|
|
2023-10-17 14:49:13 -05:00
|
|
|
let sourcesNavigationController = self.viewControllers![Tab.sources.rawValue] as! UINavigationController
|
|
|
|
|
self.sourcesViewController = sourcesNavigationController.viewControllers.first as? SourcesViewController
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-28 12:15:15 -07:00
|
|
|
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 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
|
|
|
|
|
{
|
2023-10-17 14:49:13 -05:00
|
|
|
presentedViewController.dismiss(animated: true) {
|
|
|
|
|
self.presentSources(sender)
|
2020-08-28 12:15:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-10-17 14:49:13 -05:00
|
|
|
|
|
|
|
|
if let notification = (sender as? Notification), let sourceURL = notification.userInfo?[AppDelegate.addSourceDeepLinkURLKey] as? URL
|
|
|
|
|
{
|
|
|
|
|
self.sourcesViewController?.deepLinkSourceURL = sourceURL
|
|
|
|
|
}
|
2020-08-28 12:15:15 -07:00
|
|
|
|
2023-10-17 14:49:13 -05:00
|
|
|
self.selectedIndex = Tab.sources.rawValue
|
2020-08-27 16:39:03 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 14:43:26 -07:00
|
|
|
private extension TabBarController
|
|
|
|
|
{
|
2019-09-27 17:39:36 -07:00
|
|
|
@objc func importApp(_ notification: Notification)
|
|
|
|
|
{
|
|
|
|
|
self.selectedIndex = Tab.myApps.rawValue
|
2019-09-19 14:43:26 -07:00
|
|
|
}
|
2024-12-07 17:45:09 +05:30
|
|
|
|
|
|
|
|
@objc func openErrorLog(_ notification: Notification)
|
|
|
|
|
{
|
2024-08-06 10:43:52 +09:00
|
|
|
self.selectedIndex = Tab.settings.rawValue
|
|
|
|
|
}
|
2025-04-20 08:48:50 +08:00
|
|
|
|
2025-04-24 15:48:29 +10:00
|
|
|
@objc func exportFiles(_ notification: Notification)
|
2025-04-20 08:48:50 +08:00
|
|
|
{
|
|
|
|
|
self.selectedIndex = Tab.settings.rawValue
|
|
|
|
|
}
|
2019-09-19 14:43:26 -07:00
|
|
|
}
|