Files
SideStore/SideStoreApp/Sources/SideStoreUIKit/Authentication/RefreshAltStoreViewController.swift

77 lines
3.1 KiB
Swift
Raw Normal View History

//
// RefreshAltStoreViewController.swift
// AltStore
//
// Created by Riley Testut on 10/26/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import UIKit
import AltSign
2023-03-01 00:48:36 -05:00
import SideStoreCore
2023-03-01 14:36:52 -05:00
import RoxasUIKit
2023-03-01 00:48:36 -05:00
final class RefreshAltStoreViewController: UIViewController {
var context: AuthenticatedOperationContext!
2023-03-01 00:48:36 -05:00
var completionHandler: ((Result<Void, Error>) -> Void)?
2023-03-01 00:48:36 -05:00
@IBOutlet private var placeholderView: RSTPlaceholderView!
2023-03-01 00:48:36 -05:00
override func viewDidLoad() {
super.viewDidLoad()
2023-03-01 00:48:36 -05:00
placeholderView.textLabel.isHidden = true
placeholderView.detailTextLabel.textAlignment = .left
placeholderView.detailTextLabel.textColor = UIColor.white.withAlphaComponent(0.6)
placeholderView.detailTextLabel.text = NSLocalizedString("SideStore was unable to use an existing signing certificate, so it had to create a new one. This will cause any apps installed with an existing certificate to expire — including SideStore.\n\nTo prevent SideStore from expiring early, please refresh the app now. SideStore will quit once refreshing is complete.", comment: "")
}
}
2023-03-01 00:48:36 -05:00
private extension RefreshAltStoreViewController {
@IBAction func refreshAltStore(_ sender: PillButton) {
guard let altStore = InstalledApp.fetchAltStore(in: DatabaseManager.shared.viewContext) else { return }
2023-03-01 00:48:36 -05:00
func refresh() {
sender.isIndicatingActivity = true
2023-03-01 00:48:36 -05:00
if let progress = AppManager.shared.installationProgress(for: altStore) {
// Cancel pending AltStore installation so we can start a new one.
progress.cancel()
}
2023-03-01 00:48:36 -05:00
// Install, _not_ refresh, to ensure we are installing with a non-revoked certificate.
2023-03-01 00:48:36 -05:00
let group = AppManager.shared.install(altStore, presentingViewController: self, context: context) { result in
switch result {
case .success: self.completionHandler?(.success(()))
2023-03-01 00:48:36 -05:00
case let .failure(error as NSError):
DispatchQueue.main.async {
sender.progress = nil
sender.isIndicatingActivity = false
2023-03-01 00:48:36 -05:00
let alertController = UIAlertController(title: NSLocalizedString("Failed to Refresh SideStore", comment: ""), message: error.localizedFailureReason ?? error.localizedDescription, preferredStyle: .alert)
2023-03-01 00:48:36 -05:00
alertController.addAction(UIAlertAction(title: NSLocalizedString("Try Again", comment: ""), style: .default, handler: { _ in
refresh()
}))
2023-03-01 00:48:36 -05:00
alertController.addAction(UIAlertAction(title: NSLocalizedString("Refresh Later", comment: ""), style: .cancel, handler: { _ in
self.completionHandler?(.failure(error))
}))
2023-03-01 00:48:36 -05:00
self.present(alertController, animated: true, completion: nil)
}
}
}
2023-03-01 00:48:36 -05:00
sender.progress = group.progress
}
2023-03-01 00:48:36 -05:00
refresh()
}
2023-03-01 00:48:36 -05:00
@IBAction func cancel(_: UIButton) {
completionHandler?(.failure(OperationError.cancelled))
}
}