Publish server info
This commit is contained in:
parent
1b62a1e571
commit
29fa33b1c6
|
@ -1,3 +1,4 @@
|
||||||
version 1.
|
version 1.
|
||||||
Attrs = {symbol: string ...:...} .
|
Attrs = {symbol: string ...:...} .
|
||||||
Notify = <notify @summary string @attrs Attrs> .
|
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 init(appName: cstring): bool {.notify.}
|
||||||
proc uninit() {.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 notification_new(summary, body, icon: cstring = nil): Notification {.notify.}
|
||||||
proc show(n: Notification; err: ptr GError): bool {.notification.}
|
proc show(n: Notification; err: ptr GError): bool {.notification.}
|
||||||
|
|
||||||
|
@ -41,6 +43,16 @@ const appName = "libnotify_actor"
|
||||||
if not init(appName):
|
if not init(appName):
|
||||||
quit "failed to initialize libnotify"
|
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
|
type Args {.preservesDictionary.} = object
|
||||||
dataspace: Ref
|
dataspace: Ref
|
||||||
|
@ -51,6 +63,7 @@ runActor("main") do (root: Ref; turn: var Turn):
|
||||||
if not init(appName):
|
if not init(appName):
|
||||||
stderr.writeLine "failed to initialize libnotify"
|
stderr.writeLine "failed to initialize libnotify"
|
||||||
else:
|
else:
|
||||||
|
assertServerInfo(turn, ds)
|
||||||
onMessage(turn, ds, ?Notify) do (summary: string, attrs: Attrs):
|
onMessage(turn, ds, ?Notify) do (summary: string, attrs: Attrs):
|
||||||
let
|
let
|
||||||
body = getOrDefault(attrs, Symbol"body")
|
body = getOrDefault(attrs, Symbol"body")
|
||||||
|
|
|
@ -8,8 +8,14 @@ type
|
||||||
`summary`*: string
|
`summary`*: string
|
||||||
`attrs`*: Attrs
|
`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))
|
`$`(toPreserve(x))
|
||||||
|
|
||||||
proc encode*(x: Attrs | Notify): seq[byte] =
|
proc encode*(x: Attrs | Notify | ServerInfo): seq[byte] =
|
||||||
encode(toPreserve(x))
|
encode(toPreserve(x))
|
||||||
|
|
Loading…
Reference in New Issue