Skip to content

Commit

Permalink
Add disabled apps sorting option
Browse files Browse the repository at this point in the history
  • Loading branch information
milanvarady committed Jan 24, 2025
1 parent 65e91dd commit f1795c3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Applite/Model/Preferences/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ enum Preferences: String {
// Proxy
case networkProxyEnabled
case preferredProxyType

// Sorting options
case searchSortOption
case hideUnpopularApps
case hideDisabledApps
}
7 changes: 7 additions & 0 deletions Applite/Views/Content View/ContentView+SearchFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions Applite/Views/Content View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions Applite/Views/Detail Views/Home/HomeView+SortingOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down

0 comments on commit f1795c3

Please sign in to comment.