freedesktop_notifier: grab more

Grab both assertions and messages. Assertions are better when
redundant messages can happen.

Remove the type on the notification body to make it usable as a
Syndicate diagnostic tool.
This commit is contained in:
Emery Hemingway 2022-06-10 12:09:06 -05:00
parent 9e6d39d154
commit f08fc033d2
3 changed files with 16 additions and 15 deletions

View File

@ -1,3 +1,3 @@
version 1 .
Urgency = =Low / =Normal / =Critical .
Notify = <notify @summary string @body string @timeout int @urgency Urgency> .
Notify = <notify @summary string @body any @timeout int @urgency Urgency> .

View File

@ -2,19 +2,20 @@
# SPDX-License-Identifier: Unlicense
import std/[asyncdispatch, strutils]
import syndicate
import preserves, syndicate
import ./private/libnotify
import ./schema/notifications
proc render(a: Assertion): string =
if a.isString: a.string
else: $a
bootDataspace("main") do (ds: Ref; turn: var Turn):
connectStdio(ds, turn)
let nc = newNotifyClient("syndicate")
onMessage(turn, ds, ?Notify) do (s: string, b: string, t: int, u: Urgency):
nc.send_new_notification(
summary = s,
body = b,
icon_fname = "",
timeout = t,
urgency = NotificationUrgency u)
onPublish(turn, ds, ?Notify[Ref]) do (s: string, b: Assertion, t: int, u: Urgency):
nc.send_new_notification(s, render(b), "", t, NotificationUrgency u)
onMessage(turn, ds, ?Notify[Ref]) do (s: string, b: Assertion, t: int, u: Urgency):
nc.send_new_notification(s, render(b), "", t, NotificationUrgency u)
runForever()

View File

@ -3,16 +3,16 @@ import
std/typetraits, preserves
type
Notify* {.preservesRecord: "notify".} = object
Notify*[E] {.preservesRecord: "notify".} = ref object
`summary`*: string
`body`*: string
`body`*: Preserve[E]
`timeout`*: int
`urgency`*: Urgency
`Urgency`* {.preservesOr, pure.} = enum
`Low`, `Normal`, `Critical`
proc `$`*(x: Notify): string =
`$`(toPreserve(x))
proc `$`*[E](x: Notify[E]): string =
`$`(toPreserve(x, E))
proc encode*(x: Notify): seq[byte] =
encode(toPreserve(x))
proc encode*[E](x: Notify[E]): seq[byte] =
encode(toPreserve(x, E))