From ab4af784c413d28d50e05e1c887a3f4c554a5cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Sat, 17 May 2025 13:00:42 +0200 Subject: [PATCH] Copy text to clipboard --- NearDrop/AppDelegate.swift | 23 ++++++- .../Clipboard.imageset/Clipboard.png | Bin 0 -> 6424 bytes .../Clipboard.imageset/Contents.json | 21 ++++++ NearDrop/Base.lproj/Localizable.strings | 7 ++ NearDrop/ar.lproj/Localizable.strings | 7 ++ NearDrop/de.lproj/Localizable.strings | 7 ++ NearDrop/es.lproj/Localizable.strings | 7 ++ NearDrop/fr.lproj/Localizable.strings | 7 ++ NearDrop/hu.lproj/Localizable.strings | 7 ++ NearDrop/it.lproj/Localizable.strings | 7 ++ NearDrop/ja.lproj/Localizable.strings | 7 ++ NearDrop/ko.lproj/Localizable.strings | 7 ++ NearDrop/nl.lproj/Localizable.strings | 7 ++ NearDrop/pt-BR.lproj/Localizable.strings | 7 ++ NearDrop/pt-PT.lproj/Localizable.strings | 7 ++ NearDrop/ro.lproj/Localizable.strings | 7 ++ NearDrop/ru.lproj/Localizable.strings | 7 ++ NearDrop/th.lproj/Localizable.strings | 7 ++ NearDrop/uk.lproj/Localizable.strings | 7 ++ NearDrop/zh-Hans.lproj/Localizable.strings | 7 ++ NearbyShare/InboundNearbyConnection.swift | 64 ++++++++++++------ NearbyShare/NearbyConnectionManager.swift | 11 ++- 22 files changed, 215 insertions(+), 23 deletions(-) create mode 100644 NearDrop/Assets.xcassets/Clipboard.imageset/Clipboard.png create mode 100644 NearDrop/Assets.xcassets/Clipboard.imageset/Contents.json diff --git a/NearDrop/AppDelegate.swift b/NearDrop/AppDelegate.swift index 841d340..13f24e6 100644 --- a/NearDrop/AppDelegate.swift +++ b/NearDrop/AppDelegate.swift @@ -16,6 +16,7 @@ import UserNotifications @main class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate, MainAppDelegate { + private var statusItem: NSStatusItem? private var activeIncomingTransfers: [String: TransferInfo] = [:] @@ -284,7 +285,21 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele fileStr = String.localizedStringWithFormat(NSLocalizedString("NFiles", value: "%d files", comment: ""), transfer.files.count) } - let mainMessage = String(format: (acceptAutomatically ? "DeviceCurrentlySendingFiles" : "DeviceSendingFiles").localized(), arguments: [device.name, fileStr]) + + let mainMessage: String + + switch transfer.type { + case .file: + mainMessage = String(format: (acceptAutomatically ? "DeviceCurrentlySendingFiles" : "DeviceSendingFiles").localized(), arguments: [device.name, fileStr]) + + case .text: + mainMessage = String(format: (acceptAutomatically ? "DeviceCurrentlySendingText" : "DeviceSendingText").localized(), arguments: [device.name, fileStr]) + + case .url: + mainMessage = String(format: (acceptAutomatically ? "DeviceCurrentlySendingUrl" : "DeviceSendingUrl").localized(), arguments: [device.name, fileStr]) + } + + let pinCodeMessage = String(format: NSLocalizedString("PinCode", value: "PIN: %@", comment: ""), arguments: [transfer.pinCode ?? "?"]) let transferID = transfer.id @@ -342,6 +357,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele func showFirewallAlert() { openAlert(type: .Firewall) } + + func showCopiedToClipboardAlert() { + DispatchQueue.main.async { + BezelNotification.show(messageText: "InsertedIntoClipboard".localized(), icon: .clipboard) + } + } func incomingTransfer(id: String, didFinishWith error: Error?) { guard let transfer = activeIncomingTransfers[id] else { return } diff --git a/NearDrop/Assets.xcassets/Clipboard.imageset/Clipboard.png b/NearDrop/Assets.xcassets/Clipboard.imageset/Clipboard.png new file mode 100644 index 0000000000000000000000000000000000000000..9d4f55593737eaae06e25d5f9e70d6242328d5d6 GIT binary patch literal 6424 zcmeI1XHZjJx5q<_n$QeIkWT0zf*>7f0VRN;L^{%uUQ~LOPy|6Cbm=I)Lm(i8W~=Y@aFk&@ArG}%$@tr+z)&HYoEQ>I%m%L&6%~q^bRlxu_MOTJ@u2lg4b9K7n)PL9vHveptki9?v04^jL8R%I?Fi=XP+Z;n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!v5)xytLDt_XFCI4j2rLBkF^#q` zNaa93=OgEnour|*VmkIBW6@jA*$RJ=8;_nRMwF$Ql*+>m>Mhi@z z2Nhla)MMSKELIg=#HIcdUZD%rKOh?WMxjczom}3AoJLEqMOYzTv9l zZv$0qdtx`_?+XLa=D==;#4gN$5UJ<@8b6e)+^b~o$4`P|cdoYN%wG|PUU&HdP!bcX z_cf;sa?hT{!9GL)Rl6XaB&Ni~#O)8ie$g~q>5fStf8Ql14RAo0J>@1|n)JiHS;vJ> zn!Zv68d&DaBJi_K-|1*IC6zEj!i_=H8vL=Ptx;K}I)hw!R*iD(BN1xNLvwIu)p|lP{T4NY6vk zx*PLtM%9M>^jC4CpnPKkp)nvvTFg&aL7={1!Q+a5DG>dD{ZH~|?d$M^SnI!QWhC6i z##OVrDW)kwqs^~+$0Kz#-n__QXkgOgsnX@|HnYeG z-#O%s+Q@A}?^4nyrB*)X@lf$Qtw2pZk*LlBfTWfPPSYYq)jM+Foy3-fu(=noTk3iD zo{Y$;sSZpNR%5_K{_JQzN#it7S+vdK=PhA}ir6C}W#x@$VsH911#KNQ@8 zA~5kwrCsX=gBd@yHd1G_;?MM5-#Q%Ah8+g%Ma$|7!+;mRZ2csaXQrRe8s?2P*gR8R z`H|JWd*RFa2rDHn^EOyb%w-VObAxu9cuq|C(AJ;@m5S-r!qhE43*{g{u#rpK?aXLx z_6R%o1?2(Ah6DQ~$F&30b4+h(P91Hw7qS_ksEMM;7t2)YR`>%a{olTX>7`7M_|5O-53_kg`kH2sL$zU105r!zv{a64zV u;HkeW!PtJ8k*BYU?7Q_EJl`y(yYS03AN%$A$28~z% literal 0 HcmV?d00001 diff --git a/NearDrop/Assets.xcassets/Clipboard.imageset/Contents.json b/NearDrop/Assets.xcassets/Clipboard.imageset/Contents.json new file mode 100644 index 0000000..db272bd --- /dev/null +++ b/NearDrop/Assets.xcassets/Clipboard.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Clipboard.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/NearDrop/Base.lproj/Localizable.strings b/NearDrop/Base.lproj/Localizable.strings index b09ad34..23adc0b 100644 --- a/NearDrop/Base.lproj/Localizable.strings +++ b/NearDrop/Base.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ is sending you %2$@"; +"DeviceCurrentlySendingText" = "%1$@ inserted \"%2$@\" to your clipboard."; +"DeviceSendingText" = "%1$@ wants to insert \"%2$@\" to your Mac's clipboard."; + +"DeviceCurrentlySendingUrl" = "%1$@ opened \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ wants to open \"%2$@\" on your Mac."; + +"InsertedIntoClipboard" = "Inserted"; /* No comment provided by engineer. */ "Error.Crypto" = "Encryption error"; diff --git a/NearDrop/ar.lproj/Localizable.strings b/NearDrop/ar.lproj/Localizable.strings index 7a917f7..b929902 100644 --- a/NearDrop/ar.lproj/Localizable.strings +++ b/NearDrop/ar.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ يرسل لك %2$@"; +"DeviceCurrentlySendingText" = "قام %1$@ بإدراج \"%2$@\" في الحافظة الخاصة بك."; +"DeviceSendingText" = "يرغب %1$@ في إدراج \"%2$@\" في حافظة جهاز Mac الخاص بك."; + +"DeviceCurrentlySendingUrl" = "قام %1$@ بفتح \"%2$@\"."; +"DeviceSendingUrl" = "يرغب %1$@ في فتح \"%2$@\" على جهاز Mac الخاص بك."; + +"InsertedIntoClipboard" = "تم الإدراج"; /* No comment provided by engineer. */ "Error.Crypto" = "خطأ في التشفير"; diff --git a/NearDrop/de.lproj/Localizable.strings b/NearDrop/de.lproj/Localizable.strings index c10a7e9..f9003f2 100644 --- a/NearDrop/de.lproj/Localizable.strings +++ b/NearDrop/de.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ möchte dir %2$@ senden"; +"DeviceCurrentlySendingText" = "%1$@ hat \"%2$@\" in deine Zwischenablage eingefügt."; +"DeviceSendingText" = "%1$@ möchte \"%2$@\" in die Zwischenablage deines Macs einfügen."; + +"DeviceCurrentlySendingUrl" = "%1$@ hat \"%2$@\" geöffnet."; +"DeviceSendingUrl" = "%1$@ möchte \"%2$@\" auf deinem Mac öffnen."; + +"InsertedIntoClipboard" = "Eingefügt"; /* No comment provided by engineer. */ "Error.Crypto" = "Verschlüsselungsfehler"; diff --git a/NearDrop/es.lproj/Localizable.strings b/NearDrop/es.lproj/Localizable.strings index 178d9f4..70daaa2 100644 --- a/NearDrop/es.lproj/Localizable.strings +++ b/NearDrop/es.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ te quiere mandar %2$@"; +"DeviceCurrentlySendingText" = "%1$@ ha insertado \"%2$@\" en tu portapapeles."; +"DeviceSendingText" = "%1$@ quiere insertar \"%2$@\" en el portapapeles de tu Mac."; + +"DeviceCurrentlySendingUrl" = "%1$@ ha abierto \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ quiere abrir \"%2$@\" en tu Mac."; + +"InsertedIntoClipboard" = "Insertado"; /* No comment provided by engineer. */ "Error.Crypto" = " Error de encriptación"; diff --git a/NearDrop/fr.lproj/Localizable.strings b/NearDrop/fr.lproj/Localizable.strings index 2637e7e..16d648f 100644 --- a/NearDrop/fr.lproj/Localizable.strings +++ b/NearDrop/fr.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ vous envoie %2$@"; +"DeviceCurrentlySendingText" = "%1$@ a inséré \"%2$@\" dans votre presse-papiers."; +"DeviceSendingText" = "%1$@ souhaite insérer \"%2$@\" dans le presse-papiers de votre Mac."; + +"DeviceCurrentlySendingUrl" = "%1$@ a ouvert \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ souhaite ouvrir \"%2$@\" sur votre Mac."; + +"InsertedIntoClipboard" = "Inséré"; /* No comment provided by engineer. */ "Error.Crypto" = "Erreur de cryptage"; diff --git a/NearDrop/hu.lproj/Localizable.strings b/NearDrop/hu.lproj/Localizable.strings index a1d714d..15b7d4b 100644 --- a/NearDrop/hu.lproj/Localizable.strings +++ b/NearDrop/hu.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ a következőt küldi: %2$@"; +"DeviceCurrentlySendingText" = "%1$@ beillesztette a(z) \"%2$@\" szöveget a vágólapodra."; +"DeviceSendingText" = "%1$@ be szeretné illeszteni a(z) \"%2$@\" szöveget a Mac-ed vágólapjára."; + +"DeviceCurrentlySendingUrl" = "%1$@ megnyitotta a(z) \"%2$@\" hivatkozást."; +"DeviceSendingUrl" = "%1$@ meg szeretné nyitni a(z) \"%2$@\" hivatkozást a Mac-eden."; + +"InsertedIntoClipboard" = "Beillesztve"; /* No comment provided by engineer. */ "Error.Crypto" = "Titkosítási hiba"; diff --git a/NearDrop/it.lproj/Localizable.strings b/NearDrop/it.lproj/Localizable.strings index 33c66ed..b362aa7 100644 --- a/NearDrop/it.lproj/Localizable.strings +++ b/NearDrop/it.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ ti sta mandando %2$@"; +"DeviceCurrentlySendingText" = "%1$@ ha inserito \"%2$@\" negli appunti."; +"DeviceSendingText" = "%1$@ vuole inserire \"%2$@\" negli appunti del tuo Mac."; + +"DeviceCurrentlySendingUrl" = "%1$@ ha aperto \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ vuole aprire \"%2$@\" sul tuo Mac."; + +"InsertedIntoClipboard" = "Inserito"; /* No comment provided by engineer. */ "Error.Crypto" = "Errore di crittografia"; diff --git a/NearDrop/ja.lproj/Localizable.strings b/NearDrop/ja.lproj/Localizable.strings index 0f26aa1..33f6135 100644 --- a/NearDrop/ja.lproj/Localizable.strings +++ b/NearDrop/ja.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@が%2$@を送信しています"; +"DeviceCurrentlySendingText" = "%1$@ が \"%2$@\" をクリップボードに挿入しました。"; +"DeviceSendingText" = "%1$@ が \"%2$@\" をあなたの Mac のクリップボードに挿入しようとしています。"; + +"DeviceCurrentlySendingUrl" = "%1$@ が \"%2$@\" を開きました。"; +"DeviceSendingUrl" = "%1$@ があなたの Mac で \"%2$@\" を開こうとしています。"; + +"InsertedIntoClipboard" = "挿入されました"; /* No comment provided by engineer. */ "Error.Crypto" = "暗号化エラー"; diff --git a/NearDrop/ko.lproj/Localizable.strings b/NearDrop/ko.lproj/Localizable.strings index b152c74..2df0076 100644 --- a/NearDrop/ko.lproj/Localizable.strings +++ b/NearDrop/ko.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@에서 %2$@을(를) 공유하려고 합니다."; +"DeviceCurrentlySendingText" = "%1$@이(가) \"%2$@\"을(를) 클립보드에 삽입했습니다."; +"DeviceSendingText" = "%1$@이(가) \"%2$@\"을(를) Mac의 클립보드에 삽입하려고 합니다."; + +"DeviceCurrentlySendingUrl" = "%1$@이(가) \"%2$@\"을(를) 열었습니다."; +"DeviceSendingUrl" = "%1$@이(가) Mac에서 \"%2$@\"을(를) 열려고 합니다."; + +"InsertedIntoClipboard" = "삽입됨"; /* No comment provided by engineer. */ "Error.Crypto" = "암호화 오류"; diff --git a/NearDrop/nl.lproj/Localizable.strings b/NearDrop/nl.lproj/Localizable.strings index eb76151..e823854 100644 --- a/NearDrop/nl.lproj/Localizable.strings +++ b/NearDrop/nl.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ stuurt je %2$@"; +"DeviceCurrentlySendingText" = "%1$@ heeft \"%2$@\" in je klembord geplaatst."; +"DeviceSendingText" = "%1$@ wil \"%2$@\" in het klembord van je Mac plaatsen."; + +"DeviceCurrentlySendingUrl" = "%1$@ heeft \"%2$@\" geopend."; +"DeviceSendingUrl" = "%1$@ wil \"%2$@\" openen op je Mac."; + +"InsertedIntoClipboard" = "Ingevoerd"; /* No comment provided by engineer. */ "Error.Crypto" = "Fout bij codering"; diff --git a/NearDrop/pt-BR.lproj/Localizable.strings b/NearDrop/pt-BR.lproj/Localizable.strings index d028ec4..4283217 100644 --- a/NearDrop/pt-BR.lproj/Localizable.strings +++ b/NearDrop/pt-BR.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ está te enviando %2$@"; +"DeviceCurrentlySendingText" = "%1$@ inseriu \"%2$@\" na sua área de transferência."; +"DeviceSendingText" = "%1$@ deseja inserir \"%2$@\" na área de transferência do seu Mac."; + +"DeviceCurrentlySendingUrl" = "%1$@ abriu \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ deseja abrir \"%2$@\" no seu Mac."; + +"InsertedIntoClipboard" = "Inserido"; /* No comment provided by engineer. */ "Error.Crypto" = "Erro de encriptação"; diff --git a/NearDrop/pt-PT.lproj/Localizable.strings b/NearDrop/pt-PT.lproj/Localizable.strings index 06879c4..e60c76b 100644 --- a/NearDrop/pt-PT.lproj/Localizable.strings +++ b/NearDrop/pt-PT.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ está a enviar %2$@"; +"DeviceCurrentlySendingText" = "%1$@ inseriu \"%2$@\" na sua área de transferência."; +"DeviceSendingText" = "%1$@ pretende inserir \"%2$@\" na área de transferência do seu Mac."; + +"DeviceCurrentlySendingUrl" = "%1$@ abriu \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ pretende abrir \"%2$@\" no seu Mac."; + +"InsertedIntoClipboard" = "Inserido"; /* No comment provided by engineer. */ "Error.Crypto" = "Erro de encriptação"; diff --git a/NearDrop/ro.lproj/Localizable.strings b/NearDrop/ro.lproj/Localizable.strings index d455473..7bdd9ea 100644 --- a/NearDrop/ro.lproj/Localizable.strings +++ b/NearDrop/ro.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ vă trimite %2$@"; +"DeviceCurrentlySendingText" = "%1$@ a introdus \"%2$@\" în clipboard-ul tău."; +"DeviceSendingText" = "%1$@ dorește să introducă \"%2$@\" în clipboard-ul Mac-ului tău."; + +"DeviceCurrentlySendingUrl" = "%1$@ a deschis \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ dorește să deschidă \"%2$@\" pe Mac-ul tău."; + +"InsertedIntoClipboard" = "Inserat"; /* No comment provided by engineer. */ "Error.Crypto" = "Eroare de criptare"; diff --git a/NearDrop/ru.lproj/Localizable.strings b/NearDrop/ru.lproj/Localizable.strings index 82b2386..48d82ab 100644 --- a/NearDrop/ru.lproj/Localizable.strings +++ b/NearDrop/ru.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ отправляет Вам %2$@"; +"DeviceCurrentlySendingText" = "%1$@ вставил \"%2$@\" в ваш буфер обмена."; +"DeviceSendingText" = "%1$@ хочет вставить \"%2$@\" в буфер обмена вашего Mac."; + +"DeviceCurrentlySendingUrl" = "%1$@ открыл \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ хочет открыть \"%2$@\" на вашем Mac."; + +"InsertedIntoClipboard" = "Вставлено"; /* No comment provided by engineer. */ "Error.Crypto" = "Ошибка шифрования"; diff --git a/NearDrop/th.lproj/Localizable.strings b/NearDrop/th.lproj/Localizable.strings index 344df25..63df5c7 100644 --- a/NearDrop/th.lproj/Localizable.strings +++ b/NearDrop/th.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ กำลังส่งไฟล์ให้คุณ %2$@"; +"DeviceCurrentlySendingText" = "%1$@ ได้แทรก \"%2$@\" ไปยังคลิปบอร์ดของคุณแล้ว"; +"DeviceSendingText" = "%1$@ ต้องการแทรก \"%2$@\" ไปยังคลิปบอร์ดของ Mac ของคุณ"; + +"DeviceCurrentlySendingUrl" = "%1$@ ได้เปิด \"%2$@\" แล้ว"; +"DeviceSendingUrl" = "%1$@ ต้องการเปิด \"%2$@\" บน Mac ของคุณ"; + +"InsertedIntoClipboard" = "แทรกแล้ว"; /* No comment provided by engineer. */ "Error.Crypto" = "การเข้ารหัสผิดพลาด"; diff --git a/NearDrop/uk.lproj/Localizable.strings b/NearDrop/uk.lproj/Localizable.strings index 32161e4..42bd9e0 100644 --- a/NearDrop/uk.lproj/Localizable.strings +++ b/NearDrop/uk.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ відправляє Вам %2$@"; +"DeviceCurrentlySendingText" = "%1$@ вставив \"%2$@\" до вашого буфера обміну."; +"DeviceSendingText" = "%1$@ хоче вставити \"%2$@\" до буфера обміну вашого Mac."; + +"DeviceCurrentlySendingUrl" = "%1$@ відкрив \"%2$@\"."; +"DeviceSendingUrl" = "%1$@ хоче відкрити \"%2$@\" на вашому Mac."; + +"InsertedIntoClipboard" = "Вставлено"; /* No comment provided by engineer. */ "Error.Crypto" = "Помилка шифрування"; diff --git a/NearDrop/zh-Hans.lproj/Localizable.strings b/NearDrop/zh-Hans.lproj/Localizable.strings index f034ed2..fb123dd 100644 --- a/NearDrop/zh-Hans.lproj/Localizable.strings +++ b/NearDrop/zh-Hans.lproj/Localizable.strings @@ -9,6 +9,13 @@ /* No comment provided by engineer. */ "DeviceSendingFiles" = "%1$@ 正向你发送 %2$@"; +"DeviceCurrentlySendingText" = "%1$@ 已将 \"%2$@\" 插入到你的剪贴板。"; +"DeviceSendingText" = "%1$@ 想要将 \"%2$@\" 插入到你的 Mac 剪贴板。"; + +"DeviceCurrentlySendingUrl" = "%1$@ 已打开 \"%2$@\"。"; +"DeviceSendingUrl" = "%1$@ 想要在你的 Mac 上打开 \"%2$@\"。"; + +"InsertedIntoClipboard" = "已插入"; /* No comment provided by engineer. */ "Error.Crypto" = "加密出错"; diff --git a/NearbyShare/InboundNearbyConnection.swift b/NearbyShare/InboundNearbyConnection.swift index 7bf6e48..be72d94 100644 --- a/NearbyShare/InboundNearbyConnection.swift +++ b/NearbyShare/InboundNearbyConnection.swift @@ -21,6 +21,7 @@ class InboundNearbyConnection: NearbyConnection { private var cipherCommitment: Data? private var textPayloadID: Int64 = 0 + private var isPlainTextTransfer = false enum State { case initial, receivedConnectionRequest, sentUkeyServerInit, receivedUkeyClientFinish, sentConnectionResponse, sentPairedKeyResult, receivedPairedKeyResult, waitingForUserConsent, receivingFiles, disconnected @@ -130,9 +131,21 @@ class InboundNearbyConnection: NearbyConnection { override func processBytesPayload(payload: Data, id: Int64) throws -> Bool { if id == textPayloadID { - if let urlStr = String(data: payload, encoding: .utf8), let url = URL(string: urlStr) { - NSWorkspace.shared.open(url) + if let urlStr = String(data: payload, encoding: .utf8) { + + if isPlainTextTransfer { + // paste to clipboard + let pasteboard = NSPasteboard.general + pasteboard.clearContents() + pasteboard.setString(urlStr, forType: .string) + + NearbyConnectionManager.shared.mainAppDelegate?.showCopiedToClipboardAlert() + } + else if let url = URL(string: urlStr) { + NSWorkspace.shared.open(url) + } } + try sendDisconnectionAndDisconnect() return true } else if let fileInfo = transferredFiles[id] { @@ -151,14 +164,23 @@ class InboundNearbyConnection: NearbyConnection { } private func processConnectionRequestFrame(_ frame: Location_Nearby_Connections_OfflineFrame) throws { + guard frame.hasV1 && frame.v1.hasConnectionRequest && frame.v1.connectionRequest.hasEndpointInfo else { throw NearbyError.requiredFieldMissing("connectionRequest.endpointInfo") } + guard case .connectionRequest = frame.v1.type else { throw NearbyError.protocolError("Unexpected frame type \(frame.v1.type)") } + let endpointInfo = frame.v1.connectionRequest.endpointInfo + guard endpointInfo.count > 17 else { throw NearbyError.protocolError("Endpoint info too short") } + let deviceNameLength = Int(endpointInfo[17]) + guard endpointInfo.count >= deviceNameLength + 18 else { throw NearbyError.protocolError("Endpoint info too short to contain the device name") } + guard let deviceName = String(data: endpointInfo[18 ..< (18 + deviceNameLength)], encoding: .utf8) else { throw NearbyError.protocolError("Device name is not valid UTF-8") } + let rawDeviceType = Int(endpointInfo[0] & 7) >> 1 + remoteDeviceInfo = RemoteDeviceInfo(name: deviceName, type: RemoteDeviceInfo.DeviceType.fromRawValue(value: rawDeviceType)) currentState = .receivedConnectionRequest } @@ -329,32 +351,29 @@ class InboundNearbyConnection: NearbyConnection { DispatchQueue.main.async { self.delegate?.obtainUserConsent(for: metadata, from: self.remoteDeviceInfo!, connection: self) } - } else if frame.v1.introduction.textMetadata.count == 1 { - let meta = frame.v1.introduction.textMetadata[0] - if case .url = meta.type { - let metadata = TransferMetadata(files: [], id: id, pinCode: pinCode, textDescription: meta.textTitle) - textPayloadID = meta.payloadID + } else if let textMetadata = frame.v1.introduction.textMetadata.first { + + if textMetadata.type == .url || textMetadata.type == .text { + + let isClipboardText = textMetadata.type == .text + + let metadata = TransferMetadata(files: [], id: id, pinCode: pinCode, textDescription: textMetadata.textTitle, transferType: isClipboardText ? .text : .url) + textPayloadID = textMetadata.payloadID + + if isClipboardText{ + isPlainTextTransfer = true + } + DispatchQueue.main.async { self.delegate?.obtainUserConsent(for: metadata, from: self.remoteDeviceInfo!, connection: self) } - } else if case .text = meta.type { - let saveDirectory = SaveFilesManager.shared.getSaveDirectory() - - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd HH.mm.ss" - let dest = makeFileDestinationURL(saveDirectory.appendingPathComponent("\(dateFormatter.string(from: Date())).txt")) - let info = InternalFileInfo(meta: FileMetadata(name: dest.lastPathComponent, size: meta.size, mimeType: "text/plain"), - payloadID: meta.payloadID, - destinationURL: dest) - transferredFiles[meta.payloadID] = info - DispatchQueue.main.async { - self.delegate?.obtainUserConsent(for: TransferMetadata(files: [info.meta], id: self.id, pinCode: self.pinCode), from: self.remoteDeviceInfo!, connection: self) - } - } else { + } + else { rejectTransfer(with: .unsupportedAttachmentType) } } else { rejectTransfer(with: .unsupportedAttachmentType) + } } @@ -409,6 +428,9 @@ class InboundNearbyConnection: NearbyConnection { } private func rejectTransfer(with reason: Sharing_Nearby_ConnectionResponseFrame.Status = .reject) { + + log("Rejecting transfer because of \( reason)") + var frame = Sharing_Nearby_Frame() frame.version = .v1 frame.v1.type = .response diff --git a/NearbyShare/NearbyConnectionManager.swift b/NearbyShare/NearbyConnectionManager.swift index 53c0c40..1a4b080 100644 --- a/NearbyShare/NearbyConnectionManager.swift +++ b/NearbyShare/NearbyConnectionManager.swift @@ -66,12 +66,20 @@ public struct TransferMetadata { public let id: String public let pinCode: String? public let textDescription: String? + public let type: TransferType - init(files: [FileMetadata], id: String, pinCode: String?, textDescription: String? = nil) { + init(files: [FileMetadata], id: String, pinCode: String?, textDescription: String? = nil, transferType: TransferType = .file) { self.files = files self.id = id self.pinCode = pinCode self.textDescription = textDescription + self.type = transferType + } + + public enum TransferType { + case file + case text + case url } } @@ -137,6 +145,7 @@ public protocol MainAppDelegate { func obtainUserConsent(for transfer: TransferMetadata, from device: RemoteDeviceInfo) func incomingTransfer(id: String, didFinishWith error: Error?) func showFirewallAlert() + func showCopiedToClipboardAlert() } public protocol ShareExtensionDelegate: AnyObject {