From 29fa33b1c6d4418a32869d988e840b2af72ce866 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sat, 6 May 2023 20:25:44 +0100 Subject: [PATCH] Publish server info --- protocol.prs | 1 + src/libnotify_actor.nim | 13 +++++++++++++ src/protocol.nim | 10 ++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/protocol.prs b/protocol.prs index 02a8f9d..56ee388 100644 --- a/protocol.prs +++ b/protocol.prs @@ -1,3 +1,4 @@ version 1. Attrs = {symbol: string ...:...} . Notify = . +ServerInfo = . diff --git a/src/libnotify_actor.nim b/src/libnotify_actor.nim index 9270949..2b47973 100644 --- a/src/libnotify_actor.nim +++ b/src/libnotify_actor.nim @@ -23,6 +23,8 @@ type proc init(appName: cstring): bool {.notify.} proc uninit() {.notify.} +proc get_server_info(name, vendor, version, specVersion: ptr cstring): bool {.notify.} + proc notification_new(summary, body, icon: cstring = nil): Notification {.notify.} proc show(n: Notification; err: ptr GError): bool {.notification.} @@ -41,6 +43,16 @@ const appName = "libnotify_actor" if not init(appName): quit "failed to initialize libnotify" +proc assertServerInfo(turn: var Turn; ds: Ref) = + var name, vendor, version, specVersion: cstring + if get_server_info(addr name, addr vendor, addr version, addr specVersion): + var a = ServerInfo( + name: $name, + vendor: $vendor, + version: $version, + specVersion: $specVersion, + ) + discard publish(turn, ds, a) type Args {.preservesDictionary.} = object dataspace: Ref @@ -51,6 +63,7 @@ runActor("main") do (root: Ref; turn: var Turn): if not init(appName): stderr.writeLine "failed to initialize libnotify" else: + assertServerInfo(turn, ds) onMessage(turn, ds, ?Notify) do (summary: string, attrs: Attrs): let body = getOrDefault(attrs, Symbol"body") diff --git a/src/protocol.nim b/src/protocol.nim index b613a66..c51dcaa 100644 --- a/src/protocol.nim +++ b/src/protocol.nim @@ -8,8 +8,14 @@ type `summary`*: string `attrs`*: Attrs -proc `$`*(x: Attrs | Notify): string = + ServerInfo* {.preservesRecord: "server-info".} = object + `name`*: string + `vendor`*: string + `version`*: string + `specVersion`*: string + +proc `$`*(x: Attrs | Notify | ServerInfo): string = `$`(toPreserve(x)) -proc encode*(x: Attrs | Notify): seq[byte] = +proc encode*(x: Attrs | Notify | ServerInfo): seq[byte] = encode(toPreserve(x))