Show classifier download progress

This commit is contained in:
Christoph Hagen
2023-10-24 14:51:08 +02:00
parent f55f4e65dd
commit d5edf360fb
7 changed files with 147 additions and 18 deletions

View File

@@ -0,0 +1,23 @@
import SwiftUI
struct ClassifierDownloadView: View {
@ObservedObject
var progress: Database.ClassifierProgress
var body: some View {
VStack {
ProgressView("Downloading classifier...", value: progress.bytesLoaded, total: Double(progress.total))
.progressViewStyle(.linear)
HStack {
Text(String(format: "%.0f %%", progress.percentage))
Spacer()
Text(String(format: "%.1f / %.1f MB", progress.bytesLoaded / 1_000_000, progress.total / 1_000_000 ))
}
}
}
}
#Preview {
ClassifierDownloadView(progress: .init(bytesLoaded: 12_300_000, total: 24_500_000))
}

View File

@@ -42,8 +42,28 @@ struct SettingsView: View {
.foregroundColor(.secondary)
.padding(.top)
Group {
SettingsStatisticRow(label: "Version", value: "\(database.classifierVersion)")
SettingsStatisticRow(label: "Server Version", value: "\(database.serverClassifierVersion)")
SettingsStatisticRow(label: "Local Version", value: "\(database.localClassifierVersion)")
SettingsStatisticRow(label: "Recognized caps", value: "\(database.classifierClassCount)")
HStack {
Spacer()
Button(action: updateClassifierVersion) {
Label("Refresh", systemSymbol: .arrowCounterclockwise)
}
.disabled(database.classifierDownloadProgress != nil)
.padding()
if database.localClassifierVersion != database.serverClassifierVersion {
Button(action: downloadNewClassifier) {
Label("Download", systemSymbol: .squareAndArrowDown)
}
.disabled(database.classifierDownloadProgress != nil)
.padding()
}
Spacer()
}
if let progress = database.classifierDownloadProgress {
ClassifierDownloadView(progress: progress)
}
}.padding(.horizontal)
Text("Storage")
.font(.footnote)
@@ -56,7 +76,9 @@ struct SettingsView: View {
SettingsStatisticRow(label: "Classifier", value: byteString(database.classifierSize))
HStack {
Spacer()
Button("Clear image cache", action: clearImageCache)
Button(action: clearImageCache) {
Label("Clear image cache", systemSymbol: .trash)
}
.padding()
Spacer()
}
@@ -82,6 +104,20 @@ struct SettingsView: View {
}
}
private func downloadNewClassifier() {
Task {
// Ensure that correct version is saved
await database.updateServerClassifierVersion()
await database.downloadClassifier()
}
}
private func updateClassifierVersion() {
Task {
await database.updateServerClassifierVersion()
}
}
private func hide() {
isPresented = false
}