@@ -10,7 +10,7 @@ import SwiftUI
1010struct SettingsView : View {
1111 @AppStorage ( " hf_auth_token " ) private var authToken = " "
1212 @AppStorage ( " auto_quantize " ) private var autoQuantize = false
13- @AppStorage ( " default_quantization " ) private var defaultQuantization = " Q4_K_M "
13+ @AppStorage ( " default_quantization " ) private var defaultQuantization = QuantizationType . q4_1 . rawValue
1414 @AppStorage ( " save_history " ) private var saveHistory = true
1515 @AppStorage ( " wifi_only " ) private var wifiOnly = true
1616
@@ -151,13 +151,9 @@ struct SettingsView: View {
151151 . foregroundStyle ( . white)
152152
153153 Picker ( " Quantization " , selection: $defaultQuantization) {
154- Text ( " Q2_K (2-bit) " ) . tag ( " Q2_K " )
155- Text ( " Q3_K_M (3-bit) " ) . tag ( " Q3_K_M " )
156- Text ( " Q4_K_M (4-bit) " ) . tag ( " Q4_K_M " )
157- Text ( " Q5_K_M (5-bit) " ) . tag ( " Q5_K_M " )
158- Text ( " Q6_K (6-bit) " ) . tag ( " Q6_K " )
159- Text ( " Q8_0 (8-bit) " ) . tag ( " Q8_0 " )
160- Text ( " FP16 (16-bit) " ) . tag ( " FP16 " )
154+ ForEach ( QuantizationType . onDeviceSupportedCases, id: \. self) { quantType in
155+ Text ( quantType. description) . tag ( quantType. rawValue)
156+ }
161157 }
162158 . pickerStyle ( MenuPickerStyle ( ) )
163159 . foregroundStyle ( . white)
@@ -231,7 +227,7 @@ struct SettingsView: View {
231227
232228 Spacer ( )
233229
234- Text ( " 1.0.0 " )
230+ Text ( appVersion )
235231 . font ( . system( size: 14 , weight: . semibold) )
236232 . foregroundStyle ( . white. opacity ( 0.7 ) )
237233 }
@@ -279,6 +275,7 @@ struct SettingsView: View {
279275 guard let docs = fileManager. urls ( for: . documentDirectory, in: . userDomainMask) . first else { return }
280276
281277 let tempDir = docs. appendingPathComponent ( " Temp " )
278+ let downloadDir = docs. appendingPathComponent ( " DownloadedModels " )
282279
283280 do {
284281 let contents = try fileManager. contentsOfDirectory ( at: tempDir, includingPropertiesForKeys: [ . fileSizeKey] )
@@ -287,6 +284,15 @@ struct SettingsView: View {
287284 let attrs = try fileManager. attributesOfItem ( atPath: url. path)
288285 totalSize += attrs [ . size] as? Int64 ?? 0
289286 }
287+
288+ if let enumerator = fileManager. enumerator ( at: downloadDir, includingPropertiesForKeys: [ . isRegularFileKey, . fileSizeKey] ) {
289+ for case let fileURL as URL in enumerator {
290+ let values = try fileURL. resourceValues ( forKeys: [ . isRegularFileKey, . fileSizeKey] )
291+ if values. isRegularFile == true {
292+ totalSize += Int64 ( values. fileSize ?? 0 )
293+ }
294+ }
295+ }
290296 cacheSize = totalSize
291297 } catch {
292298 cacheSize = 0
@@ -314,12 +320,15 @@ struct SettingsView: View {
314320
315321 let modelsDir = docs. appendingPathComponent ( " Models " )
316322 let tempDir = docs. appendingPathComponent ( " Temp " )
323+ let downloadDir = docs. appendingPathComponent ( " DownloadedModels " )
317324
318325 do {
319326 try fileManager. removeItem ( at: modelsDir)
320327 try fileManager. removeItem ( at: tempDir)
328+ try fileManager. removeItem ( at: downloadDir)
321329 try fileManager. createDirectory ( at: modelsDir, withIntermediateDirectories: true )
322330 try fileManager. createDirectory ( at: tempDir, withIntermediateDirectories: true )
331+ try fileManager. createDirectory ( at: downloadDir, withIntermediateDirectories: true )
323332
324333 // Clear history
325334 UserDefaults . standard. removeObject ( forKey: " quantizationHistory " )
@@ -335,6 +344,12 @@ struct SettingsView: View {
335344 formatter. countStyle = . binary
336345 return formatter. string ( fromByteCount: bytes)
337346 }
347+
348+ private var appVersion : String {
349+ let version = Bundle . main. infoDictionary ? [ " CFBundleShortVersionString " ] as? String ?? " 1.0 "
350+ let build = Bundle . main. infoDictionary ? [ " CFBundleVersion " ] as? String ?? " 1 "
351+ return " \( version) ( \( build) ) "
352+ }
338353}
339354
340355#Preview {
0 commit comments