[ADD] Refresh all apps functionality in MyAppsView

This commit is contained in:
Fabian Thies
2023-02-19 14:25:13 +01:00
parent a95d8a502c
commit bc2cae46a8
2 changed files with 14 additions and 8 deletions

View File

@@ -75,7 +75,7 @@ struct AppPillButton: View {
}
func refreshApp(_ installedApp: InstalledApp) {
AppManager.shared.refresh([installedApp], presentingViewController: nil)
}
func installApp(_ storeApp: StoreApp) {

View File

@@ -38,7 +38,7 @@ struct MyAppsView: View {
var viewModel = MyAppsViewModel()
// TODO: Refactor
@State var isShowingFilePicker: Bool = false
@State var isRefreshingAllApps: Bool = false
@State var selectedSideloadingIpaURL: URL?
@State var isShowingAppIDsView: Bool = false
@@ -89,11 +89,14 @@ struct MyAppsView: View {
Text(L10n.MyAppsView.active)
.font(.title2)
.bold()
Spacer()
SwiftUI.Button {
} label: {
Text(L10n.MyAppsView.refreshAll)
if !self.isRefreshingAllApps {
SwiftUI.Button(L10n.MyAppsView.refreshAll, action: self.refreshAllApps)
} else {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
}
}
@@ -206,7 +209,10 @@ struct MyAppsView: View {
func refreshAllApps() {
let installedApps = InstalledApp.fetchAppsForRefreshingAll(in: DatabaseManager.shared.viewContext)
self.refresh(installedApps) { result in }
self.isRefreshingAllApps = true
self.refresh(installedApps) { result in
self.isRefreshingAllApps = false
}
}
func dismissUpdatesHint(forever: Bool) {
@@ -218,7 +224,7 @@ struct MyAppsView: View {
extension MyAppsView {
// TODO: Convert to async
// TODO: Convert to async?
func refresh(_ apps: [InstalledApp], completionHandler: @escaping ([String : Result<InstalledApp, Error>]) -> Void) {
let group = AppManager.shared.refresh(apps, presentingViewController: nil, group: self.viewModel.refreshGroup)
@@ -248,10 +254,10 @@ extension MyAppsView {
NotificationManager.shared.showNotification(title: title, detailText: message)
}
}
self.viewModel.refreshGroup = nil
completionHandler(results)
}
}
self.viewModel.refreshGroup = group