Private
Public Access
1
0

Implements attachment previewing

This commit is contained in:
2025-08-24 23:38:35 -07:00
parent 126a4cc55f
commit f0029d02e1
9 changed files with 500 additions and 178 deletions

View File

@@ -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