Skip to content

Commit

Permalink
- SaveFileIntentHandler: no longer use File Provider for uploading
Browse files Browse the repository at this point in the history
- Intents.intentdefinition: remove File Provider upload option for SaveIntentHandler
  • Loading branch information
felix-schwarz committed Sep 9, 2024
1 parent 919eef4 commit 5fcd9b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 114 deletions.
56 changes: 4 additions & 52 deletions ownCloud Intents/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>21E230</string>
<string>23G93</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>13E113</string>
<string>16A5230g</string>
<key>INIntentDefinitionToolsVersion</key>
<string>13.3</string>
<string>16.0</string>
<key>INIntents</key>
<array>
<dict>
Expand Down Expand Up @@ -943,7 +943,7 @@
<integer>13</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>path,file,account,filename,fileextension,shouldOverwrite,waitForCompletion</key>
<key>path,file,account,filename,fileextension,shouldOverwrite</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
Expand Down Expand Up @@ -1219,54 +1219,6 @@
<key>INIntentParameterType</key>
<string>Boolean</string>
</dict>
<dict>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>Wait for upload to complete</string>
<key>INIntentParameterDisplayNameID</key>
<string>X18VvP</string>
<key>INIntentParameterDisplayPriority</key>
<integer>7</integer>
<key>INIntentParameterMetadata</key>
<dict>
<key>INIntentParameterMetadataFalseDisplayName</key>
<string>false</string>
<key>INIntentParameterMetadataFalseDisplayNameID</key>
<string>7Zv2I0</string>
<key>INIntentParameterMetadataTrueDisplayName</key>
<string>true</string>
<key>INIntentParameterMetadataTrueDisplayNameID</key>
<string>w1TCyX</string>
</dict>
<key>INIntentParameterName</key>
<string>waitForCompletion</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Configuration</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>Wait for upload to complete before continuing</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>Wt9Wgt</string>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
</array>
<key>INIntentParameterSupportsResolution</key>
<true/>
<key>INIntentParameterTag</key>
<integer>13</integer>
<key>INIntentParameterType</key>
<string>Boolean</string>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
Expand Down
82 changes: 20 additions & 62 deletions ownCloud Intents/SaveFileIntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling, OCCoreDele
}
}
let filePath = path + newFilename
let waitForCompletion = (intent.waitForCompletion as? Bool) ?? false
let shouldOverwrite = (intent.shouldOverwrite as? Bool) ?? false

let completeWithCode = { (code: SaveFileIntentResponseCode) in
Expand Down Expand Up @@ -132,7 +131,7 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling, OCCoreDele
if error == nil, let targetItem = item {
// Check if file already exists
OCItemTracker(for: bookmark, at: .legacyRootPath(filePath), waitOnlineTimeout: 5) { (error, core, fileItem) in
if let core = core {
if core != nil {
if error == nil, let fileItem = fileItem {
// File already exists
if !shouldOverwrite {
Expand All @@ -147,26 +146,10 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling, OCCoreDele

OnBackgroundQueue {
if let parentItem = fileItem.parentItem(from: core) {
if waitForCompletion {
// Wait for completion: report local modification from extension
core.reportLocalModification(of: fileItem, parentItem: parentItem, withContentsOfFileAt: fileURL, isSecurityScoped: true, options: [OCCoreOption.importByCopying : true], placeholderCompletionHandler: nil, resultHandler: { (error, _, item, _) in
completeWithResult(error, item?.path)
})
} else {
// Delegate local modification report to File Provider
let fpServiceSession = OCFileProviderServiceSession(vault: core.vault)
self.fpServiceSession = fpServiceSession

let didStartSecurityScopedResource = fileURL.startAccessingSecurityScopedResource()

fpServiceSession.reportModificationThroughFileProvider(url: fileURL, as: fileItem.name, for: fileItem, to: parentItem, lastModifiedDate: nil, completion: { (error) in
completeWithResult(error, fileItem.path)

if didStartSecurityScopedResource {
fileURL.stopAccessingSecurityScopedResource()
}
})
}
// Wait for completion: report local modification from extension
core.reportLocalModification(of: fileItem, parentItem: parentItem, withContentsOfFileAt: fileURL, isSecurityScoped: true, options: [OCCoreOption.importByCopying : true], placeholderCompletionHandler: nil, resultHandler: { (error, _, item, _) in
completeWithResult(error, item?.path)
})
} else {
completeWithCode(.pathFailure)
}
Expand All @@ -178,39 +161,22 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling, OCCoreDele
}
} else {
// File does NOT exist => import file
if waitForCompletion {
// Wait for completion: import from extension
OCCoreManager.shared.requestCore(for: bookmark, setup: { (core, error) in
core?.delegate = self
}, completionHandler: { (core, error) in
if let core = core {
self.core = core

OnBackgroundQueue {
core.importFileNamed(newFilename, at: targetItem, from: fileURL, isSecurityScoped: true, options: [OCCoreOption.importByCopying : true], placeholderCompletionHandler: nil, resultHandler: { (error, _, item, _) in
completeWithResult(error, item?.path)
})
}
} else {
completeWithResult(error, nil)
// Wait for completion: import from extension
OCCoreManager.shared.requestCore(for: bookmark, setup: { (core, error) in
core?.delegate = self
}, completionHandler: { (core, error) in
if let core = core {
self.core = core

OnBackgroundQueue {
core.importFileNamed(newFilename, at: targetItem, from: fileURL, isSecurityScoped: true, options: [OCCoreOption.importByCopying : true], placeholderCompletionHandler: nil, resultHandler: { (error, _, item, _) in
completeWithResult(error, item?.path)
})
}
})
} else {
// Delegate import to File Provider
let fpServiceSession = OCFileProviderServiceSession(vault: core.vault)
self.fpServiceSession = fpServiceSession

let didStartSecurityScopedResource = fileURL.startAccessingSecurityScopedResource()

fpServiceSession.importThroughFileProvider(url: fileURL, as: newFilename, to: targetItem, completion: { (error, _) in
let itemPath = (targetItem.path as NSString? ?? path as NSString?)?.appendingPathComponent(newFilename)
completeWithResult(error, itemPath)

if didStartSecurityScopedResource {
fileURL.stopAccessingSecurityScopedResource()
}
})
}
} else {
completeWithResult(error, nil)
}
})
}
} else {
failWithError(error)
Expand Down Expand Up @@ -276,14 +242,6 @@ public class SaveFileIntentHandler: NSObject, SaveFileIntentHandling, OCCoreDele
}
completion(INBooleanResolutionResult.success(with: shouldOverwrite))
}

func resolveWaitForCompletion(for intent: SaveFileIntent, with completion: @escaping (INBooleanResolutionResult) -> Void) {
var waitForCompletion = false
if let doWait = intent.waitForCompletion?.boolValue {
waitForCompletion = doWait
}
completion(INBooleanResolutionResult.success(with: waitForCompletion))
}
}

@available(iOS 13.0, *)
Expand Down

0 comments on commit 5fcd9b8

Please sign in to comment.