Skip to content

Commit

Permalink
[fix/shortcut-save-file] (#624)
Browse files Browse the repository at this point in the history
* #622 if a file already exists, the given file could not be saved

* added parameter to SaveIntent to decide if file could be overwritten or not, if already exists
  • Loading branch information
hosy authored Feb 26, 2020
1 parent 7056131 commit 7fb0668
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 44 deletions.
2 changes: 2 additions & 0 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
3913213822946E5E00EF88F4 /* FileListTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3913213722946E5E00EF88F4 /* FileListTableViewController.swift */; };
3913214D22956D5700EF88F4 /* LibraryTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3913214A22956D5700EF88F4 /* LibraryTableViewController.swift */; };
39265BB223D9987500B0C4CA /* MediaEditingAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39265BB123D9987500B0C4CA /* MediaEditingAction.swift */; };
393D2B3F23FEB6DC00ED4F8C /* DispatchQueueTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC4FEAE9209E48E800D4476B /* DispatchQueueTools.swift */; };
3940C4F02326985B008227AE /* GetAccountIntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3940C4EF2326985B008227AE /* GetAccountIntentHandler.swift */; };
394804DA225CBDBA00AA8183 /* BreadCrumbTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 394804D9225CBDBA00AA8183 /* BreadCrumbTableViewController.swift */; };
394A0AED22EEE32C00603813 /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39A7138222E79C6700089423 /* IntentHandler.swift */; };
Expand Down Expand Up @@ -3466,6 +3467,7 @@
397754E223279EED00119FCB /* OCItem+Extension.swift in Sources */,
39BE385D23435AFE0062A2FE /* String+Extension.swift in Sources */,
39E6DE86233CDF1E008DAE04 /* OCItemTracker.swift in Sources */,
393D2B3F23FEB6DC00ED4F8C /* DispatchQueueTools.swift in Sources */,
3984F5712319202200DC2639 /* DeletePathItemIntentHandler.swift in Sources */,
39F689AC22F0206900E63429 /* OCBookmark+Extension.swift in Sources */,
395E16FF22F172C900DE89A1 /* CreateFolderIntentHandler.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions ownCloud/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
<string>This permission is needed to upload photos and videos from your photo library.</string>
<key>NSUserActivityTypes</key>
<array>
<string>com.owncloud.ios-app.openAccount</string>
<string>com.owncloud.ios-app.openItem</string>
<string>CreateFolderIntent</string>
<string>DeletePathItemIntent</string>
<string>GetAccountIntent</string>
Expand All @@ -75,6 +73,8 @@
<string>GetFileIntent</string>
<string>PathExistsIntent</string>
<string>SaveFileIntent</string>
<string>com.owncloud.ios-app.openAccount</string>
<string>com.owncloud.ios-app.openItem</string>
</array>
<key>OCAppGroupIdentifier</key>
<string>group.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
Expand Down
98 changes: 75 additions & 23 deletions ownCloudAppShared/Intent/Base.lproj/Intents.intentdefinition
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@
<key>INIntentDefinitionNamespace</key>
<string>K5U8aR</string>
<key>INIntentDefinitionSystemVersion</key>
<string>19B88</string>
<string>19D76</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>11B53</string>
<string>11C504</string>
<key>INIntentDefinitionToolsVersion</key>
<string>11.2.1</string>
<string>11.3.1</string>
<key>INIntents</key>
<array>
<dict>
Expand Down Expand Up @@ -214,11 +214,11 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>y8oko2</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>VSQYEZ</string>
<key>INIntentResponseCodeName</key>
Expand Down Expand Up @@ -609,11 +609,11 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>fjiVU2</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>0pF5fq</string>
<key>INIntentResponseCodeName</key>
Expand Down Expand Up @@ -854,11 +854,11 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>rzbAOP</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>8a8rsQ</string>
<key>INIntentResponseCodeName</key>
Expand Down Expand Up @@ -912,10 +912,10 @@
<key>INIntentKeyParameter</key>
<string>file</string>
<key>INIntentLastParameterTag</key>
<integer>9</integer>
<integer>11</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>path,file,account,filename,fileextension</key>
<key>path,file,account,filename,fileextension,shouldOverwrite</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
Expand Down Expand Up @@ -1147,6 +1147,46 @@
<key>INIntentParameterType</key>
<string>String</string>
</dict>
<dict>
<key>INIntentParameterDisplayName</key>
<string>Overwrite existing File</string>
<key>INIntentParameterDisplayNameID</key>
<string>YNY6aQ</string>
<key>INIntentParameterDisplayPriority</key>
<integer>6</integer>
<key>INIntentParameterMetadata</key>
<dict>
<key>INIntentParameterMetadataFalseDisplayName</key>
<string>false</string>
<key>INIntentParameterMetadataFalseDisplayNameID</key>
<string>pDN16g</string>
<key>INIntentParameterMetadataTrueDisplayName</key>
<string>true</string>
<key>INIntentParameterMetadataTrueDisplayNameID</key>
<string>icA1AQ</string>
</dict>
<key>INIntentParameterName</key>
<string>shouldOverwrite</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>Overwrite file if already exists</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>X2zTIZ</string>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
</array>
<key>INIntentParameterSupportsResolution</key>
<true/>
<key>INIntentParameterTag</key>
<integer>11</integer>
<key>INIntentParameterType</key>
<string>Boolean</string>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
Expand Down Expand Up @@ -1212,16 +1252,28 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>81IjYk</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>yTzyi1</string>
<key>INIntentResponseCodeName</key>
<string>unlicensed</string>
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>The file already exists and overwrite file is disabled.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>UaOocE</string>
<key>INIntentResponseCodeFormatString</key>
<string>The file already exists and overwrite file is disabled.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>GUKqkE</string>
<key>INIntentResponseCodeName</key>
<string>overwriteFailure</string>
</dict>
</array>
<key>INIntentResponseLastParameterTag</key>
<integer>1</integer>
Expand Down Expand Up @@ -1499,11 +1551,11 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>X0Zskf</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>bfU2dy</string>
<key>INIntentResponseCodeName</key>
Expand Down Expand Up @@ -1740,11 +1792,11 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>idUnAy</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>lNNcvh</string>
<key>INIntentResponseCodeName</key>
Expand Down Expand Up @@ -1987,11 +2039,11 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>65dv1W</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>9tIXKj</string>
<key>INIntentResponseCodeName</key>
Expand Down Expand Up @@ -2253,11 +2305,11 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>sKUo1c</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>1rpPPR</string>
<key>INIntentResponseCodeName</key>
Expand Down Expand Up @@ -2408,11 +2460,11 @@
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>ceG0fs</string>
<key>INIntentResponseCodeFormatString</key>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings > Pro Features &gt; Shortcuts.</string>
<string>This action is a Pro Feature and currently not unlocked. For more information and available unlocking options, please see Settings &gt; Pro Features &gt; Shortcuts.</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>GJ25u2</string>
<key>INIntentResponseCodeName</key>
Expand Down
64 changes: 45 additions & 19 deletions ownCloudAppShared/Intent/SaveFileIntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,46 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling {
newFilename = changedFilename
}
}
let filePath = path + newFilename

// Check if given save path exists
OCItemTracker().item(for: bookmark, at: path) { (error, core, item) in
if error == nil, let targetItem = item {
if core?.importFileNamed(newFilename,
at: targetItem,
from: fileURL,
isSecurityScoped: true,
options: [OCCoreOption.importByCopying : true],
placeholderCompletionHandler: { (error, item) in
if error != nil {
completion(SaveFileIntentResponse(code: .failure, userActivity: nil))
}
},
resultHandler: { (error, _ core, _ item, _) in
if error != nil {
completion(SaveFileIntentResponse(code: .failure, userActivity: nil))
} else {
completion(SaveFileIntentResponse.success(filePath: item?.path ?? ""))
}
}
) == nil {
completion(SaveFileIntentResponse(code: .failure, userActivity: nil))
// Check if file already exists
OCItemTracker().item(for: bookmark, at: filePath) { (error, core, fileItem) in
OnBackgroundQueue {
if error == nil, let core = core, let fileItem = fileItem, let parentItem = fileItem.parentItem(from: core) {
// File already exists
if intent.shouldOverwrite?.boolValue == true {
core.reportLocalModification(of: fileItem, parentItem: parentItem, withContentsOfFileAt: fileURL, isSecurityScoped: true, options: [OCCoreOption.importByCopying : true], placeholderCompletionHandler: nil,
resultHandler: { (error, _ core, _ item, _) in
if error != nil {
completion(SaveFileIntentResponse(code: .failure, userActivity: nil))
} else { completion(SaveFileIntentResponse.success(filePath: item?.path ?? ""))
}
})
} else {
completion(SaveFileIntentResponse(code: .overwriteFailure, userActivity: nil))
}
} else if core != nil {
// File does NOT exists => import file
core?.importFileNamed(newFilename,
at: targetItem,
from: fileURL,
isSecurityScoped: true,
options: [OCCoreOption.importByCopying : true],
placeholderCompletionHandler: nil,
resultHandler: { (error, _ core, _ item, _) in
if error != nil {
completion(SaveFileIntentResponse(code: .failure, userActivity: nil))
} else { completion(SaveFileIntentResponse.success(filePath: item?.path ?? ""))
}
}
)
} else {
completion(SaveFileIntentResponse(code: .failure, userActivity: nil))
}
}
}
} else if core != nil {
completion(SaveFileIntentResponse(code: .pathFailure, userActivity: nil))
Expand Down Expand Up @@ -131,6 +149,14 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling {
public func resolveFileextension(for intent: SaveFileIntent, with completion: @escaping (INStringResolutionResult) -> Void) {
completion(INStringResolutionResult.success(with: intent.fileextension ?? ""))
}

public func resolveShouldOverwrite(for intent: SaveFileIntent, with completion: @escaping (INBooleanResolutionResult) -> Void) {
var shouldOverwrite = false
if let overwrite = intent.shouldOverwrite?.boolValue {
shouldOverwrite = overwrite
}
completion(INBooleanResolutionResult.success(with: shouldOverwrite))
}
}

@available(iOS 13.0, *)
Expand Down

0 comments on commit 7fb0668

Please sign in to comment.