mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-21 13:55:58 +00:00
Add clipboard sync notification
This commit is contained in:
1 parent
5fdc5f8a1b
commit
2f6b0ff5ba
7 files changed
+178
-6
No files matched your search
@@ -30,11 +30,13 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
private var textPayloadID: Int64 = 0
|
||||
private var bytesToBeTransferred: Int64 = 0
|
||||
private var isAuthenticated = false
|
||||
private var receiverAuthenticationAccepted = false
|
||||
private var peerCertificate: Sharing_Nearby_PublicCertificate? = nil
|
||||
private var mirroredNotificationMetadata: Sharing_Nearby_MirroredNotificationMetadata?
|
||||
private var pairingMetadata: Sharing_Nearby_PairingMetadata?
|
||||
private var isPairingSetupRequest = false
|
||||
var isPlainTextTransfer = false
|
||||
var isClipboardSyncTransfer = false
|
||||
var isControlTransfer = false
|
||||
|
||||
var wasUserRejected = false
|
||||
@@ -287,6 +289,14 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
let pasteboard = NSPasteboard.general
|
||||
pasteboard.clearContents()
|
||||
pasteboard.setString(urlStr, forType: .string)
|
||||
#if !EXTENSION
|
||||
if isClipboardSyncTransfer {
|
||||
ClipboardSyncNotificationPresenter.shared.present(
|
||||
clipboardText: urlStr,
|
||||
senderDeviceName: remoteDeviceInfo?.name
|
||||
)
|
||||
}
|
||||
#endif
|
||||
#elseif os(iOS)
|
||||
// iOS clipboard
|
||||
UIPasteboard.general.string = urlStr
|
||||
@@ -570,6 +580,7 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
|
||||
private func processPairedKeyResultFrame(_ frame: Sharing_Nearby_Frame) throws {
|
||||
guard frame.hasV1, frame.v1.hasPairedKeyResult else { throw NearbyError.requiredFieldMissing("shareNearbyFrame.v1.pairedKeyResult") }
|
||||
receiverAuthenticationAccepted = frame.v1.pairedKeyResult.status == .success
|
||||
currentState = .receivedPairedKeyResult
|
||||
}
|
||||
|
||||
@@ -727,8 +738,17 @@ class InboundNearbyConnection: NearbyConnection {
|
||||
if let textMetadata = frame.v1.introduction.textMetadata.first {
|
||||
let isURL = textMetadata.type == .url
|
||||
textPayloadID = textMetadata.payloadID
|
||||
isClipboardSyncTransfer = !isURL && isAuthenticated && receiverAuthenticationAccepted
|
||||
|
||||
let metadata = TransferMetadata(files: [], id: id, pinCode: pinCode, textDescription: textMetadata.textTitle, transferType: isURL ? .url : .text, allowsToBeAddedAsTrustedDevice: self.peerCertificate != nil)
|
||||
let metadata = TransferMetadata(
|
||||
files: [],
|
||||
id: id,
|
||||
pinCode: pinCode,
|
||||
textDescription: textMetadata.textTitle,
|
||||
transferType: isURL ? .url : .text,
|
||||
allowsToBeAddedAsTrustedDevice: self.peerCertificate != nil,
|
||||
isClipboardSync: isClipboardSyncTransfer
|
||||
)
|
||||
|
||||
if !isURL {
|
||||
isPlainTextTransfer = true
|
||||
|
||||
@@ -379,7 +379,14 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
|
||||
|
||||
if !connection.wasUserRejected {
|
||||
inboundAppDelegates.forEach { delegate in
|
||||
delegate.connectionWasTerminated(connectionID: connection.id, from: connection.remoteDeviceInfo, savedFiles: savedFiles, wasPlainTextTransfer: connection.isPlainTextTransfer, error: error)
|
||||
delegate.connectionWasTerminated(
|
||||
connectionID: connection.id,
|
||||
from: connection.remoteDeviceInfo,
|
||||
savedFiles: savedFiles,
|
||||
wasPlainTextTransfer: connection.isPlainTextTransfer,
|
||||
wasClipboardSync: connection.isClipboardSyncTransfer,
|
||||
error: error
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public enum ReceiverAuthenticationPolicy: Equatable {
|
||||
public protocol InboundAppDelegate: AnyObject {
|
||||
func obtainUserConsent(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, wasClipboardSync: Bool, error: Error?)
|
||||
func transferProgress(connectionID: String, progress: Double)
|
||||
func showPlusScreen()
|
||||
func notificationSyncSetupConfirmed()
|
||||
@@ -217,14 +217,16 @@ public struct TransferMetadata {
|
||||
public let textDescription: String?
|
||||
public let type: TransferType
|
||||
public let allowsToBeAddedAsTrustedDevice: Bool
|
||||
public let isClipboardSync: Bool
|
||||
|
||||
init(files: [FileMetadata], id: String, pinCode: String?, textDescription: String? = nil, transferType: TransferType = .file, allowsToBeAddedAsTrustedDevice: Bool) {
|
||||
init(files: [FileMetadata], id: String, pinCode: String?, textDescription: String? = nil, transferType: TransferType = .file, allowsToBeAddedAsTrustedDevice: Bool, isClipboardSync: Bool = false) {
|
||||
self.files = files
|
||||
self.id = id
|
||||
self.pinCode = pinCode
|
||||
self.textDescription = textDescription
|
||||
self.type = transferType
|
||||
self.allowsToBeAddedAsTrustedDevice = allowsToBeAddedAsTrustedDevice
|
||||
self.isClipboardSync = isClipboardSync
|
||||
}
|
||||
|
||||
public enum TransferType {
|
||||
|
||||
Reference in new issue
Block a user