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
import AltSign
import Roxas
class RefreshAltStoreViewController : UIViewController
{
var signer : ALTSigner !
2019-11-18 14:49:17 -08:00
var session : ALTAppleAPISession !
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 )
self . placeholderView . detailTextLabel . text = NSLocalizedString ( " AltStore 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 AltStore. \n \n To prevent AltStore from expiring early, please refresh the app now. AltStore will quit once refreshing is complete. " , comment : " " )
}
}
private extension RefreshAltStoreViewController
{
@IBAction func refreshAltStore ( _ sender : PillButton )
{
guard let altStore = InstalledApp . fetchAltStore ( in : DatabaseManager . shared . viewContext ) else { return }
func refresh ( )
{
sender . isIndicatingActivity = true
if let progress = AppManager . shared . refreshProgress ( for : altStore ) ? ? AppManager . shared . installationProgress ( for : altStore )
{
// C a n c e l p e n d i n g A l t S t o r e r e f r e s h s o w e c a n s t a r t a n e w o n e .
progress . cancel ( )
}
let group = OperationGroup ( )
group . signer = self . signer // P r e v e n t u s f r o m t r y i n g t o a u t h e n t i c a t e a s e c o n d t i m e .
2019-11-18 14:49:17 -08:00
group . session = self . session // ^
2019-10-28 13:16:55 -07:00
group . completionHandler = { ( result ) in
if let error = result . error ? ? result . value ? . values . compactMap ( { $0 . error } ) . first
{
DispatchQueue . main . async {
sender . progress = nil
sender . isIndicatingActivity = false
let alertController = UIAlertController ( title : NSLocalizedString ( " Failed to Refresh AltStore " , comment : " " ) , message : error . localizedDescription , preferredStyle : . alert )
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 )
}
}
else
{
self . completionHandler ? ( . success ( ( ) ) )
}
}
_ = AppManager . shared . refresh ( [ altStore ] , presentingViewController : self , group : group )
sender . progress = group . progress
}
refresh ( )
}
@IBAction func cancel ( _ sender : UIButton )
{
self . completionHandler ? ( . failure ( OperationError . cancelled ) )
}
}