2019-10-28 13:16:55 -07:00
//
// R e f r e s h A l t S t o r e V i e w C o n t r o l l e r . s w i f t
// A l t S t o r e
//
// C r e a t e d b y R i l e y T e s t u t o n 1 0 / 2 6 / 1 9 .
// C o p y r i g h t © 2 0 1 9 R i l e y T e s t u t . A l l r i g h t s r e s e r v e d .
//
import UIKit
2020-09-03 16:39:08 -07:00
import AltStoreCore
import AltSign
2019-10-28 13:16:55 -07:00
import Roxas
2023-01-04 09:52:12 -05:00
final class RefreshAltStoreViewController : UIViewController
2019-10-28 13:16:55 -07:00
{
2020-03-06 17:08:35 -08:00
var context : AuthenticatedOperationContext !
2019-10-28 13:16:55 -07:00
var completionHandler : ( ( Result < Void , Error > ) -> Void ) ?
@IBOutlet private var placeholderView : RSTPlaceholderView !
override func viewDidLoad ( )
{
super . viewDidLoad ( )
self . placeholderView . textLabel . isHidden = true
self . placeholderView . detailTextLabel . textAlignment = . left
self . placeholderView . detailTextLabel . textColor = UIColor . white . withAlphaComponent ( 0.6 )
2022-11-05 23:50:07 -07:00
self . 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 \n To prevent SideStore from expiring early, please refresh the app now. SideStore will quit once refreshing is complete. " , comment : " " )
2019-10-28 13:16:55 -07:00
}
}
private extension RefreshAltStoreViewController
{
@IBAction func refreshAltStore ( _ sender : PillButton )
{
guard let altStore = InstalledApp . fetchAltStore ( in : DatabaseManager . shared . viewContext ) else { return }
func refresh ( )
{
sender . isIndicatingActivity = true
2020-03-06 17:08:35 -08:00
if let progress = AppManager . shared . installationProgress ( for : altStore )
2019-10-28 13:16:55 -07:00
{
2020-03-06 17:08:35 -08:00
// C a n c e l p e n d i n g A l t S t o r e i n s t a l l a t i o n s o w e c a n s t a r t a n e w o n e .
2019-10-28 13:16:55 -07:00
progress . cancel ( )
}
2020-03-06 17:08:35 -08:00
// I n s t a l l , _ n o t _ r e f r e s h , t o e n s u r e w e a r e i n s t a l l i n g w i t h a n o n - r e v o k e d c e r t i f i c a t e .
2021-10-25 22:27:30 -07:00
let group = AppManager . shared . install ( altStore , presentingViewController : self , context : self . context ) { ( result ) in
2020-03-06 17:08:35 -08:00
switch result
2019-10-28 13:16:55 -07:00
{
2020-03-06 17:08:35 -08:00
case . success : self . completionHandler ? ( . success ( ( ) ) )
2020-03-30 15:23:20 -07:00
case . failure ( let error as NSError ) :
2019-10-28 13:16:55 -07:00
DispatchQueue . main . async {
sender . progress = nil
sender . isIndicatingActivity = false
2022-11-05 23:50:07 -07:00
let alertController = UIAlertController ( title : NSLocalizedString ( " Failed to Refresh SideStore " , comment : " " ) , message : error . localizedFailureReason ? ? error . localizedDescription , preferredStyle : . alert )
2019-10-28 13:16:55 -07:00
alertController . addAction ( UIAlertAction ( title : NSLocalizedString ( " Try Again " , comment : " " ) , style : . default , handler : { ( action ) in
refresh ( )
} ) )
alertController . addAction ( UIAlertAction ( title : NSLocalizedString ( " Refresh Later " , comment : " " ) , style : . cancel , handler : { ( action ) in
self . completionHandler ? ( . failure ( error ) )
} ) )
self . present ( alertController , animated : true , completion : nil )
}
}
}
2021-10-25 22:27:30 -07:00
sender . progress = group . progress
2019-10-28 13:16:55 -07:00
}
refresh ( )
}
@IBAction func cancel ( _ sender : UIButton )
{
self . completionHandler ? ( . failure ( OperationError . cancelled ) )
}
}