New Alert for receiving files, rename to QuickDrop

This commit is contained in:
Leon Böttger committed 2025-03-01 16:06:08 +01:00
1 parent 79b359fb64
commit 4929a96134
71 files changed
+1521 -413

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
//
// Data+URLSafeBase64.swift
// NearDrop
// QuickDrop
//
// Created by Grishka on 08.04.2023.
//
+8 -8
View File
@@ -1,6 +1,6 @@
//
// InboundNearbyConnection.swift
// NearDrop
// QuickDrop
//
// Created by Grishka on 08.04.2023.
//
@@ -37,7 +37,7 @@ class InboundNearbyConnection: NearbyConnection{
do{
try deletePartiallyReceivedFiles()
}catch{
print("Error deleting partially received files: \(error)")
log("Error deleting partially received files: \(error)")
}
DispatchQueue.main.async {
self.delegate?.connectionWasTerminated(connection: self, error: self.lastError)
@@ -66,7 +66,7 @@ class InboundNearbyConnection: NearbyConnection{
}
}catch{
lastError=error
print("Deserialization error: \(error) in state \(currentState)")
log("Deserialization error: \(error) in state \(currentState)")
#if !DEBUG
protocolError()
#endif
@@ -75,7 +75,7 @@ class InboundNearbyConnection: NearbyConnection{
override internal func processTransferSetupFrame(_ frame:Sharing_Nearby_Frame) throws{
if frame.hasV1 && frame.v1.hasType, case .cancel = frame.v1.type {
print("Transfer canceled")
log("Transfer canceled")
try sendDisconnectionAndDisconnect()
return
}
@@ -87,8 +87,8 @@ class InboundNearbyConnection: NearbyConnection{
case .receivedPairedKeyResult:
try processIntroductionFrame(frame)
default:
print("Unexpected connection state in processTransferSetupFrame: \(currentState)")
print(frame)
log("Unexpected connection state in processTransferSetupFrame: \(currentState)")
log(frame.debugDescription)
}
}
@@ -259,7 +259,7 @@ class InboundNearbyConnection: NearbyConnection{
try sendTransferSetupFrame(pairedEncryption)
currentState = .sentConnectionResponse
} else {
print("Unhandled offline frame plaintext: \(frame)")
log("Unhandled offline frame plaintext: \(frame)")
}
}
@@ -390,7 +390,7 @@ class InboundNearbyConnection: NearbyConnection{
try sendTransferSetupFrame(frame)
try sendDisconnectionAndDisconnect()
}catch{
print("Error \(error)")
log("Error \(error)")
protocolError()
}
}
+7 -7
View File
@@ -1,6 +1,6 @@
//
// NearbyConnection.swift
// NearDrop
// QuickDrop
//
// Created by Grishka on 09.04.2023.
//
@@ -16,7 +16,7 @@ import BigInt
class NearbyConnection{
internal static let SANE_FRAME_LENGTH=5*1024*1024
private static let dispatchQueue=DispatchQueue(label: "me.grishka.NearDrop.queue", qos: .utility) // FIFO (non-concurrent) queue to avoid those exciting concurrency bugs
private static let dispatchQueue=DispatchQueue(label: "com.leonboettger.quickdrop.queue", qos: .utility) // FIFO (non-concurrent) queue to avoid those exciting concurrency bugs
internal let connection:NWConnection
internal var remoteDeviceInfo:RemoteDeviceInfo?
@@ -57,7 +57,7 @@ class NearbyConnection{
self.receiveFrameAsync()
} else if case .failed(let err) = state {
self.lastError=err
print("Error opening socket: \(err)")
log("Error opening socket: \(err)")
self.handleConnectionClosure()
}
}
@@ -68,7 +68,7 @@ class NearbyConnection{
func connectionReady(){}
internal func handleConnectionClosure(){
print("Connection closed")
log("Connection closed")
}
internal func protocolError(){
@@ -295,11 +295,11 @@ class NearbyConnection{
}
}else if offlineFrame.hasV1 && offlineFrame.v1.hasType, case .keepAlive = offlineFrame.v1.type{
#if DEBUG
print("Sent keep-alive")
log("Sent keep-alive")
#endif
sendKeepAlive(ack: true)
}else{
print("Unhandled offline frame encrypted: \(offlineFrame)")
log("Unhandled offline frame encrypted: \(offlineFrame)")
}
}
@@ -444,7 +444,7 @@ class NearbyConnection{
sendFrameAsync(try offlineFrame.serializedData())
}
}catch{
print("Error sending KEEP_ALIVE: \(error)")
log("Error sending KEEP_ALIVE: \(error)")
}
}
}
+4 -4
View File
@@ -1,6 +1,6 @@
//
// NearbyConnectionManager.swift
// NearDrop
// QuickDrop
//
// Created by Grishka on 08.04.2023.
//
@@ -296,19 +296,19 @@ public class NearbyConnectionManager : NSObject, NetServiceDelegate, InboundNear
private func maybeAddFoundDevice(service:NWBrowser.Result){
#if DEBUG
print("found service \(service)")
log("found service \(service)")
#endif
for interface in service.interfaces{
if case .loopback=interface.type{
#if DEBUG
print("ignoring localhost service")
log("ignoring localhost service")
#endif
return
}
}
guard let endpointID=endpointID(for: service) else {return}
#if DEBUG
print("service name is valid, endpoint ID \(endpointID)")
log("service name is valid, endpoint ID \(endpointID)")
#endif
var foundService=FoundServiceInfo(service: service)
+8 -8
View File
@@ -80,7 +80,7 @@ class OutboundNearbyConnection:NearbyConnection{
override func processReceivedFrame(frameData: Data) {
do{
#if DEBUG
print("received \(frameData), state is \(currentState)")
log("received \(frameData), state is \(currentState)")
#endif
switch currentState {
case .initial:
@@ -105,12 +105,12 @@ class OutboundNearbyConnection:NearbyConnection{
override func processTransferSetupFrame(_ frame: Sharing_Nearby_Frame) throws {
if frame.hasV1 && frame.v1.hasType, case .cancel = frame.v1.type {
print("Transfer canceled")
log("Transfer canceled")
try sendDisconnectionAndDisconnect()
delegate?.outboundConnection(connection: self, failedWithError: NearbyError.canceled(reason: .userCanceled))
return
}
print(frame)
log(frame.debugDescription)
switch currentState{
case .sentPairedKeyEncryption:
try processPairedKeyEncryption(frame: frame)
@@ -224,7 +224,7 @@ class OutboundNearbyConnection:NearbyConnection{
private func processConnectionResponse(frame:Location_Nearby_Connections_OfflineFrame) throws{
#if DEBUG
print("connection response: \(frame)")
log("connection response: \(frame)")
#endif
guard frame.version == .v1 else {throw NearbyError.protocolError("Unexpected offline frame version \(frame.version)")}
guard frame.v1.type == .connectionResponse else {throw NearbyError.protocolError("Unexpected frame type \(frame.v1.type)")}
@@ -306,7 +306,7 @@ class OutboundNearbyConnection:NearbyConnection{
}
}
#if DEBUG
print("sent introduction: \(introduction)")
log("sent introduction: \(introduction)")
#endif
try sendTransferSetupFrame(introduction)
@@ -355,7 +355,7 @@ class OutboundNearbyConnection:NearbyConnection{
}
if queue.isEmpty{
#if DEBUG
print("Disconnecting because all files have been transferred")
log("Disconnecting because all files have been transferred")
#endif
try sendDisconnectionAndDisconnect()
delegate?.outboundConnectionTransferFinished(connection: self)
@@ -399,7 +399,7 @@ class OutboundNearbyConnection:NearbyConnection{
}
})
#if DEBUG
print("sent file chunk, current transfer: \(String(describing: currentTransfer))")
log("sent file chunk, current transfer: \(String(describing: currentTransfer))")
#endif
totalBytesSent+=Int64(fileBuffer.count)
delegate?.outboundConnection(connection: self, transferProgress: Double(totalBytesSent)/Double(totalBytesToSend))
@@ -422,7 +422,7 @@ class OutboundNearbyConnection:NearbyConnection{
wrapper.v1.payloadTransfer=transfer
try encryptAndSendOfflineFrame(wrapper)
#if DEBUG
print("sent EOF, current transfer: \(String(describing: currentTransfer))")
log("sent EOF, current transfer: \(String(describing: currentTransfer))")
#endif
}
}