Compare commits
3 Commits
80b7bf7277
...
bbd122a2f5
Author | SHA1 | Date |
---|---|---|
Emery Hemingway | bbd122a2f5 | |
Emery Hemingway | 29fa33b1c6 | |
Emery Hemingway | 1b62a1e571 |
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "20230405"
|
||||
version = "20230506"
|
||||
author = "Emery Hemingway"
|
||||
description = "Actor for sending notifications with Libnotify"
|
||||
license = "Unlicense"
|
||||
|
|
|
@ -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> .
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
include_rules
|
||||
: foreach ../*.prs |> !preserves_schema_nim |> {schema}
|
||||
: libnotify_actor.nim | {schema} $(SYNDICATE_PROTOCOL) |> !nim_bin |>
|
||||
: libnotify_actor.nim | {schema} $(SYNDICATE_PROTOCOL) |> !nim_bin |> {bin}
|
||||
: {bin} |> !assert_built |>
|
||||
|
|
|
@ -21,7 +21,9 @@ type
|
|||
message: cstring
|
||||
|
||||
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 show(n: Notification; err: ptr GError): bool {.notification.}
|
||||
|
@ -41,31 +43,49 @@ const appName = "libnotify_actor"
|
|||
if not init(appName):
|
||||
quit "failed to initialize libnotify"
|
||||
|
||||
bootDataspace(appName) do (ds: Ref; turn: var Turn):
|
||||
connectStdio(ds, turn)
|
||||
#during(turn, ds, grab()) do (config: Config):
|
||||
# discard init(config.app_name)
|
||||
onMessage(turn, ds, ?Notify) do (summary: string, attrs: Attrs):
|
||||
let
|
||||
body = getOrDefault(attrs, Symbol"body")
|
||||
icon = getOrDefault(attrs, Symbol"icon")
|
||||
n = notification_new(summary, body, icon)
|
||||
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)
|
||||
|
||||
case getOrDefault(attrs, Symbol"urgency").normalize
|
||||
of "high", "critical":
|
||||
set_urgency(n, Critical)
|
||||
of "low":
|
||||
set_urgency(n, Low)
|
||||
else: discard
|
||||
type Args {.preservesDictionary.} = object
|
||||
dataspace: Ref
|
||||
|
||||
let app_name = getOrDefault(attrs, Symbol"app_name")
|
||||
if app_name != "":
|
||||
set_app_name(n, app_name)
|
||||
runActor("main") do (root: Ref; turn: var Turn):
|
||||
connectStdio(root, turn)
|
||||
during(turn, root, ?Args) do (ds: Ref):
|
||||
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")
|
||||
icon = getOrDefault(attrs, Symbol"icon")
|
||||
n = notification_new(summary, body, icon)
|
||||
|
||||
let category = getOrDefault(attrs, Symbol"category")
|
||||
if category != "":
|
||||
set_category(n, category)
|
||||
case getOrDefault(attrs, Symbol"urgency").normalize
|
||||
of "high", "critical":
|
||||
set_urgency(n, Critical)
|
||||
of "low":
|
||||
set_urgency(n, Low)
|
||||
else: discard
|
||||
|
||||
show(n)
|
||||
let app_name = getOrDefault(attrs, Symbol"app_name")
|
||||
if app_name != "":
|
||||
set_app_name(n, app_name)
|
||||
|
||||
runForever()
|
||||
let category = getOrDefault(attrs, Symbol"category")
|
||||
if category != "":
|
||||
set_category(n, category)
|
||||
|
||||
show(n)
|
||||
|
||||
do:
|
||||
uninit()
|
||||
|
|
|
@ -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