Skip to content

Commit

Permalink
Show the downloading progress in Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
buh committed Oct 2, 2023
1 parent 0d66315 commit 388a86b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Demo/Hubble/ImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct ImageView: View {
@State private var dataImage: XImage?
@State private var size = ""
@State private var error: String?
@State private var progress: Double = 0

var body: some View {
ZStack {
Expand Down Expand Up @@ -50,17 +51,27 @@ struct ImageView: View {
.symbolRenderingMode(.multicolor)
.padding(.horizontal)
} else {
ProgressView()
.progressViewStyle(.circular)
ProgressView(value: progress)
.padding(.horizontal)
}
}
.navigationTitle(entry?.title ?? "")
.task { @MainActor in
guard let entry, let url else { return }

do {
let data = try await URLSession(configuration: .ephemeral).zipEntryData(entry, from: url)
size = ByteCountFormatter.appFormatter.string(fromByteCount: Int64(data.count))
let data = try await URLSession(configuration: .ephemeral)
.zipEntryData(
entry,
from: url,
progress: .init(bufferSize: 0x1ffff) { progressValue in
Task { @MainActor in
self.progress = progressValue
}
}
)

size = ByteCountFormatter.appFormatter.string(fromByteCount: entry.uncompressedSize)
#if os(macOS)
dataImage = NSImage(data: data)
#else
Expand All @@ -69,7 +80,7 @@ struct ImageView: View {

} catch {
self.error = error.localizedDescription
print("💥 Image:", error)
print("💥 ImageView:", error)
}
}
}
Expand Down

0 comments on commit 388a86b

Please sign in to comment.