mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-20 21:36:00 +00:00
Fix zipping large file freezes app
This commit is contained in:
1 parent
e6d1c7b1a3
commit
ce16bca415
2 files changed
+48
-8
No files matched your search
@@ -33,6 +33,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
|||||||
private var outboundAppDelegates: [OutboundAppDelegate] = []
|
private var outboundAppDelegates: [OutboundAppDelegate] = []
|
||||||
private var inboundAppDelegates: [InboundAppDelegate] = []
|
private var inboundAppDelegates: [InboundAppDelegate] = []
|
||||||
private var outgoingTransfers: [String: OutgoingTransferInfo] = [:]
|
private var outgoingTransfers: [String: OutgoingTransferInfo] = [:]
|
||||||
|
private var pendingOutgoingTransferPreparations: [String: UUID] = [:]
|
||||||
private var startedDeviceDiscovery = false
|
private var startedDeviceDiscovery = false
|
||||||
private var startedAdvertising = false { didSet { informAboutStatus() }}
|
private var startedAdvertising = false { didSet { informAboutStatus() }}
|
||||||
private var browsers: [NWBrowser] = []
|
private var browsers: [NWBrowser] = []
|
||||||
@@ -515,6 +516,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
|||||||
if let transfer = incomingConnections[id] {
|
if let transfer = incomingConnections[id] {
|
||||||
transfer.cancel()
|
transfer.cancel()
|
||||||
}
|
}
|
||||||
|
pendingOutgoingTransferPreparations.removeValue(forKey: id)
|
||||||
if let info = outgoingTransfers[id] {
|
if let info = outgoingTransfers[id] {
|
||||||
info.connection.cancel()
|
info.connection.cancel()
|
||||||
}
|
}
|
||||||
@@ -699,12 +701,35 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public func startOutgoingTransfer(deviceID: String, delegate: OutboundAppDelegate, urls: [URL], textToSend: String?) {
|
public func startOutgoingTransfer(
|
||||||
|
deviceID: String,
|
||||||
|
delegate: OutboundAppDelegate,
|
||||||
|
urls: [URL],
|
||||||
|
textToSend: String?,
|
||||||
|
preparationFinished: (() -> Void)? = nil
|
||||||
|
) {
|
||||||
log("Starting outgoing transfer to \(deviceID)")
|
log("Starting outgoing transfer to \(deviceID)")
|
||||||
guard let info = foundServices[deviceID] else { return }
|
guard foundServices[deviceID] != nil else { return }
|
||||||
|
|
||||||
|
let preparationID = UUID()
|
||||||
|
pendingOutgoingTransferPreparations[deviceID] = preparationID
|
||||||
|
|
||||||
|
DispatchQueue.global(qos: .userInitiated).async { [weak self, weak delegate] in
|
||||||
|
guard let self else { return }
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let localUrls = try saveFilesToTemp(urls: urls)
|
let localUrls = try self.saveFilesToTemp(urls: urls)
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
guard let info = self.foundServices[deviceID],
|
||||||
|
self.pendingOutgoingTransferPreparations[deviceID] == preparationID else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.pendingOutgoingTransferPreparations.removeValue(forKey: deviceID)
|
||||||
|
guard let delegate else { return }
|
||||||
|
|
||||||
|
preparationFinished?()
|
||||||
|
|
||||||
let tcp = NWProtocolTCP.Options()
|
let tcp = NWProtocolTCP.Options()
|
||||||
tcp.noDelay = true
|
tcp.noDelay = true
|
||||||
@@ -712,18 +737,27 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
|||||||
|
|
||||||
let conn = OutboundNearbyConnection(connection: nwconn, id: deviceID, urlsToSend: localUrls, textToSend: textToSend)
|
let conn = OutboundNearbyConnection(connection: nwconn, id: deviceID, urlsToSend: localUrls, textToSend: textToSend)
|
||||||
conn.delegate = self
|
conn.delegate = self
|
||||||
conn.qrCodePrivateKey = qrCodePrivateKey
|
conn.qrCodePrivateKey = self.qrCodePrivateKey
|
||||||
|
|
||||||
let transfer = OutgoingTransferInfo(service: info.service, device: info.device!, connection: conn, delegate: delegate)
|
let transfer = OutgoingTransferInfo(service: info.service, device: info.device!, connection: conn, delegate: delegate)
|
||||||
outgoingTransfers[deviceID] = transfer
|
self.outgoingTransfers[deviceID] = transfer
|
||||||
conn.start()
|
conn.start()
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
log("[NearbyConnectionManager] Error storing URLs: \(error)")
|
log("[NearbyConnectionManager] Error storing URLs: \(error)")
|
||||||
outboundAppDelegates.forEach { delegate in
|
DispatchQueue.main.async {
|
||||||
|
guard self.pendingOutgoingTransferPreparations[deviceID] == preparationID else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.pendingOutgoingTransferPreparations.removeValue(forKey: deviceID)
|
||||||
|
self.outboundAppDelegates.forEach { delegate in
|
||||||
delegate.connectionFailed(error: error)
|
delegate.connectionFailed(error: error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func connectionWasEstablished(connection: OutboundNearbyConnection) {
|
func connectionWasEstablished(connection: OutboundNearbyConnection) {
|
||||||
|
|||||||
@@ -259,8 +259,12 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
|
|||||||
chosenDevice = device
|
chosenDevice = device
|
||||||
|
|
||||||
runAfter(seconds: 0.3) {
|
runAfter(seconds: 0.3) {
|
||||||
NearbyConnectionManager.shared.startOutgoingTransfer(deviceID: device.id!, delegate: self, urls: self.urls, textToSend: self.textToSend)
|
NearbyConnectionManager.shared.startOutgoingTransfer(
|
||||||
|
deviceID: device.id!,
|
||||||
|
delegate: self,
|
||||||
|
urls: self.urls,
|
||||||
|
textToSend: self.textToSend,
|
||||||
|
preparationFinished: {
|
||||||
self.progressState?.stringValue = "Connecting".localized()
|
self.progressState?.stringValue = "Connecting".localized()
|
||||||
|
|
||||||
let timeoutAlert = DispatchWorkItem {
|
let timeoutAlert = DispatchWorkItem {
|
||||||
@@ -291,6 +295,8 @@ class ShareViewController: NSViewController, OutboundAppDelegate {
|
|||||||
self.timeoutDispatchWorkItem = timeoutAlert
|
self.timeoutDispatchWorkItem = timeoutAlert
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: timeoutAlert)
|
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0, execute: timeoutAlert)
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user