mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-19 12:56:06 +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
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user