Convert createFolder to async await.

This commit is contained in:
Brent Simmons
2024-03-26 22:18:48 -07:00
parent 91b0e7158a
commit c68738bf64
12 changed files with 109 additions and 58 deletions

View File

@@ -66,33 +66,33 @@ import Core
tell account X to make new folder at end with properties {name:"new folder name"}
*/
@MainActor class func handleCreateElement(command:NSCreateCommand) -> Any? {
guard command.isCreateCommand(forClass:"fold") else { return nil }
let name = command.property(forKey:"name") as? String ?? ""
guard command.isCreateCommand(forClass:"fold") else { return nil }
let name = command.property(forKey:"name") as? String ?? ""
// some combination of the tell target and the location specifier ("in" or "at")
// identifies where the new folder should be created
let (account, folder) = command.accountAndFolderForNewChild()
guard folder == nil else {
print("support for folders within folders is NYI");
return nil
}
// some combination of the tell target and the location specifier ("in" or "at")
// identifies where the new folder should be created
let (account, folder) = command.accountAndFolderForNewChild()
guard folder == nil else {
print("support for folders within folders is NYI");
return nil
}
command.suspendExecution()
account.addFolder(name) { result in
switch result {
case .success(let folder):
Task { @MainActor in
do {
let folder = try await account.addFolder(name)
let scriptableAccount = ScriptableAccount(account)
let scriptableFolder = ScriptableFolder(folder, container:scriptableAccount)
command.resumeExecution(withResult:scriptableFolder.objectSpecifier)
case .failure:
} catch {
command.resumeExecution(withResult:nil)
}
}
return nil
}
return nil
}
// MARK: --- Scriptable elements ---
@objc(feeds)