mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Supports updating apps from AppViewController
Unlike MyAppsViewController, AppViewController will attempt to update to the latest available version, rather than the latest supported version. If the latest version is not supported, it will fall back to asking user to install last supported version.
This commit is contained in:
@@ -371,13 +371,20 @@ private extension AppViewController
|
||||
button.tintColor = self.app.tintColor
|
||||
button.isIndicatingActivity = false
|
||||
|
||||
if self.app.installedApp == nil
|
||||
if let installedApp = self.app.installedApp
|
||||
{
|
||||
button.setTitle(NSLocalizedString("FREE", comment: ""), for: .normal)
|
||||
if let latestVersion = self.app.latestAvailableVersion, installedApp.version != latestVersion.version
|
||||
{
|
||||
button.setTitle(NSLocalizedString("UPDATE", comment: ""), for: .normal)
|
||||
}
|
||||
else
|
||||
{
|
||||
button.setTitle(NSLocalizedString("OPEN", comment: ""), for: .normal)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
button.setTitle(NSLocalizedString("OPEN", comment: ""), for: .normal)
|
||||
button.setTitle(NSLocalizedString("FREE", comment: ""), for: .normal)
|
||||
}
|
||||
|
||||
let progress = AppManager.shared.installationProgress(for: self.app)
|
||||
@@ -486,7 +493,14 @@ extension AppViewController
|
||||
{
|
||||
if let installedApp = self.app.installedApp
|
||||
{
|
||||
self.open(installedApp)
|
||||
if let latestVersion = self.app.latestAvailableVersion, installedApp.version != latestVersion.version
|
||||
{
|
||||
self.updateApp(installedApp)
|
||||
}
|
||||
else
|
||||
{
|
||||
self.open(installedApp)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -531,6 +545,34 @@ extension AppViewController
|
||||
{
|
||||
UIApplication.shared.open(installedApp.openAppURL)
|
||||
}
|
||||
|
||||
func updateApp(_ installedApp: InstalledApp)
|
||||
{
|
||||
let previousProgress = AppManager.shared.installationProgress(for: installedApp)
|
||||
guard previousProgress == nil else {
|
||||
//TODO: Handle cancellation
|
||||
//previousProgress?.cancel()
|
||||
return
|
||||
}
|
||||
|
||||
_ = AppManager.shared.update(installedApp, to: .latestAvailableVersionWithFallback, presentingViewController: self) { (result) in
|
||||
DispatchQueue.main.async {
|
||||
switch result
|
||||
{
|
||||
case .success: print("Updated app from AppViewController:", installedApp.bundleIdentifier)
|
||||
case .failure(OperationError.cancelled): break
|
||||
case .failure(let error):
|
||||
let toastView = ToastView(error: error)
|
||||
toastView.opensErrorLog = true
|
||||
toastView.show(in: self)
|
||||
}
|
||||
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppViewController
|
||||
|
||||
Reference in New Issue
Block a user