Show average process for multiple incoming connnections

This commit is contained in:
Leon Böttger committed 2025-10-19 14:39:25 +02:00
1 parent 9d1e698d9b
commit 646da767a7
3 files changed
+25 -8

No files matched your search

@@ -203,7 +203,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
if !connection.wasUserRejected { if !connection.wasUserRejected {
inboundAppDelegates.forEach { delegate in inboundAppDelegates.forEach { delegate in
delegate.connectionWasTerminated(from: connection.remoteDeviceInfo ?? RemoteDeviceInfo(name: "UnknownDevice".localized(), type: .unknown), wasPlainTextTransfer: connection.isPlainTextTransfer, error: error) delegate.connectionWasTerminated(connectionID: connection.id, from: connection.remoteDeviceInfo ?? RemoteDeviceInfo(name: "UnknownDevice".localized(), type: .unknown), wasPlainTextTransfer: connection.isPlainTextTransfer, error: error)
} }
} }
} }
+1 -1
View File
@@ -29,7 +29,7 @@ protocol OutboundNearbyConnectionDelegate {
public protocol InboundAppDelegate: AnyObject { public protocol InboundAppDelegate: AnyObject {
func obtainUserConsent(transfer: TransferMetadata, device: RemoteDeviceInfo, acceptAutomatically: Bool) func obtainUserConsent(transfer: TransferMetadata, device: RemoteDeviceInfo, acceptAutomatically: Bool)
func connectionWasTerminated(from device: RemoteDeviceInfo, wasPlainTextTransfer: Bool, error: Error?) func connectionWasTerminated(connectionID: String, from device: RemoteDeviceInfo, wasPlainTextTransfer: Bool, error: Error?)
func transferProgress(connectionID: String, progress: Double) func transferProgress(connectionID: String, progress: Double)
} }
+23 -6
View File
@@ -17,6 +17,9 @@ import LUI
class ReceiveModel: ObservableObject, InboundAppDelegate { class ReceiveModel: ObservableObject, InboundAppDelegate {
/// For each connection ID, store the last reported progress value
private var processes: [String: Double] = [:]
#if os(macOS) #if os(macOS)
@Published var progress: Double? = nil @Published var progress: Double? = nil
private var toastWindow: NSWindow? private var toastWindow: NSWindow?
@@ -156,28 +159,42 @@ class ReceiveModel: ObservableObject, InboundAppDelegate {
func transferProgress(connectionID: String, progress: Double) { 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) #if os(iOS)
ProgressAlert.shared.updateProgress(progress) ProgressAlert.shared.updateProgress(averageProgress)
#else #else
DispatchQueue.main.async { DispatchQueue.main.async {
self.progress = progress self.progress = averageProgress
self.showQuickDropToast(for: connectionID) self.showQuickDropToast(for: connectionID)
} }
#endif #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) #if os(macOS)
DispatchQueue.main.async { DispatchQueue.main.async {
self.hideQuickDropToast() self.hideQuickDropToast()
self.progress = nil
if self.processes.isEmpty {
self.progress = nil
}
} }
finish() finish()
#else #else
ProgressAlert.shared.updateProgress(nil) { if self.processes.isEmpty {
finish() ProgressAlert.shared.updateProgress(nil) {
finish()
}
} }
#endif #endif