mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-11 11:01:07 +00:00
Show average process for multiple incoming connnections
This commit is contained in:
1 parent
9d1e698d9b
commit
646da767a7
3 files changed
+25
-8
No files matched your search
@@ -17,6 +17,9 @@ import LUI
|
||||
|
||||
class ReceiveModel: ObservableObject, InboundAppDelegate {
|
||||
|
||||
/// For each connection ID, store the last reported progress value
|
||||
private var processes: [String: Double] = [:]
|
||||
|
||||
#if os(macOS)
|
||||
@Published var progress: Double? = nil
|
||||
private var toastWindow: NSWindow?
|
||||
@@ -156,28 +159,42 @@ class ReceiveModel: ObservableObject, InboundAppDelegate {
|
||||
|
||||
func transferProgress(connectionID: String, progress: Double) {
|
||||
|
||||
// Update process dictionary
|
||||
processes[connectionID] = progress
|
||||
|
||||
// Calcualate average value for all ongoing transfers
|
||||
let totalProgress = processes.values.reduce(0, +)
|
||||
let averageProgress = totalProgress / Double(processes.count)
|
||||
|
||||
#if os(iOS)
|
||||
ProgressAlert.shared.updateProgress(progress)
|
||||
ProgressAlert.shared.updateProgress(averageProgress)
|
||||
#else
|
||||
DispatchQueue.main.async {
|
||||
self.progress = progress
|
||||
self.progress = averageProgress
|
||||
self.showQuickDropToast(for: connectionID)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
func connectionWasTerminated(from device: RemoteDeviceInfo, wasPlainTextTransfer: Bool, error: (any Error)?) {
|
||||
func connectionWasTerminated(connectionID: String, from device: RemoteDeviceInfo, wasPlainTextTransfer: Bool, error: (any Error)?) {
|
||||
|
||||
processes.removeValue(forKey: connectionID)
|
||||
|
||||
#if os(macOS)
|
||||
DispatchQueue.main.async {
|
||||
self.hideQuickDropToast()
|
||||
self.progress = nil
|
||||
|
||||
if self.processes.isEmpty {
|
||||
self.progress = nil
|
||||
}
|
||||
}
|
||||
finish()
|
||||
#else
|
||||
ProgressAlert.shared.updateProgress(nil) {
|
||||
finish()
|
||||
if self.processes.isEmpty {
|
||||
ProgressAlert.shared.updateProgress(nil) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user