diff --git a/Applite/Model/Preferences/Preferences.swift b/Applite/Model/Preferences/Preferences.swift index 6be23fd..b259531 100644 --- a/Applite/Model/Preferences/Preferences.swift +++ b/Applite/Model/Preferences/Preferences.swift @@ -27,4 +27,9 @@ enum Preferences: String { // Proxy case networkProxyEnabled case preferredProxyType + + // Sorting options + case searchSortOption + case hideUnpopularApps + case hideDisabledApps } diff --git a/Applite/Views/Content View/ContentView+SearchFunctions.swift b/Applite/Views/Content View/ContentView+SearchFunctions.swift index 40ddb38..0a2f06b 100644 --- a/Applite/Views/Content View/ContentView+SearchFunctions.swift +++ b/Applite/Views/Content View/ContentView+SearchFunctions.swift @@ -11,6 +11,7 @@ extension ContentView { func searchAndSort() async { await caskManager.allCasks.search(query: searchInput, diffScroreThreshold: 0.3, limitResults: 25) if hideUnpopularApps { await filterUnpopular() } + if hideDisabledApps { await filterDisabled() } await sortCasks(ignoreBestMatch: true) } @@ -20,6 +21,12 @@ extension ContentView { } } + func filterDisabled() async { + caskManager.allCasks.filterSearch { casks in + casks.filter { !($0.info.warning?.isDisabled ?? false) } + } + } + func sortCasks(ignoreBestMatch: Bool) async { switch sortBy { case .bestMatch: diff --git a/Applite/Views/Content View/ContentView.swift b/Applite/Views/Content View/ContentView.swift index 2e8bc22..6751bc0 100755 --- a/Applite/Views/Content View/ContentView.swift +++ b/Applite/Views/Content View/ContentView.swift @@ -27,8 +27,9 @@ struct ContentView: View { @State var showSearchResults = false // Sorting options - @AppStorage("searchSortOption") var sortBy = SortingOptions.mostDownloaded - @AppStorage("hideUnpopularApps") var hideUnpopularApps = false + @AppStorage(Preferences.searchSortOption.rawValue) var sortBy = SortingOptions.mostDownloaded + @AppStorage(Preferences.hideUnpopularApps.rawValue) var hideUnpopularApps = false + @AppStorage(Preferences.hideDisabledApps.rawValue) var hideDisabledApps = false let logger = Logger() @@ -81,6 +82,13 @@ struct ContentView: View { await caskManager.allCasks.search(query: searchInput) } } + .task(id: hideDisabledApps) { + if hideDisabledApps { + await filterDisabled() + } else { + await caskManager.allCasks.search(query: searchInput) + } + } // Load failure alert .alert(loadAlert.title, isPresented: $loadAlert.isPresented) { AsyncButton { diff --git a/Applite/Views/Detail Views/Home/HomeView+NoSearchResults.swift b/Applite/Views/Detail Views/Home/HomeView+NoSearchResults.swift index 2a740b6..229c518 100644 --- a/Applite/Views/Detail Views/Home/HomeView+NoSearchResults.swift +++ b/Applite/Views/Detail Views/Home/HomeView+NoSearchResults.swift @@ -10,7 +10,7 @@ import SwiftUI extension HomeView { struct NoSearchResults: View { @Binding var searchText: String - @AppStorage("hideUnpopularApps") var hideUnpopularApps = false + @AppStorage(Preferences.hideUnpopularApps.rawValue) var hideUnpopularApps = false var body: some View { VStack { diff --git a/Applite/Views/Detail Views/Home/HomeView+SortingOptions.swift b/Applite/Views/Detail Views/Home/HomeView+SortingOptions.swift index c105797..f853eac 100644 --- a/Applite/Views/Detail Views/Home/HomeView+SortingOptions.swift +++ b/Applite/Views/Detail Views/Home/HomeView+SortingOptions.swift @@ -10,8 +10,9 @@ import SwiftUI extension HomeView { struct SortingOptionsToolbar: ToolbarContent { // Sorting options - @AppStorage("searchSortOption") var sortBy = SortingOptions.mostDownloaded - @AppStorage("hideUnpopularApps") var hideUnpopularApps = false + @AppStorage(Preferences.searchSortOption.rawValue) var sortBy = SortingOptions.mostDownloaded + @AppStorage(Preferences.hideUnpopularApps.rawValue) var hideUnpopularApps = false + @AppStorage(Preferences.hideDisabledApps.rawValue) var hideDisabledApps = false var body: some ToolbarContent { ToolbarItem { @@ -27,6 +28,10 @@ extension HomeView { Toggle(isOn: $hideUnpopularApps) { Text("Hide apps with few downloads", comment: "Few downloads search filter") } + + Toggle(isOn: $hideDisabledApps) { + Text("Hide disabled apps", comment: "Disabled apps search filter") + } } label: { Label("Search Sorting Options", systemImage: "slider.horizontal.3") .labelStyle(.titleAndIcon) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index d436a9b..e49776f 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -2745,6 +2745,17 @@ } } }, + "Hide disabled apps" : { + "comment" : "Disabled apps search filter", + "localizations" : { + "hu" : { + "stringUnit" : { + "state" : "translated", + "value" : "Letiltott alkalmazások elrejtése" + } + } + } + }, "Homebrew" : { "comment" : "Sidebar item", "localizations" : {