mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-23 06:46:03 +00:00
Add progress view for incoming transfer on iOS
This commit is contained in:
1 parent
62f5a13fd6
commit
288625cbd3
8 files changed
+1786
-1553
No files matched your search
@@ -25,6 +25,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
private var currentState: State = .initial
|
||||
private var cipherCommitment: Data?
|
||||
private var textPayloadID: Int64 = 0
|
||||
private var bytesToBeTransferred: Int64 = 0
|
||||
var isPlainTextTransfer = false
|
||||
|
||||
var wasUserRejected = false
|
||||
@@ -154,6 +155,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
|
||||
// only for logging
|
||||
self.bytesTransferred += Int64(frame.payloadChunk.body.count)
|
||||
NearbyConnectionManager.shared.inboundConnection(connection: self, transferProgress: Double(self.bytesTransferred) / Double(self.bytesToBeTransferred))
|
||||
} catch {
|
||||
log("[InboundNearbyConnection \(self.id)] Error occurred during writing file: \(error.localizedDescription)")
|
||||
|
||||
@@ -172,6 +174,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
|
||||
if filesToBeReceived.isEmpty {
|
||||
log("[InboundNearbyConnection \(self.id)] All files received, sending disconnection frame and disconnecting.")
|
||||
NearbyConnectionManager.shared.inboundConnection(connection: self, transferProgress: 1)
|
||||
try sendDisconnectionAndDisconnect()
|
||||
}
|
||||
}
|
||||
@@ -218,6 +221,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
SaveFilesManager.shared.registerFileFinishedDownloading(fileInfo.destinationURL)
|
||||
|
||||
log("[InboundNearbyConnection \(self.id)] Received file payload. Disconnecting...")
|
||||
NearbyConnectionManager.shared.inboundConnection(connection: self, transferProgress: 1)
|
||||
try sendDisconnectionAndDisconnect()
|
||||
return true
|
||||
}
|
||||
@@ -426,6 +430,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
payloadID: file.payloadID,
|
||||
destinationURL: dest)
|
||||
filesToBeReceived[file.payloadID] = info
|
||||
bytesToBeTransferred += file.size
|
||||
}
|
||||
let metadata = TransferMetadata(files: filesToBeReceived.map { $0.value.meta }, id: id, pinCode: pinCode)
|
||||
DispatchQueue.main.async {
|
||||
|
||||
@@ -134,6 +134,11 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
||||
}
|
||||
|
||||
|
||||
func inboundConnection(connection: InboundNearbyConnection, transferProgress: Double) {
|
||||
mainAppDelegate?.transferProgress(progress: transferProgress)
|
||||
}
|
||||
|
||||
|
||||
public func submitUserConsent(transferID: String, accept: Bool, storeInTemp: Bool = false) {
|
||||
guard let conn = incomingConnections[transferID] else { return }
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import SwiftECC
|
||||
|
||||
protocol InboundNearbyConnectionDelegate {
|
||||
func obtainUserConsent(for transfer: TransferMetadata, from device: RemoteDeviceInfo, connection: InboundNearbyConnection)
|
||||
func inboundConnection(connection: InboundNearbyConnection, transferProgress: Double)
|
||||
func connectionWasTerminated(connection: InboundNearbyConnection, error: Error?)
|
||||
}
|
||||
|
||||
@@ -29,6 +30,7 @@ protocol OutboundNearbyConnectionDelegate {
|
||||
public protocol InboundAppDelegate: AnyObject {
|
||||
func obtainUserConsent(for transfer: TransferMetadata, from device: RemoteDeviceInfo)
|
||||
func connectionWasTerminated(from device: RemoteDeviceInfo, wasPlainTextTransfer: Bool, error: Error?)
|
||||
func transferProgress(progress: Double)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import Foundation
|
||||
import ImageIO
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
#else
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
public class SaveFilesManager {
|
||||
|
||||
Reference in new issue
Block a user