diff --git a/damus.xcodeproj/xcshareddata/xcschemes/DamusNotificationService.xcscheme b/damus.xcodeproj/xcshareddata/xcschemes/DamusNotificationService.xcscheme index d2f574995..4c06fd6b8 100644 --- a/damus.xcodeproj/xcshareddata/xcschemes/DamusNotificationService.xcscheme +++ b/damus.xcodeproj/xcshareddata/xcschemes/DamusNotificationService.xcscheme @@ -77,6 +77,7 @@ savedToolIdentifier = "" useCustomWorkingDirectory = "NO" debugDocumentVersioning = "YES" + askForAppToLaunch = "Yes" launchAutomaticallySubstyle = "2"> diff --git a/damus/Models/ImageUploadModel.swift b/damus/Models/ImageUploadModel.swift index 7e556a683..0d4cdedaa 100644 --- a/damus/Models/ImageUploadModel.swift +++ b/damus/Models/ImageUploadModel.swift @@ -53,12 +53,15 @@ enum MediaUpload { class ImageUploadModel: NSObject, URLSessionTaskDelegate, ObservableObject { @Published var progress: Double? = nil + @Published var currentImagesUploaded: Int = 0 + @Published var totalImagesToUpload: Int = 0 + private var completedUploads: Int = 0 func start(media: MediaUpload, uploader: MediaUploader, keypair: Keypair? = nil) async -> ImageUploadResult { - let res = await create_upload_request(mediaToUpload: media, mediaUploader: uploader, progress: self, keypair: keypair) DispatchQueue.main.async { - self.progress = nil + self.totalImagesToUpload += 1 } + let res = await create_upload_request(mediaToUpload: media, mediaUploader: uploader, progress: self, keypair: keypair) return res } @@ -67,4 +70,20 @@ class ImageUploadModel: NSObject, URLSessionTaskDelegate, ObservableObject { self.progress = Double(totalBytesSent) / Double(totalBytesExpectedToSend) } } + + func didFinishUpload() { + DispatchQueue.main.async { + self.completedUploads += 1 + self.currentImagesUploaded = self.completedUploads + } + } + + func resetProgress() { + DispatchQueue.main.async { + self.progress = nil + self.currentImagesUploaded = 0 + self.totalImagesToUpload = 0 + self.completedUploads = 0 + } + } } diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift index 7450dd5a5..86d465881 100644 --- a/damus/Views/PostView.swift +++ b/damus/Views/PostView.swift @@ -285,8 +285,11 @@ struct PostView: View { } if let progress = image_upload.progress { - ProgressView(value: progress, total: 1.0) - .progressViewStyle(.linear) + HStack { + ProgressView(value: progress, total: 1.0) + .progressViewStyle(.linear) + Text("\(image_upload.currentImagesUploaded)/\(image_upload.totalImagesToUpload)") + } } Divider() @@ -316,6 +319,7 @@ struct PostView: View { let meta = blurhash.map { bh in calculate_image_metadata(url: url, img: img, blurhash: bh) } let uploadedMedia = UploadedMedia(localURL: media.localURL, uploadedURL: url, representingImage: img, metadata: meta) uploadedMedias.append(uploadedMedia) + image_upload.didFinishUpload() case .failed(let error): if let error { @@ -325,6 +329,9 @@ struct PostView: View { } } + if (image_upload.currentImagesUploaded + 1) == image_upload.totalImagesToUpload { + image_upload.resetProgress() + } } }