From e2b8b7369e16a0c1d535406988d55c76a4f8225b Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Mon, 30 May 2022 23:43:47 -0600 Subject: [PATCH] Add view for multiple teams from Megarush --- AltStore.xcodeproj/project.pbxproj | 1 + .../Authentication/Authentication.storyboard | 72 +++++++++++++++++-- .../SelectTeamViewController.swift | 61 ++++++++++++++++ .../Operations/AuthenticationOperation.swift | 41 ++++++----- 4 files changed, 150 insertions(+), 25 deletions(-) create mode 100644 AltStore/Authentication/SelectTeamViewController.swift diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 8cb680fb..802a2bba 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 0E33F94B8D78AB969FD309A3 /* Pods_AltStoreCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A08F67C18350C7990753F03F /* Pods_AltStoreCore.framework */; }; + 195EA4C92845E15500F25835 /* SelectTeamViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 195EA4C82845E15500F25835 /* SelectTeamViewController.swift */; }; 2A77E3D272F3D92436FAC272 /* Pods_AltStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9EEAA842DA87A88A870053B /* Pods_AltStore.framework */; }; A8BCEBEAC0620CF80A2FD26D /* Pods_AltServer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC3822AB1C4CF1D4CDF7445D /* Pods_AltServer.framework */; }; BF02419622F2199300129732 /* RefreshAttemptsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF02419522F2199300129732 /* RefreshAttemptsViewController.swift */; }; diff --git a/AltStore/Authentication/Authentication.storyboard b/AltStore/Authentication/Authentication.storyboard index aaf662be..278831b0 100644 --- a/AltStore/Authentication/Authentication.storyboard +++ b/AltStore/Authentication/Authentication.storyboard @@ -493,14 +493,72 @@ - + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AltStore/Authentication/SelectTeamViewController.swift b/AltStore/Authentication/SelectTeamViewController.swift new file mode 100644 index 00000000..822dc945 --- /dev/null +++ b/AltStore/Authentication/SelectTeamViewController.swift @@ -0,0 +1,61 @@ +// +// SelectTeamViewController.swift +// AltStore +// +// Created by Megarushing on 4/26/21. +// Copyright © 2021 Riley Testut. All rights reserved. +// + +import UIKit +import SafariServices +import MessageUI +import Intents +import IntentsUI + +import AltSign + +class SelectTeamViewController: UITableViewController +{ + public var teams: [ALTTeam]? + public var completionHandler: ((Result) -> Void)? + + private var prototypeHeaderFooterView: SettingsHeaderFooterView! + + override var preferredStatusBarStyle: UIStatusBarStyle { + return .lightContent + } + + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return teams?.count ?? 0 + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + return self.completionHandler!(.success((self.teams?[indexPath.row])!)) + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "TeamCell", for: indexPath) as! InsetGroupTableViewCell + + cell.textLabel?.text = self.teams?[indexPath.row].name + cell.detailTextLabel?.text = self.teams?[indexPath.row].type.localizedDescription + if indexPath.row == 0 + { + cell.style = InsetGroupTableViewCell.Style.top + } else if indexPath.row == self.tableView(self.tableView, numberOfRowsInSection: indexPath.section) - 1 { + cell.style = InsetGroupTableViewCell.Style.bottom + } else { + cell.style = InsetGroupTableViewCell.Style.middle + } + + return cell + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + "Teams" + } + +} diff --git a/AltStore/Operations/AuthenticationOperation.swift b/AltStore/Operations/AuthenticationOperation.swift index 1aaf81bd..c787ffdc 100644 --- a/AltStore/Operations/AuthenticationOperation.swift +++ b/AltStore/Operations/AuthenticationOperation.swift @@ -17,6 +17,7 @@ enum AuthenticationError: LocalizedError { case noTeam case noCertificate + case teamSelectorError case missingPrivateKey case missingCertificate @@ -24,6 +25,7 @@ enum AuthenticationError: LocalizedError var errorDescription: String? { switch self { case .noTeam: return NSLocalizedString("Developer team could not be found.", comment: "") + case .teamSelectorError: return NSLocalizedString("Error presenting team selector view.", comment: "") case .noCertificate: return NSLocalizedString("Developer certificate could not be found.", comment: "") case .missingPrivateKey: return NSLocalizedString("The certificate's private key could not be found.", comment: "") case .missingCertificate: return NSLocalizedString("The certificate could not be found.", comment: "") @@ -441,24 +443,27 @@ private extension AuthenticationOperation func fetchTeam(for account: ALTAccount, session: ALTAppleAPISession, completionHandler: @escaping (Result) -> Void) { func selectTeam(from teams: [ALTTeam]) - { - if let team = teams.first(where: { $0.type == .individual }) - { - return completionHandler(.success(team)) - } - else if let team = teams.first(where: { $0.type == .free }) - { - return completionHandler(.success(team)) - } - else if let team = teams.first - { - return completionHandler(.success(team)) - } - else - { - return completionHandler(.failure(AuthenticationError.noTeam)) - } - } + { + if teams.count <= 1 { + if let team = teams.first { + return completionHandler(.success(team)) + } else { + return completionHandler(.failure(AuthenticationError.noTeam)) + } + } else { + DispatchQueue.main.async { + let selectTeamViewController = self.storyboard.instantiateViewController(withIdentifier: "selectTeamViewController") as! SelectTeamViewController + + selectTeamViewController.teams = teams + selectTeamViewController.completionHandler = completionHandler + + if !self.present(selectTeamViewController) + { + return completionHandler(.failure(AuthenticationError.noTeam)) + } + } + } + } ALTAppleAPI.shared.fetchTeams(for: account, session: session) { (teams, error) in switch Result(teams, error)