mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-19 04:46:08 +00:00
Replace alert with toast view
This commit is contained in:
1 parent
b55d6ff07b
commit
ed20c9155e
9 files changed
+3311
-1270
No files matched your search
@@ -539,6 +539,12 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
let acceptAutomatically = isAuthenticated || Settings.sharedInstance.automaticallyAcceptFiles
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if !NearbyConnectionManager.shared.claimIncomingTransfer(id: self.id) {
|
||||
log("[InboundNearbyConnection \(self.id)] Another transfer is active. Rejecting incoming transfer.")
|
||||
self.rejectTransfer()
|
||||
return
|
||||
}
|
||||
|
||||
if acceptAutomatically {
|
||||
self.delegate?.obtainedUserConsentAutomatically(transfer: metadata, device: self.remoteDeviceInfo!, connection: self)
|
||||
self.submitUserConsent(accepted: true, trustDevice: false)
|
||||
|
||||
@@ -29,6 +29,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
||||
private var tcpListener: NWListener
|
||||
private var mdnsServices: [NetService] = []
|
||||
private var incomingConnections: [String: InboundNearbyConnection] = [:]
|
||||
private var activeIncomingTransferID: String?
|
||||
private var foundServices: [String: FoundServiceInfo] = [:]
|
||||
private var outboundAppDelegates: [OutboundAppDelegate] = []
|
||||
private var inboundAppDelegates: [InboundAppDelegate] = []
|
||||
@@ -340,6 +341,9 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
||||
|
||||
|
||||
func connectionWasTerminated(connection: InboundNearbyConnection, savedFiles: [URL], error: Error?) {
|
||||
if activeIncomingTransferID == connection.id {
|
||||
activeIncomingTransferID = nil
|
||||
}
|
||||
incomingConnections.removeValue(forKey: connection.id)
|
||||
|
||||
if !connection.wasUserRejected {
|
||||
@@ -481,6 +485,14 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
||||
info.connection.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
func claimIncomingTransfer(id: String) -> Bool {
|
||||
if let activeIncomingTransferID, activeIncomingTransferID != id {
|
||||
return false
|
||||
}
|
||||
activeIncomingTransferID = id
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
private func endpointID(for service: NWBrowser.Result) -> String? {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UniformTypeIdentifiers
|
||||
import Network
|
||||
import CryptoKit
|
||||
import SwiftECC
|
||||
@@ -144,28 +145,57 @@ public struct TransferMetadata {
|
||||
if let textTitle = textDescription {
|
||||
return textTitle
|
||||
} else if files.count == 1 {
|
||||
return files[0].name
|
||||
return fileTypeSummary(for: files[0])
|
||||
} else {
|
||||
return String.localizedStringWithFormat("NFiles".localized(), files.count)
|
||||
}
|
||||
}
|
||||
|
||||
private func fileTypeSummary(for file: FileMetadata) -> String {
|
||||
let mimeType = file.mimeType.lowercased()
|
||||
let ext = URL(fileURLWithPath: file.name).pathExtension.lowercased()
|
||||
let type = UTType(mimeType: mimeType) ?? UTType(filenameExtension: ext)
|
||||
|
||||
if let type, type.conforms(to: .pdf) {
|
||||
return UTType.pdf.localizedDescription ?? "PDF"
|
||||
}
|
||||
if let type, type.conforms(to: .image) {
|
||||
return UTType.image.localizedDescription ?? "Image"
|
||||
}
|
||||
if let type, type.conforms(to: .video) || type.conforms(to: .movie) {
|
||||
return UTType.video.localizedDescription ?? "Video"
|
||||
}
|
||||
if let type, type.conforms(to: .audio) {
|
||||
return UTType.audio.localizedDescription ?? "Audio"
|
||||
}
|
||||
if let type, type.conforms(to: .text) {
|
||||
return UTType.text.localizedDescription ?? "Text"
|
||||
}
|
||||
if let type, type.conforms(to: .archive) {
|
||||
return UTType.archive.localizedDescription ?? "Archive"
|
||||
}
|
||||
if let type, let description = type.localizedDescription {
|
||||
return description
|
||||
}
|
||||
return "File"
|
||||
}
|
||||
|
||||
public func getDescription(deviceName: String, alreadyAccepted: Bool) -> String {
|
||||
public func getDescription(deviceName: String) -> String {
|
||||
|
||||
let fileStr = getSummary()
|
||||
|
||||
switch type {
|
||||
case .file:
|
||||
return String(format: (alreadyAccepted ? "DeviceCurrentlySendingFiles" : "DeviceSendingFiles").localized(), arguments: [deviceName, fileStr])
|
||||
return "DeviceSendingFiles".localized(with: fileStr, deviceName)
|
||||
|
||||
case .text:
|
||||
return String(format: (alreadyAccepted ? "DeviceCurrentlySendingText" : "DeviceSendingText").localized(), arguments: [deviceName, fileStr])
|
||||
return "DeviceSendingText".localized(with: deviceName)
|
||||
|
||||
case .url:
|
||||
return String(format: (alreadyAccepted ? "DeviceCurrentlySendingUrl" : "DeviceSendingUrl").localized(), arguments: [deviceName, fileStr])
|
||||
return "DeviceSendingUrl".localized(with: deviceName)
|
||||
|
||||
case .wifiPassword:
|
||||
return String(format: (alreadyAccepted ? "DeviceCurrentlySendingWifiPassword" : "DeviceSendingWifiPassword").localized(), arguments: [deviceName, fileStr])
|
||||
return "DeviceSendingWifiPassword".localized(with: deviceName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user