Initial commit
This commit is contained in:
commit
2395749892
|
@ -0,0 +1,3 @@
|
|||
# libnotify_actor
|
||||
|
||||
[Syndicate](https://syndicate-lang.org/) actor for sending notifications with [Libnotify](https://gnome.pages.gitlab.gnome.org/libnotify/index.html).
|
|
@ -0,0 +1,2 @@
|
|||
include ../syndicate-nim/depends.tup
|
||||
NIM_FLAGS += --path:$(TUP_CWD)/../syndicate-nim/src
|
|
@ -0,0 +1,13 @@
|
|||
# Package
|
||||
|
||||
version = "20230405"
|
||||
author = "Emery Hemingway"
|
||||
description = "Actor for sending notifications with Libnotify"
|
||||
license = "Unlicense"
|
||||
srcDir = "src"
|
||||
bin = @["libnotify_actor"]
|
||||
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires "nim >= 1.6.10"
|
|
@ -0,0 +1,3 @@
|
|||
version 1.
|
||||
Attrs = {symbol: string ...:...} .
|
||||
Notify = <notify @summary string @attrs Attrs> .
|
|
@ -0,0 +1,3 @@
|
|||
include_rules
|
||||
: foreach ../*.prs |> !preserves_schema_nim |> {schema}
|
||||
: libnotify_actor.nim | {schema} $(SYNDICATE_PROTOCOL) |> !nim_bin |>
|
|
@ -0,0 +1,71 @@
|
|||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
include ./protocol
|
||||
|
||||
import std/[asyncdispatch]
|
||||
from std/strutils import normalize
|
||||
import syndicate
|
||||
|
||||
{.passC: staticExec("pkg-config --cflags libnotify").}
|
||||
{.passL: staticExec("pkg-config --libs libnotify").}
|
||||
|
||||
const notifyHeader = "<libnotify/notify.h>"
|
||||
{.pragma: notify, header: notifyHeader, importc: "notify_$1".}
|
||||
{.pragma: notification, header: notifyHeader, importc: "notify_notification_$1".}
|
||||
|
||||
type
|
||||
Notification {.importc: "NotifyNotification".} = ptr object
|
||||
discard
|
||||
GError {.importc.} = ptr object
|
||||
message: cstring
|
||||
|
||||
proc init(appName: cstring): bool {.notify.}
|
||||
# proc uninit() {.notify.}
|
||||
|
||||
proc notification_new(summary, body, icon: cstring = nil): Notification {.notify.}
|
||||
proc show(n: Notification; err: ptr GError): bool {.notification.}
|
||||
|
||||
proc set_app_name(n: Notification; s: string) {.notification.}
|
||||
proc set_category(n: Notification; s: string) {.notification.}
|
||||
|
||||
type NotifyUrgency {.importc.} = enum Low, Normal, Critical
|
||||
proc set_urgency(n: Notification; u: NotifyUrgency) {.notification.}
|
||||
|
||||
proc show(n: Notification) =
|
||||
if not show(n, nil):
|
||||
stderr.writeLine "show failed"
|
||||
|
||||
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)
|
||||
|
||||
case getOrDefault(attrs, Symbol"urgency").normalize
|
||||
of "high", "critical":
|
||||
set_urgency(n, Critical)
|
||||
of "low":
|
||||
set_urgency(n, Low)
|
||||
else: discard
|
||||
|
||||
let app_name = getOrDefault(attrs, Symbol"app_name")
|
||||
if app_name != "":
|
||||
set_app_name(n, app_name)
|
||||
|
||||
let category = getOrDefault(attrs, Symbol"category")
|
||||
if category != "":
|
||||
set_category(n, category)
|
||||
|
||||
show(n)
|
||||
|
||||
runForever()
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
import
|
||||
std/typetraits, preserves, std/tables
|
||||
|
||||
type
|
||||
Attrs* = Table[Symbol, string]
|
||||
Notify* {.preservesRecord: "notify".} = object
|
||||
`summary`*: string
|
||||
`attrs`*: Attrs
|
||||
|
||||
proc `$`*(x: Attrs | Notify): string =
|
||||
`$`(toPreserve(x))
|
||||
|
||||
proc encode*(x: Attrs | Notify): seq[byte] =
|
||||
encode(toPreserve(x))
|
Loading…
Reference in New Issue