Publish server info
This commit is contained in:
parent
1b62a1e571
commit
29fa33b1c6
|
@ -1,3 +1,4 @@
|
|||
version 1.
|
||||
Attrs = {symbol: string ...:...} .
|
||||
Notify = <notify @summary string @attrs Attrs> .
|
||||
ServerInfo = <server-info @name string @vendor string @version string @specVersion string> .
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue