From 067ccd93559e4bf51efac46ee4db76b4b9c4ab7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Hu=CC=88hne?= Date: Mon, 23 Sep 2019 10:16:51 +0200 Subject: [PATCH] added optional parameter "filename" for SaveFileIntent --- ownCloud/Resources/Info.plist | 4 +- .../Intent/Intents.intentdefinition | 38 ++++++++++++++++++- .../Intent/SaveFileIntentHandler.swift | 18 ++++++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/ownCloud/Resources/Info.plist b/ownCloud/Resources/Info.plist index 4fc5394f5..2c257ca04 100644 --- a/ownCloud/Resources/Info.plist +++ b/ownCloud/Resources/Info.plist @@ -54,14 +54,14 @@ NSAppleMusicUsageDescription This permission is needed for uploading media files to your server. + NSCameraUsageDescription + This permission is needed to scan documents. NSFaceIDUsageDescription Unlock the app without entering the passcode. NSPhotoLibraryAddUsageDescription This permission is needed to upload photos and videos from your photo library. NSPhotoLibraryUsageDescription This permission is needed to upload photos and videos from your photo library. - NSCameraUsageDescription - This permission is needed to scan documents. NSUserActivityTypes CreateFolderIntent diff --git a/ownCloudAppShared/Intent/Intents.intentdefinition b/ownCloudAppShared/Intent/Intents.intentdefinition index f40db9dab..4b8aefc82 100644 --- a/ownCloudAppShared/Intent/Intents.intentdefinition +++ b/ownCloudAppShared/Intent/Intents.intentdefinition @@ -840,10 +840,10 @@ INIntentKeyParameter file INIntentLastParameterTag - 7 + 8 INIntentManagedParameterCombinations - path,file,account + path,file,account,filename INIntentParameterCombinationSupportsBackgroundExecution @@ -1007,6 +1007,40 @@ INIntentParameterType Object + + INIntentParameterDisplayName + File Name (without file extension) + INIntentParameterDisplayNameID + B1lmXQ + INIntentParameterDisplayPriority + 4 + INIntentParameterMetadata + + INIntentParameterMetadataCapitalization + Sentences + + INIntentParameterName + filename + INIntentParameterPromptDialogs + + + INIntentParameterPromptDialogCustom + + INIntentParameterPromptDialogFormatString + Optinal file name for saving file + INIntentParameterPromptDialogFormatStringID + b4VIz0 + INIntentParameterPromptDialogType + Primary + + + INIntentParameterSupportsResolution + + INIntentParameterTag + 8 + INIntentParameterType + String + INIntentResponse diff --git a/ownCloudAppShared/Intent/SaveFileIntentHandler.swift b/ownCloudAppShared/Intent/SaveFileIntentHandler.swift index aa3773f67..43d7dcfbf 100644 --- a/ownCloudAppShared/Intent/SaveFileIntentHandler.swift +++ b/ownCloudAppShared/Intent/SaveFileIntentHandler.swift @@ -37,7 +37,15 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling { if error == nil, let core = core { self.itemTracking = core.trackItem(atPath: path, trackingHandler: { (error, item, isInitial) in if let targetItem = item { - if core.importFileNamed(file.filename, + var newFilename = file.filename + if let filename = intent.filename as NSString?, filename.length > 0, let defaultFilename = file.filename as NSString? { + let pathExtention = defaultFilename.pathExtension + if let changedFilename = filename.appendingPathExtension(pathExtention) { + newFilename = changedFilename + } + } + + if core.importFileNamed(newFilename, at: targetItem, from: fileURL, isSecurityScoped: true, @@ -106,6 +114,14 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling { completion(INFileResolutionResult.needsValue()) } } + + public func resolveFilename(for intent: SaveFileIntent, with completion: @escaping (INStringResolutionResult) -> Void) { + if let filename = intent.filename { + completion(INStringResolutionResult.success(with: filename)) + } else { + completion(INStringResolutionResult.needsValue()) + } + } } @available(iOS 13.0, watchOS 6.0, *)