From 9d71ed35b7bfc9459768091ebbabeeff2c60fe76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Mon, 18 Aug 2025 10:10:37 +0200 Subject: [PATCH] iOS: Fix share extension showed app introduction, share extension add cancel button, add browse button to settings --- NearbyShare/Util/SaveFilesManager.swift | 26 +++-- QuickDrop/Localizable.xcstrings | 107 ++++++++++++++++++++ QuickDropiOS/ContentView.swift | 29 +++++- iOSShareExtension/ShareViewController.swift | 4 + 4 files changed, 152 insertions(+), 14 deletions(-) diff --git a/NearbyShare/Util/SaveFilesManager.swift b/NearbyShare/Util/SaveFilesManager.swift index c41bcfa..b3868fc 100644 --- a/NearbyShare/Util/SaveFilesManager.swift +++ b/NearbyShare/Util/SaveFilesManager.swift @@ -124,17 +124,7 @@ public class SaveFilesManager { NSWorkspace.shared.activateFileViewerSelecting(filesFinishedDownloadingSinceLastRun) } #else - - let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first - #if !EXTENSION - if let documentsUrl = documentsUrl, let sharedUrl = URL(string: "shareddocuments://\(documentsUrl.path)"), UIApplication.shared.canOpenURL(sharedUrl) { - UIApplication.shared.open(sharedUrl, options: [:]) - } - else { - showAlert(title: "CouldNotOpenDocumentsFolder", message: "CouldNotOpenDocumentsFolderDescription") - } - #endif - + openDownloadedFilesFolder() #endif // Clear the list of finished files @@ -144,6 +134,20 @@ public class SaveFilesManager { stopAccessingSecurityScopedResource() } + + public func openDownloadedFilesFolder() { + #if !EXTENSION + let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first + + if let documentsUrl = documentsUrl, let sharedUrl = URL(string: "shareddocuments://\(documentsUrl.path)"), UIApplication.shared.canOpenURL(sharedUrl) { + UIApplication.shared.open(sharedUrl, options: [:]) + } + else { + showAlert(title: "CouldNotOpenDocumentsFolder", message: "CouldNotOpenDocumentsFolderDescription") + } + #endif + } + public func stopAccessingSecurityScopedResource() { guard let url = securityScopeUrl else { diff --git a/QuickDrop/Localizable.xcstrings b/QuickDrop/Localizable.xcstrings index ea12896..9ea92ae 100644 --- a/QuickDrop/Localizable.xcstrings +++ b/QuickDrop/Localizable.xcstrings @@ -1282,6 +1282,113 @@ } } }, + "BrowseDownloadedFiles" : { + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "translated", + "value" : "تصفح الملفات التي تم تنزيلها" + } + }, + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "Heruntergeladene Dateien durchsuchen" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Browse Downloaded Files" + } + }, + "es" : { + "stringUnit" : { + "state" : "translated", + "value" : "Explorar archivos descargados" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Parcourir les fichiers téléchargés" + } + }, + "hu" : { + "stringUnit" : { + "state" : "translated", + "value" : "Letöltött fájlok böngészése" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "Sfoglia file scaricati" + } + }, + "ja" : { + "stringUnit" : { + "state" : "translated", + "value" : "ダウンロードしたファイルを表示" + } + }, + "ko" : { + "stringUnit" : { + "state" : "translated", + "value" : "다운로드된 파일 탐색" + } + }, + "nl" : { + "stringUnit" : { + "state" : "translated", + "value" : "Blader door gedownloade bestanden" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "translated", + "value" : "Navegar pelos arquivos baixados" + } + }, + "pt-PT" : { + "stringUnit" : { + "state" : "translated", + "value" : "Procurar Ficheiros Transferidos" + } + }, + "ro" : { + "stringUnit" : { + "state" : "translated", + "value" : "Navigați prin Fișierele Descărcate" + } + }, + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Просмотр загруженных файлов" + } + }, + "th" : { + "stringUnit" : { + "state" : "translated", + "value" : "เรียกดูไฟล์ที่ดาวน์โหลด" + } + }, + "uk" : { + "stringUnit" : { + "state" : "translated", + "value" : "Переглянути завантажені файли" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "浏览已下载的文件" + } + } + } + }, "Cancel" : { "extractionState" : "manual", "localizations" : { diff --git a/QuickDropiOS/ContentView.swift b/QuickDropiOS/ContentView.swift index 9d32e98..ab3575e 100644 --- a/QuickDropiOS/ContentView.swift +++ b/QuickDropiOS/ContentView.swift @@ -13,8 +13,15 @@ struct ContentView: View { var body: some View { AppRootView(isPlus: .constant(true), phoneView: { DeviceListView() + .environment(\.sheetActive, isShareExtension()) }, settingsView: { - EmptyView() + CustomSection { + LUIButton { + SaveFilesManager.shared.openDownloadedFilesFolder() + } label: { + NavigationLinkLabel(imageName: "folder.fill", text: "BrowseDownloadedFiles") + } + } }) } } @@ -31,7 +38,7 @@ struct DeviceListView: View { var body: some View { - NavigationSubView(header: "QuickDrop ") { + NavigationSubView(header: "QuickDrop ", navigationBarLayout: isShareExtension() ? .SmallOnlyAlways : .Default) { VStack(alignment: .leading, spacing: 8) { @@ -117,7 +124,14 @@ struct DeviceListView: View { } .padding(.vertical, 16) } - .navigationBarItems(trailing: LUISettingsButton()) + .navigationBarItems(trailing: ZStack { + if isShareExtension() { + XButton(action: { NearbyConnectionManager.shared.attachments?.closeView?() }) + } + else { + LUISettingsButton() + } + }) } } @@ -176,6 +190,15 @@ struct DeviceButton: View { } +func isShareExtension() -> Bool { + #if EXTENSION + return true + #else + return false + #endif +} + + //extension DeviceListView { // static var preview: DeviceListView { // let model = SendModel() diff --git a/iOSShareExtension/ShareViewController.swift b/iOSShareExtension/ShareViewController.swift index c1eadd8..102486d 100644 --- a/iOSShareExtension/ShareViewController.swift +++ b/iOSShareExtension/ShareViewController.swift @@ -7,6 +7,7 @@ import UIKit import SwiftUI +import LUI class ShareViewController: UIViewController { override func viewDidLoad() { @@ -27,6 +28,9 @@ class ShareViewController: UIViewController { } }) + // skip introduction for share extension + LUISettings.sharedInstance.appLaunchedBefore = true + // Replace with your app’s SwiftUI entry view let contentView = ContentView()