Implements attachment previewing
This commit is contained in:
@@ -114,6 +114,29 @@ final class XPCClient
|
||||
let req = makeRequest(method: "SendMessage", arguments: args)
|
||||
guard let reply = try await sendSync(req), xpc_get_type(reply) == XPC_TYPE_DICTIONARY else { throw Error.typeError }
|
||||
}
|
||||
|
||||
public func downloadAttachment(attachmentId: String, preview: Bool) async throws {
|
||||
var args: [String: xpc_object_t] = [:]
|
||||
args["attachment_id"] = xpcString(attachmentId)
|
||||
args["preview"] = xpcString(preview ? "true" : "false")
|
||||
|
||||
let req = makeRequest(method: "DownloadAttachment", arguments: args)
|
||||
_ = try await sendSync(req)
|
||||
}
|
||||
|
||||
public func openAttachmentFileHandle(attachmentId: String, preview: Bool) async throws -> FileHandle {
|
||||
var args: [String: xpc_object_t] = [:]
|
||||
args["attachment_id"] = xpcString(attachmentId)
|
||||
args["preview"] = xpcString(preview ? "true" : "false")
|
||||
|
||||
let req = makeRequest(method: "OpenAttachmentFd", arguments: args)
|
||||
guard let reply = try await sendSync(req), xpc_get_type(reply) == XPC_TYPE_DICTIONARY else { throw Error.typeError }
|
||||
|
||||
let fd = xpc_dictionary_dup_fd(reply, "fd")
|
||||
if fd < 0 { throw Error.typeError }
|
||||
|
||||
return FileHandle(fileDescriptor: fd, closeOnDealloc: true)
|
||||
}
|
||||
|
||||
// MARK: - Types
|
||||
|
||||
|
||||
Reference in New Issue
Block a user