Show classifier download progress
This commit is contained in:
23
Caps/Views/ClassifierDownloadView.swift
Normal file
23
Caps/Views/ClassifierDownloadView.swift
Normal 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))
|
||||
}
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user