Skip to content

Commit

Permalink
added optional parameter "filename" for SaveFileIntent
Browse files Browse the repository at this point in the history
  • Loading branch information
hosy committed Sep 23, 2019
1 parent 832df8a commit 067ccd9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ownCloud/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>This permission is needed for uploading media files to your server.</string>
<key>NSCameraUsageDescription</key>
<string>This permission is needed to scan documents.</string>
<key>NSFaceIDUsageDescription</key>
<string>Unlock the app without entering the passcode.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>This permission is needed to upload photos and videos from your photo library.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This permission is needed to upload photos and videos from your photo library.</string>
<key>NSCameraUsageDescription</key>
<string>This permission is needed to scan documents.</string>
<key>NSUserActivityTypes</key>
<array>
<string>CreateFolderIntent</string>
Expand Down
38 changes: 36 additions & 2 deletions ownCloudAppShared/Intent/Intents.intentdefinition
Original file line number Diff line number Diff line change
Expand Up @@ -840,10 +840,10 @@
<key>INIntentKeyParameter</key>
<string>file</string>
<key>INIntentLastParameterTag</key>
<integer>7</integer>
<integer>8</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>path,file,account</key>
<key>path,file,account,filename</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
Expand Down Expand Up @@ -1007,6 +1007,40 @@
<key>INIntentParameterType</key>
<string>Object</string>
</dict>
<dict>
<key>INIntentParameterDisplayName</key>
<string>File Name (without file extension)</string>
<key>INIntentParameterDisplayNameID</key>
<string>B1lmXQ</string>
<key>INIntentParameterDisplayPriority</key>
<integer>4</integer>
<key>INIntentParameterMetadata</key>
<dict>
<key>INIntentParameterMetadataCapitalization</key>
<string>Sentences</string>
</dict>
<key>INIntentParameterName</key>
<string>filename</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>Optinal file name for saving file</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>b4VIz0</string>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
</array>
<key>INIntentParameterSupportsResolution</key>
<true/>
<key>INIntentParameterTag</key>
<integer>8</integer>
<key>INIntentParameterType</key>
<string>String</string>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
Expand Down
18 changes: 17 additions & 1 deletion ownCloudAppShared/Intent/SaveFileIntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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, *)
Expand Down

0 comments on commit 067ccd9

Please sign in to comment.