From 6b883e945723397e59828c34e13dcde8070325ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Sat, 17 May 2025 13:28:36 +0200 Subject: [PATCH] Add detection of unsupported file type --- NearDrop/AppDelegate.swift | 20 +++++++++++++++++++- NearDrop/Base.lproj/Localizable.strings | 1 + NearDrop/ar.lproj/Localizable.strings | 1 + NearDrop/de.lproj/Localizable.strings | 1 + NearDrop/es.lproj/Localizable.strings | 1 + NearDrop/fr.lproj/Localizable.strings | 1 + NearDrop/hu.lproj/Localizable.strings | 1 + NearDrop/it.lproj/Localizable.strings | 1 + NearDrop/ja.lproj/Localizable.strings | 1 + NearDrop/ko.lproj/Localizable.strings | 1 + NearDrop/nl.lproj/Localizable.strings | 1 + NearDrop/pt-BR.lproj/Localizable.strings | 1 + NearDrop/pt-PT.lproj/Localizable.strings | 1 + NearDrop/ro.lproj/Localizable.strings | 1 + NearDrop/ru.lproj/Localizable.strings | 1 + NearDrop/th.lproj/Localizable.strings | 1 + NearDrop/uk.lproj/Localizable.strings | 1 + NearDrop/zh-Hans.lproj/Localizable.strings | 1 + NearbyShare/InboundNearbyConnection.swift | 12 ++++++++++-- NearbyShare/NearbyConnectionManager.swift | 1 + 20 files changed, 47 insertions(+), 3 deletions(-) diff --git a/NearDrop/AppDelegate.swift b/NearDrop/AppDelegate.swift index 13f24e6..58740af 100644 --- a/NearDrop/AppDelegate.swift +++ b/NearDrop/AppDelegate.swift @@ -344,7 +344,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele } private func pressAcceptButton(transferID: String) { - if false || (!isPlusVersion() && transmissionCount() > 1) { + if (!isPlusVersion() && transmissionCount() > 1) { continueTransmission(accept: true, transferID: transferID, storeInTemp: true) log("Showing plus screen...") @@ -363,9 +363,27 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele BezelNotification.show(messageText: "InsertedIntoClipboard".localized(), icon: .clipboard) } } + + func showUnsupportedFileAlert(for device: RemoteDeviceInfo?) { + DispatchQueue.main.async { + + let alert = NSAlert() + alert.alertStyle = .critical + + alert.messageText = String(format: NSLocalizedString("TransferError", value: "Failed to receive files from %@", comment: ""), arguments: [device?.name ?? "??"]) + alert.informativeText = "UnsupportedFileType".localized() + + alert.addButton(withTitle: "InformDeveloper".localized()) + alert.addButton(withTitle: "CloseAlert".localized()) + + let _ = alert.runModal() + } + } func incomingTransfer(id: String, didFinishWith error: Error?) { + guard let transfer = activeIncomingTransfers[id] else { return } + if let error = error { var description = "" diff --git a/NearDrop/Base.lproj/Localizable.strings b/NearDrop/Base.lproj/Localizable.strings index 23adc0b..67aaff4 100644 --- a/NearDrop/Base.lproj/Localizable.strings +++ b/NearDrop/Base.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ wants to open \"%2$@\" on your Mac."; "InsertedIntoClipboard" = "Inserted"; +"UnsupportedFileType" = "The file you tried to send is currently not supported. Please send an error report."; /* No comment provided by engineer. */ "Error.Crypto" = "Encryption error"; diff --git a/NearDrop/ar.lproj/Localizable.strings b/NearDrop/ar.lproj/Localizable.strings index b929902..81cae06 100644 --- a/NearDrop/ar.lproj/Localizable.strings +++ b/NearDrop/ar.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "يرغب %1$@ في فتح \"%2$@\" على جهاز Mac الخاص بك."; "InsertedIntoClipboard" = "تم الإدراج"; +"UnsupportedFileType" = "الملف الذي حاولت إرساله غير مدعوم حالياً. يُرجى إرسال تقرير بالخطأ."; /* No comment provided by engineer. */ "Error.Crypto" = "خطأ في التشفير"; diff --git a/NearDrop/de.lproj/Localizable.strings b/NearDrop/de.lproj/Localizable.strings index f9003f2..8735759 100644 --- a/NearDrop/de.lproj/Localizable.strings +++ b/NearDrop/de.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ möchte \"%2$@\" auf deinem Mac öffnen."; "InsertedIntoClipboard" = "Eingefügt"; +"UnsupportedFileType" = "Die Datei, die du senden wolltest, wird derzeit nicht unterstützt. Bitte sende einen Fehlerbericht."; /* No comment provided by engineer. */ "Error.Crypto" = "Verschlüsselungsfehler"; diff --git a/NearDrop/es.lproj/Localizable.strings b/NearDrop/es.lproj/Localizable.strings index 70daaa2..4077a44 100644 --- a/NearDrop/es.lproj/Localizable.strings +++ b/NearDrop/es.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ quiere abrir \"%2$@\" en tu Mac."; "InsertedIntoClipboard" = "Insertado"; +"UnsupportedFileType" = "El archivo que intentaste enviar no es compatible actualmente. Por favor, envía un informe de error."; /* 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 16d648f..42b9a06 100644 --- a/NearDrop/fr.lproj/Localizable.strings +++ b/NearDrop/fr.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ souhaite ouvrir \"%2$@\" sur votre Mac."; "InsertedIntoClipboard" = "Inséré"; +"UnsupportedFileType" = "Le fichier que vous avez essayé d'envoyer n'est pas pris en charge actuellement. Veuillez envoyer un rapport d'erreur."; /* 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 15b7d4b..7472694 100644 --- a/NearDrop/hu.lproj/Localizable.strings +++ b/NearDrop/hu.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ meg szeretné nyitni a(z) \"%2$@\" hivatkozást a Mac-eden."; "InsertedIntoClipboard" = "Beillesztve"; +"UnsupportedFileType" = "A fájl, amelyet megpróbáltál küldeni, jelenleg nem támogatott. Kérjük, küldj hibajelentést."; /* 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 b362aa7..a5c2df7 100644 --- a/NearDrop/it.lproj/Localizable.strings +++ b/NearDrop/it.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ vuole aprire \"%2$@\" sul tuo Mac."; "InsertedIntoClipboard" = "Inserito"; +"UnsupportedFileType" = "Il file che hai provato a inviare non è attualmente supportato. Invia un rapporto di errore."; /* 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 33f6135..91380ab 100644 --- a/NearDrop/ja.lproj/Localizable.strings +++ b/NearDrop/ja.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ があなたの Mac で \"%2$@\" を開こうとしています。"; "InsertedIntoClipboard" = "挿入されました"; +"UnsupportedFileType" = "送信しようとしたファイルは現在サポートされていません。エラーレポートを送信してください。"; /* No comment provided by engineer. */ "Error.Crypto" = "暗号化エラー"; diff --git a/NearDrop/ko.lproj/Localizable.strings b/NearDrop/ko.lproj/Localizable.strings index 2df0076..ee29292 100644 --- a/NearDrop/ko.lproj/Localizable.strings +++ b/NearDrop/ko.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@이(가) Mac에서 \"%2$@\"을(를) 열려고 합니다."; "InsertedIntoClipboard" = "삽입됨"; +"UnsupportedFileType" = "보내려는 파일은 현재 지원되지 않습니다. 오류 보고서를 보내주세요."; /* No comment provided by engineer. */ "Error.Crypto" = "암호화 오류"; diff --git a/NearDrop/nl.lproj/Localizable.strings b/NearDrop/nl.lproj/Localizable.strings index e823854..998e69d 100644 --- a/NearDrop/nl.lproj/Localizable.strings +++ b/NearDrop/nl.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ wil \"%2$@\" openen op je Mac."; "InsertedIntoClipboard" = "Ingevoerd"; +"UnsupportedFileType" = "Het bestand dat je probeerde te verzenden, wordt momenteel niet ondersteund. Stuur een foutrapport."; /* 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 4283217..1239c23 100644 --- a/NearDrop/pt-BR.lproj/Localizable.strings +++ b/NearDrop/pt-BR.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ deseja abrir \"%2$@\" no seu Mac."; "InsertedIntoClipboard" = "Inserido"; +"UnsupportedFileType" = "O arquivo que você tentou enviar não é compatível no momento. Por favor, envie um relatório de erro."; /* 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 e60c76b..8bedd9d 100644 --- a/NearDrop/pt-PT.lproj/Localizable.strings +++ b/NearDrop/pt-PT.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ pretende abrir \"%2$@\" no seu Mac."; "InsertedIntoClipboard" = "Inserido"; +"UnsupportedFileType" = "O ficheiro que tentou enviar não é atualmente suportado. Por favor, envie um relatório de erro."; /* 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 7bdd9ea..36af03e 100644 --- a/NearDrop/ro.lproj/Localizable.strings +++ b/NearDrop/ro.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ dorește să deschidă \"%2$@\" pe Mac-ul tău."; "InsertedIntoClipboard" = "Inserat"; +"UnsupportedFileType" = "Fișierul pe care ai încercat să-l trimiți nu este momentan acceptat. Te rugăm să trimiți un raport de eroare."; /* 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 48d82ab..58e6f8b 100644 --- a/NearDrop/ru.lproj/Localizable.strings +++ b/NearDrop/ru.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ хочет открыть \"%2$@\" на вашем Mac."; "InsertedIntoClipboard" = "Вставлено"; +"UnsupportedFileType" = "Файл, который вы пытались отправить, в настоящее время не поддерживается. Пожалуйста, отправьте отчет об ошибке."; /* No comment provided by engineer. */ "Error.Crypto" = "Ошибка шифрования"; diff --git a/NearDrop/th.lproj/Localizable.strings b/NearDrop/th.lproj/Localizable.strings index 63df5c7..7ba1aae 100644 --- a/NearDrop/th.lproj/Localizable.strings +++ b/NearDrop/th.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ ต้องการเปิด \"%2$@\" บน Mac ของคุณ"; "InsertedIntoClipboard" = "แทรกแล้ว"; +"UnsupportedFileType" = "ไฟล์ที่คุณพยายามส่งยังไม่รองรับในขณะนี้ โปรดส่งรายงานข้อผิดพลาด"; /* No comment provided by engineer. */ "Error.Crypto" = "การเข้ารหัสผิดพลาด"; diff --git a/NearDrop/uk.lproj/Localizable.strings b/NearDrop/uk.lproj/Localizable.strings index 42bd9e0..8970e03 100644 --- a/NearDrop/uk.lproj/Localizable.strings +++ b/NearDrop/uk.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ хоче відкрити \"%2$@\" на вашому Mac."; "InsertedIntoClipboard" = "Вставлено"; +"UnsupportedFileType" = "Файл, який ви намагалися надіслати, наразі не підтримується. Будь ласка, надішліть звіт про помилку."; /* No comment provided by engineer. */ "Error.Crypto" = "Помилка шифрування"; diff --git a/NearDrop/zh-Hans.lproj/Localizable.strings b/NearDrop/zh-Hans.lproj/Localizable.strings index fb123dd..216b7d2 100644 --- a/NearDrop/zh-Hans.lproj/Localizable.strings +++ b/NearDrop/zh-Hans.lproj/Localizable.strings @@ -16,6 +16,7 @@ "DeviceSendingUrl" = "%1$@ 想要在你的 Mac 上打开 \"%2$@\"。"; "InsertedIntoClipboard" = "已插入"; +"UnsupportedFileType" = "您尝试发送的文件当前不受支持。请发送错误报告。"; /* No comment provided by engineer. */ "Error.Crypto" = "加密出错"; diff --git a/NearbyShare/InboundNearbyConnection.swift b/NearbyShare/InboundNearbyConnection.swift index ed076f4..bfb35f5 100644 --- a/NearbyShare/InboundNearbyConnection.swift +++ b/NearbyShare/InboundNearbyConnection.swift @@ -369,12 +369,20 @@ class InboundNearbyConnection: NearbyConnection { } } else { - rejectTransfer(with: .unsupportedAttachmentType) + rejectDueToUnsupportedFileType(frame) } } else { - rejectTransfer(with: .unsupportedAttachmentType) + rejectDueToUnsupportedFileType(frame) } } + + func rejectDueToUnsupportedFileType(_ frame: Sharing_Nearby_Frame) { + + log("Rejecting transfer due to unsupported file type. Frame is \(frame.debugDescription)") + + NearbyConnectionManager.shared.mainAppDelegate?.showUnsupportedFileAlert(for: remoteDeviceInfo) + rejectTransfer(with: .unsupportedAttachmentType) + } func submitUserConsent(accepted: Bool, storeInTemp: Bool = false) { DispatchQueue.global(qos: .utility).async { diff --git a/NearbyShare/NearbyConnectionManager.swift b/NearbyShare/NearbyConnectionManager.swift index 1a4b080..7ed70b9 100644 --- a/NearbyShare/NearbyConnectionManager.swift +++ b/NearbyShare/NearbyConnectionManager.swift @@ -146,6 +146,7 @@ public protocol MainAppDelegate { func incomingTransfer(id: String, didFinishWith error: Error?) func showFirewallAlert() func showCopiedToClipboardAlert() + func showUnsupportedFileAlert(for: RemoteDeviceInfo?) } public protocol ShareExtensionDelegate: AnyObject {