diff --git a/Caps/Data/Database.swift b/Caps/Data/Database.swift index 576dae4..4883695 100644 --- a/Caps/Data/Database.swift +++ b/Caps/Data/Database.swift @@ -713,7 +713,7 @@ final class Database: ObservableObject { return caps.values.filter { $0.classifiable(by: version) }.count } - var imageCacheSize: Int { + func imageCacheSize() async -> Int { fm.directorySize(images.folder) } diff --git a/Caps/Views/SettingsView.swift b/Caps/Views/SettingsView.swift index b7b4df8..37161ab 100644 --- a/Caps/Views/SettingsView.swift +++ b/Caps/Views/SettingsView.swift @@ -12,6 +12,9 @@ struct SettingsView: View { @AppStorage("authKey") private var serverAuthenticationKey: String = "" + @State + private var imageCacheSize: Int = 0 + var body: some View { NavigationView { VStack(alignment: .leading, spacing: 3) { @@ -48,7 +51,7 @@ struct SettingsView: View { .foregroundColor(.secondary) .padding(.top) Group { - SettingsStatisticRow(label: "Image cache", value: byteString(database.imageCacheSize)) + SettingsStatisticRow(label: "Image cache", value: byteString(imageCacheSize)) SettingsStatisticRow(label: "Database", value: byteString(database.databaseSize)) SettingsStatisticRow(label: "Classifier", value: byteString(database.classifierSize)) }.padding(.horizontal) @@ -56,6 +59,13 @@ struct SettingsView: View { } .padding(.horizontal) .navigationTitle("Settings") + .onAppear(perform: updateImageCacheSize) + } + } + + private func updateImageCacheSize() { + Task { + imageCacheSize = await database.imageCacheSize() } }