Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PlayTools icon not updating #809

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -483,6 +483,7 @@ struct MiscView: View {
}

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