mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-24 23:36:05 +00:00
Fix outgoing transfer to Windows
This commit is contained in:
1 parent
a9e6ed1ddf
commit
9dfe864677
6 files changed
+35
-18
No files matched your search
@@ -547,7 +547,7 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
TrustStore.shared.addTrusted(certificate: peerCertificate, device: remoteDeviceInfo)
|
TrustStore.shared.addTrusted(certificate: peerCertificate, device: remoteDeviceInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.global(qos: .utility).async {
|
NearbyConnection.dispatchQueue.async {
|
||||||
if accepted {
|
if accepted {
|
||||||
self.acceptTransfer()
|
self.acceptTransfer()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import LUI
|
|||||||
class NearbyConnection {
|
class NearbyConnection {
|
||||||
|
|
||||||
private let maxFrameLength = 5 * 1024 * 1024
|
private let maxFrameLength = 5 * 1024 * 1024
|
||||||
private static let dispatchQueue = DispatchQueue(label: "com.leonboettger.quickdrop.queue", qos: .utility)
|
static let dispatchQueue = DispatchQueue(label: "com.leonboettger.quickdrop.queue", qos: .utility)
|
||||||
|
|
||||||
let id: String
|
let id: String
|
||||||
let connection: NWConnection
|
let connection: NWConnection
|
||||||
@@ -118,7 +118,7 @@ class NearbyConnection {
|
|||||||
|
|
||||||
|
|
||||||
func connectionClosedByPeer(onError: @escaping () -> Void) {
|
func connectionClosedByPeer(onError: @escaping () -> Void) {
|
||||||
NearbyConnection.dispatchQueue.asyncAfter(deadline: .now() + 0.5) {
|
NearbyConnection.dispatchQueue.asyncAfter(deadline: .now() + 1) {
|
||||||
|
|
||||||
// If already closed, ignore the error, as file transfer has been processed
|
// If already closed, ignore the error, as file transfer has been processed
|
||||||
if !self.connectionClosed {
|
if !self.connectionClosed {
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
|||||||
|
|
||||||
if !connection.wasUserRejected {
|
if !connection.wasUserRejected {
|
||||||
inboundAppDelegates.forEach { delegate in
|
inboundAppDelegates.forEach { delegate in
|
||||||
delegate.connectionWasTerminated(connectionID: connection.id, from: connection.remoteDeviceInfo ?? RemoteDeviceInfo(name: "UnknownDevice".localized(), type: .unknown), savedFiles: savedFiles, wasPlainTextTransfer: connection.isPlainTextTransfer, error: error)
|
delegate.connectionWasTerminated(connectionID: connection.id, from: connection.remoteDeviceInfo, savedFiles: savedFiles, wasPlainTextTransfer: connection.isPlainTextTransfer, error: error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -347,6 +347,7 @@ class OutboundNearbyConnection: NearbyConnection {
|
|||||||
meta.textTitle = textToSend
|
meta.textTitle = textToSend
|
||||||
meta.size = Int64(textToSend.utf8.count)
|
meta.size = Int64(textToSend.utf8.count)
|
||||||
meta.payloadID = textPayloadID
|
meta.payloadID = textPayloadID
|
||||||
|
meta.id = Int64.random(in: Int64.min ... Int64.max)
|
||||||
introduction.v1.introduction.textMetadata.append(meta)
|
introduction.v1.introduction.textMetadata.append(meta)
|
||||||
|
|
||||||
} else if hasURL() {
|
} else if hasURL() {
|
||||||
@@ -355,6 +356,7 @@ class OutboundNearbyConnection: NearbyConnection {
|
|||||||
meta.textTitle = urlsToSend[0].host ?? "URL"
|
meta.textTitle = urlsToSend[0].host ?? "URL"
|
||||||
meta.size = Int64(urlsToSend[0].absoluteString.utf8.count)
|
meta.size = Int64(urlsToSend[0].absoluteString.utf8.count)
|
||||||
meta.payloadID = textPayloadID
|
meta.payloadID = textPayloadID
|
||||||
|
meta.id = Int64.random(in: Int64.min ... Int64.max)
|
||||||
introduction.v1.introduction.textMetadata.append(meta)
|
introduction.v1.introduction.textMetadata.append(meta)
|
||||||
} else {
|
} else {
|
||||||
for url in urlsToSend {
|
for url in urlsToSend {
|
||||||
@@ -382,12 +384,15 @@ class OutboundNearbyConnection: NearbyConnection {
|
|||||||
} else {
|
} else {
|
||||||
meta.type = .unknown
|
meta.type = .unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.payloadID = Int64.random(in: Int64.min ... Int64.max)
|
meta.payloadID = Int64.random(in: Int64.min ... Int64.max)
|
||||||
|
meta.id = Int64.random(in: Int64.min ... Int64.max)
|
||||||
|
|
||||||
try queue.append(OutgoingFileTransfer(url: url, payloadID: meta.payloadID, handle: FileHandle(forReadingFrom: url), totalBytes: meta.size, currentOffset: 0))
|
try queue.append(OutgoingFileTransfer(url: url, payloadID: meta.payloadID, handle: FileHandle(forReadingFrom: url), totalBytes: meta.size, currentOffset: 0))
|
||||||
introduction.v1.introduction.fileMetadata.append(meta)
|
introduction.v1.introduction.fileMetadata.append(meta)
|
||||||
totalBytesToSend += meta.size
|
totalBytesToSend += meta.size
|
||||||
|
|
||||||
log("[OutboundNearbyConnection \(self.id)] Sending file with \(meta.size) bytes")
|
log("[OutboundNearbyConnection \(self.id)] Sending file with \(meta.size) bytes and mime type \(meta.mimeType) and type \(meta.type) and name \(meta.name)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try sendTransferSetupFrame(introduction)
|
try sendTransferSetupFrame(introduction)
|
||||||
@@ -454,8 +459,18 @@ class OutboundNearbyConnection: NearbyConnection {
|
|||||||
}
|
}
|
||||||
if queue.isEmpty {
|
if queue.isEmpty {
|
||||||
log("[OutboundNearbyConnection \(self.id)] Disconnecting because all files have been transferred")
|
log("[OutboundNearbyConnection \(self.id)] Disconnecting because all files have been transferred")
|
||||||
try sendDisconnectionAndDisconnect()
|
|
||||||
delegate?.transferFinished(connection: self)
|
// Delay disconnection to ensure EOF frame is processed at peer
|
||||||
|
NearbyConnection.dispatchQueue.asyncAfter(deadline: .now() + 0.5) {
|
||||||
|
do {
|
||||||
|
try self.sendDisconnectionAndDisconnect()
|
||||||
|
self.delegate?.transferFinished(connection: self)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
log("[OutboundNearbyConnection \(self.id)] Error while sending disconnection: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentTransfer = queue.removeFirst()
|
currentTransfer = queue.removeFirst()
|
||||||
@@ -476,6 +491,7 @@ class OutboundNearbyConnection: NearbyConnection {
|
|||||||
transfer.payloadHeader.type = .file
|
transfer.payloadHeader.type = .file
|
||||||
transfer.payloadHeader.totalSize = Int64(currentTransfer!.totalBytes)
|
transfer.payloadHeader.totalSize = Int64(currentTransfer!.totalBytes)
|
||||||
transfer.payloadHeader.isSensitive = false
|
transfer.payloadHeader.isSensitive = false
|
||||||
|
transfer.payloadHeader.fileName = OutboundNearbyConnection.sanitizeFileName(name: currentTransfer!.url.lastPathComponent)
|
||||||
currentTransfer!.currentOffset += Int64(fileBuffer.count)
|
currentTransfer!.currentOffset += Int64(fileBuffer.count)
|
||||||
|
|
||||||
var wrapper = Location_Nearby_Connections_OfflineFrame()
|
var wrapper = Location_Nearby_Connections_OfflineFrame()
|
||||||
@@ -498,11 +514,12 @@ class OutboundNearbyConnection: NearbyConnection {
|
|||||||
delegate?.updatedTransferProgress(connection: self, progress: Double(bytesTransferred) / Double(totalBytesToSend))
|
delegate?.updatedTransferProgress(connection: self, progress: Double(bytesTransferred) / Double(totalBytesToSend))
|
||||||
|
|
||||||
if currentTransfer!.currentOffset == currentTransfer!.totalBytes {
|
if currentTransfer!.currentOffset == currentTransfer!.totalBytes {
|
||||||
// Signal end of file (yes, all this for one bit)
|
|
||||||
|
// Signal end of file
|
||||||
var transfer = Location_Nearby_Connections_PayloadTransferFrame()
|
var transfer = Location_Nearby_Connections_PayloadTransferFrame()
|
||||||
transfer.packetType = .data
|
transfer.packetType = .data
|
||||||
transfer.payloadChunk.offset = currentTransfer!.currentOffset
|
transfer.payloadChunk.offset = currentTransfer!.currentOffset
|
||||||
transfer.payloadChunk.flags = 1 // <- this one here
|
transfer.payloadChunk.flags = 1
|
||||||
transfer.payloadHeader.id = currentTransfer!.payloadID
|
transfer.payloadHeader.id = currentTransfer!.payloadID
|
||||||
transfer.payloadHeader.type = .file
|
transfer.payloadHeader.type = .file
|
||||||
transfer.payloadHeader.totalSize = Int64(currentTransfer!.totalBytes)
|
transfer.payloadHeader.totalSize = Int64(currentTransfer!.totalBytes)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ protocol OutboundNearbyConnectionDelegate {
|
|||||||
public protocol InboundAppDelegate: AnyObject {
|
public protocol InboundAppDelegate: AnyObject {
|
||||||
func obtainUserConsent(transfer: TransferMetadata, device: RemoteDeviceInfo)
|
func obtainUserConsent(transfer: TransferMetadata, device: RemoteDeviceInfo)
|
||||||
func obtainedUserConsentAutomatically(transfer: TransferMetadata, device: RemoteDeviceInfo)
|
func obtainedUserConsentAutomatically(transfer: TransferMetadata, device: RemoteDeviceInfo)
|
||||||
func connectionWasTerminated(connectionID: String, from device: RemoteDeviceInfo, savedFiles: [URL], wasPlainTextTransfer: Bool, error: Error?)
|
func connectionWasTerminated(connectionID: String, from device: RemoteDeviceInfo?, savedFiles: [URL], wasPlainTextTransfer: Bool, error: Error?)
|
||||||
func transferProgress(connectionID: String, progress: Double)
|
func transferProgress(connectionID: String, progress: Double)
|
||||||
func showPlusScreen()
|
func showPlusScreen()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ class ReceiveModel: ObservableObject, InboundAppDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func connectionWasTerminated(connectionID: String, from device: RemoteDeviceInfo, savedFiles: [URL], wasPlainTextTransfer: Bool, error: (any Error)?) {
|
func connectionWasTerminated(connectionID: String, from device: RemoteDeviceInfo?, savedFiles: [URL], wasPlainTextTransfer: Bool, error: (any Error)?) {
|
||||||
|
|
||||||
processes.removeValue(forKey: connectionID)
|
processes.removeValue(forKey: connectionID)
|
||||||
|
|
||||||
@@ -193,16 +193,16 @@ class ReceiveModel: ObservableObject, InboundAppDelegate {
|
|||||||
|
|
||||||
func finish() {
|
func finish() {
|
||||||
if let error = error {
|
if let error = error {
|
||||||
|
if let name = device?.name {
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.hideQuickDropToast()
|
self.hideQuickDropToast()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
controlPlusScreen(false)
|
controlPlusScreen(false)
|
||||||
|
|
||||||
if let name = device.name {
|
|
||||||
errorVibration()
|
errorVibration()
|
||||||
ErrorAlertHandler.shared.showErrorAlert(for: name, error: error)
|
ErrorAlertHandler.shared.showErrorAlert(for: name, error: error)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user