osx: implements quicklook
This commit is contained in:
@@ -146,13 +146,33 @@ final class XPCClient
|
||||
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 {
|
||||
public func getAttachmentInfo(attachmentId: String) async throws -> AttachmentInfo {
|
||||
var args: [String: xpc_object_t] = [:]
|
||||
args["attachment_id"] = xpcString(attachmentId)
|
||||
|
||||
let req = makeRequest(method: "GetAttachmentInfo", arguments: args)
|
||||
guard let reply = try await sendSync(req), xpc_get_type(reply) == XPC_TYPE_DICTIONARY else { throw Error.typeError }
|
||||
|
||||
return AttachmentInfo(
|
||||
path: reply["path"] ?? "",
|
||||
previewPath: reply["preview_path"] ?? "",
|
||||
isDownloaded: reply["is_downloaded"] ?? false,
|
||||
isPreviewDownloaded: reply["is_preview_downloaded"] ?? false
|
||||
)
|
||||
}
|
||||
|
||||
public func downloadAttachment(attachmentId: String, preview: Bool, awaitCompletion: Bool = false) 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)
|
||||
|
||||
if awaitCompletion {
|
||||
// Wait for downloaded event
|
||||
let _ = await eventStream().first { $0 == .attachmentDownloaded(attachmentId: attachmentId) }
|
||||
}
|
||||
}
|
||||
|
||||
public func uploadAttachment(path: String) async throws -> String {
|
||||
@@ -200,6 +220,14 @@ final class XPCClient
|
||||
}
|
||||
|
||||
// MARK: - Types
|
||||
|
||||
struct AttachmentInfo: Decodable
|
||||
{
|
||||
let path: String
|
||||
let previewPath: String
|
||||
let isDownloaded: Bool
|
||||
let isPreviewDownloaded: Bool
|
||||
}
|
||||
|
||||
enum Error: Swift.Error
|
||||
{
|
||||
@@ -209,7 +237,7 @@ final class XPCClient
|
||||
case connectionError
|
||||
}
|
||||
|
||||
enum Signal
|
||||
enum Signal: Equatable
|
||||
{
|
||||
case conversationsUpdated
|
||||
case messagesUpdated(conversationId: String)
|
||||
|
||||
@@ -76,6 +76,22 @@ extension Array: XPCConvertible where Element: XPCConvertible
|
||||
}
|
||||
}
|
||||
|
||||
extension Bool: XPCConvertible
|
||||
{
|
||||
static func fromXPC(_ value: xpc_object_t) -> Bool? {
|
||||
if xpc_get_type(value) == XPC_TYPE_BOOL {
|
||||
return xpc_bool_get_value(value)
|
||||
}
|
||||
|
||||
if xpc_get_type(value) == XPC_TYPE_STRING {
|
||||
guard let cstr = xpc_string_get_string_ptr(value) else { return nil }
|
||||
return strcmp(cstr, "true") == 0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
extension xpc_object_t
|
||||
{
|
||||
func getObject(_ key: String) -> xpc_object_t? {
|
||||
|
||||
Reference in New Issue
Block a user