Skip to content

Commit

Permalink
Fix PlayTools icon not updating (#809)
Browse files Browse the repository at this point in the history
* fix: playtools icon not updating when removed

* chore: cleanup code
  • Loading branch information
TheMoonThatRises committed Feb 23, 2023
1 parent 7b1416e commit 6426ef7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
28 changes: 10 additions & 18 deletions PlayCover/ViewModel/AppsVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class AppsVM: ObservableObject {
func fetchApps() {
Task { @MainActor in
updatingApps = true
var result: [PlayApp] = []

filteredApps.removeAll()
apps.removeAll()

do {
let containers = try AppContainer.containers()
let directoryContents = try FileManager.default
Expand All @@ -40,31 +43,20 @@ class AppsVM: ObservableObject {
app.container = container
print("Application installed under:", sub.path)
}
result.append(app)
apps.append(app)
if uif.searchText.isEmpty || app.searchText.contains(uif.searchText.lowercased()) {
filteredApps.append(app)
}
}
}

} catch let error as NSError {
print(error)
}

apps = result

updateApps(result)
}
}
filteredApps.sort(by: { $0.name.lowercased() < $1.name.lowercased() })

@MainActor func updateApps(_ newApps: [PlayApp]) {
updatingApps = true
self.filteredApps.removeAll()
var filteredApps = newApps

if !uif.searchText.isEmpty {
filteredApps = newApps.filter({ $0.searchText.contains(uif.searchText.lowercased()) })
updatingApps = false
}

filteredApps.sort(by: { $0.name.lowercased() < $1.name.lowercased() })
self.filteredApps.append(contentsOf: filteredApps)
updatingApps = false
}
}
7 changes: 3 additions & 4 deletions PlayCover/ViewModel/StoreVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ class StoreVM: ObservableObject {

func fetchApps() {
filteredApps.removeAll()
var result = apps
filteredApps = apps
if !uif.searchText.isEmpty {
result = result.filter({
filteredApps = filteredApps.filter({
$0.name.lowercased().contains(uif.searchText.lowercased())
})
}
result.sort(by: { $0.name.lowercased() < $1.name.lowercased() })
filteredApps = result
filteredApps.sort(by: { $0.name.lowercased() < $1.name.lowercased() })
}

func resolveSources() {
Expand Down
1 change: 1 addition & 0 deletions PlayCover/Views/AppSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ struct MiscView: View {
}

Task { @MainActor in
AppsVM.shared.filteredApps = []
AppsVM.shared.fetchApps()
}
}
Expand Down

0 comments on commit 6426ef7

Please sign in to comment.