@@ -22,7 +22,7 @@ struct AppSearchView: View {
22
22
@Binding var showPopover : Bool
23
23
@State private var showMenu = false
24
24
@Binding var isMenuBar : Bool
25
- @AppStorage ( " settings.general.selectedSortAppsList " ) var selectedSortAlpha : Bool = true
25
+ @AppStorage ( " settings.general.selectedSortAppsList " ) var selectedSortOption : SortOption = . alphabetical
26
26
@AppStorage ( " settings.interface.animationEnabled " ) private var animationEnabled : Bool = true
27
27
28
28
@@ -81,10 +81,10 @@ struct AppSearchView: View {
81
81
. buttonStyle ( SimpleButtonStyle ( icon: " arrow.counterclockwise.circle " , help: " Refresh apps (⌘+R) " , size: 16 ) )
82
82
}
83
83
84
- SearchBar ( search: $search, darker: ( mini || menubarEnabled) ? false : true , glass: glass)
84
+ SearchBar ( search: $search, darker: ( mini || menubarEnabled) ? false : true , glass: glass, sidebar : false )
85
85
86
86
87
- if search. isEmpty {
87
+ if search. isEmpty && ( mini || menubarEnabled ) {
88
88
Button ( " More " ) {
89
89
self . showMenu. toggle ( )
90
90
}
@@ -94,10 +94,19 @@ struct AppSearchView: View {
94
94
95
95
Button ( " " ) {
96
96
withAnimation ( Animation . easeInOut ( duration: animationEnabled ? 0.35 : 0 ) ) {
97
- selectedSortAlpha. toggle ( )
97
+ // Cycle through all enum cases using `CaseIterable`
98
+ if let nextSortOption = SortOption ( rawValue: selectedSortOption. rawValue + 1 ) {
99
+ selectedSortOption = nextSortOption
100
+ showPopover = false
101
+ showMenu = false
102
+ } else {
103
+ selectedSortOption = . alphabetical
104
+ showPopover = false
105
+ showMenu = false
106
+ }
98
107
}
99
108
}
100
- . buttonStyle ( SimpleButtonStyle ( icon: " circle.fill " , label: " Sorting: \( selectedSortAlpha ? " Name " : " Size " ) " , help: " Sort app list alphabetically by name or by size " , size: 5 ) )
109
+ . buttonStyle ( SimpleButtonStyle ( icon: " circle.fill " , label: " Sorting: \( selectedSortOption . title ) " , help: " Sort app list alphabetically by name or by size " , size: 5 ) )
101
110
102
111
if mini && !menubarEnabled {
103
112
Button ( " " ) {
@@ -149,15 +158,48 @@ struct AppSearchView: View {
149
158
Button ( " Quit " ) {
150
159
NSApp . terminate ( nil )
151
160
}
152
- . buttonStyle ( SimpleButtonStyle ( icon: " circle.fill " , label: " Quit Pearcleaner " , help: " Quit Pearcleaner " , size: 5 ) )
161
+ . buttonStyle ( SimpleButtonStyle ( icon: " circle.fill " , label: " Quit " , help: " Quit Pearcleaner " , size: 5 ) )
153
162
}
154
163
155
164
}
156
165
. padding ( )
157
166
. background ( backgroundView ( themeManager: themeManager, glass: glass) . padding ( - 80 ) )
158
- . frame ( width: 150 )
167
+ // .frame(width: 200)
168
+
169
+ }
170
+ } else if search. isEmpty && ( !mini || !menubarEnabled) {
171
+
172
+ Button ( " " ) {
173
+ withAnimation ( Animation . easeInOut ( duration: animationEnabled ? 0.35 : 0 ) ) {
174
+ showMenu. toggle ( )
175
+ }
176
+ }
177
+ . buttonStyle ( SimpleButtonStyle ( icon: " line.3.horizontal.decrease.circle " , help: selectedSortOption. title, size: 16 ) )
178
+ . popover ( isPresented: $showMenu, arrowEdge: . bottom) {
179
+ VStack ( alignment: . leading, spacing: 10 ) {
180
+ HStack {
181
+ Spacer ( )
182
+ Text ( " Sorting Options " ) . font ( . subheadline) . foregroundStyle ( . secondary)
183
+ Spacer ( )
184
+ }
185
+ Divider ( )
186
+ ForEach ( SortOption . allCases) { option in
187
+ Button ( " " ) {
188
+ withAnimation ( Animation . easeInOut ( duration: animationEnabled ? 0.35 : 0 ) ) {
189
+ selectedSortOption = option
190
+ showMenu = false
191
+ }
192
+ }
193
+ . buttonStyle ( SimpleButtonStyle ( icon: selectedSortOption == option ? " circle.inset.filled " : " circle " , label: option. title, help: " " , size: 5 ) )
194
+
159
195
196
+ }
197
+ }
198
+ . padding ( )
199
+ . background ( backgroundView ( themeManager: themeManager, glass: glass) . padding ( - 80 ) )
200
+ // .frame(width: 160)
160
201
}
202
+
161
203
}
162
204
163
205
@@ -174,12 +216,28 @@ struct AppSearchView: View {
174
216
apps = appState. sortedApps. filter { $0. appName. localizedCaseInsensitiveContains ( search) }
175
217
}
176
218
177
- switch selectedSortAlpha {
178
- case true :
179
- return apps. sorted { $0. appName. replacingOccurrences ( of: " . " , with: " " ) . lowercased ( ) < $1. appName. replacingOccurrences ( of: " . " , with: " " ) . lowercased ( ) }
180
- case false :
219
+ // Sort based on the selected option
220
+ switch selectedSortOption {
221
+ case . alphabetical:
222
+ return apps. sorted {
223
+ $0. appName. replacingOccurrences ( of: " . " , with: " " ) . lowercased ( ) < $1. appName. replacingOccurrences ( of: " . " , with: " " ) . lowercased ( )
224
+ }
225
+ case . size:
181
226
return apps. sorted { $0. bundleSize > $1. bundleSize }
227
+ case . creationDate:
228
+ return apps. sorted { ( $0. creationDate ?? Date . distantPast) > ( $1. creationDate ?? Date . distantPast) }
229
+ case . contentChangeDate:
230
+ return apps. sorted { ( $0. contentChangeDate ?? Date . distantPast) > ( $1. contentChangeDate ?? Date . distantPast) }
231
+ case . lastUsedDate:
232
+ return apps. sorted { ( $0. lastUsedDate ?? Date . distantPast) > ( $1. lastUsedDate ?? Date . distantPast) }
182
233
}
234
+
235
+ // switch selectedSortAlpha {
236
+ // case true:
237
+ // return apps.sorted { $0.appName.replacingOccurrences(of: ".", with: "").lowercased() < $1.appName.replacingOccurrences(of: ".", with: "").lowercased() }
238
+ // case false:
239
+ // return apps.sorted { $0.bundleSize > $1.bundleSize }
240
+ // }
183
241
}
184
242
185
243
}
@@ -218,7 +276,7 @@ struct SimpleSearchStyle: TextFieldStyle {
218
276
Spacer ( )
219
277
Text ( isFocused ? " Type to search " : " Click to search " )
220
278
. font ( . subheadline)
221
- . foregroundColor ( . primary . opacity ( 0.2 ) )
279
+ . foregroundColor ( . secondary )
222
280
Spacer ( )
223
281
}
224
282
}
0 commit comments