Compare commits
3 Commits
5b7d241c62
...
c8e23d0f2e
Author | SHA1 | Date |
---|---|---|
Emery Hemingway | c8e23d0f2e | |
Emery Hemingway | 22a7a61007 | |
Emery Hemingway | 72327020ac |
|
@ -1 +1 @@
|
|||
/.direnv
|
||||
/nim.cfg
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
include_rules
|
||||
: |> !nim_lk |> | ./<lock>
|
||||
: lock.json |> !nim_cfg |> | ./<lock>
|
|
@ -1,2 +1,3 @@
|
|||
include ../syndicate-nim/depends.tup
|
||||
NIM_FLAGS += --path:$(TUP_CWD)/../syndicate-nim/src
|
||||
NIM_GROUPS += $(TUP_CWD)/<lock>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "20230506"
|
||||
version = "20231009"
|
||||
author = "Emery Hemingway"
|
||||
description = "Actor for sending notifications with Libnotify"
|
||||
license = "Unlicense"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"depends":[{"method":"fetchzip","packages":["syndicate"],"path":"/nix/store/008s11kkqscfqxs6g29q77c38pnrlppi-source","ref":"20231005","rev":"552e51899c82c0c2f4f466382be7d8e22a1da689","sha256":"1j3k0zlh5z02adhfvb7rdqz8fjzc6gri4v3v1fgcv2h2b7vrf0dg","srcDir":"src","url":"https://git.syndicate-lang.org/ehmry/syndicate-nim/archive/552e51899c82c0c2f4f466382be7d8e22a1da689.tar.gz"},{"method":"fetchzip","packages":["hashlib"],"path":"/nix/store/v03nzlpdgbfxd2zhcnkfbkq01d5kqxcl-source","rev":"84e0247555e4488594975900401baaf5bbbfb53","sha256":"1pfczsv8kl36qpv543f93d2y2vgz2acckssfap7l51s2x62m6qwx","srcDir":"","url":"https://github.com/khchen/hashlib/archive/84e0247555e4488594975900401baaf5bbbfb53.tar.gz"},{"method":"fetchzip","packages":["preserves"],"path":"/nix/store/vx6ihnickx7d5lwy69i8k7fsjicv33r3-source","ref":"20230914","rev":"c915accf7d2a36ca1f323e2f02e2df7375e815f1","sha256":"11rlcbs9mvk335ibkbj8fk9aslhmnlaiqhcsjpp5n04k447sr7nx","srcDir":"src","url":"https://git.syndicate-lang.org/ehmry/preserves-nim/archive/c915accf7d2a36ca1f323e2f02e2df7375e815f1.tar.gz"},{"method":"fetchzip","packages":["nimcrypto"],"path":"/nix/store/zyr8zwh7vaiycn1s4r8cxwc71f2k5l0h-source","ref":"traditional-api","rev":"602c5d20c69c76137201b5d41f788f72afb95aa8","sha256":"1dmdmgb6b9m5f8dyxk781nnd61dsk3hdxqks7idk9ncnpj9fng65","srcDir":"","url":"https://github.com/cheatfate/nimcrypto/archive/602c5d20c69c76137201b5d41f788f72afb95aa8.tar.gz"},{"method":"fetchzip","packages":["npeg"],"path":"/nix/store/ffkxmjmigfs7zhhiiqm0iw2c34smyciy-source","ref":"1.2.1","rev":"26d62fdc40feb84c6533956dc11d5ee9ea9b6c09","sha256":"0xpzifjkfp49w76qmaylan8q181bs45anmp46l4bwr3lkrr7bpwh","srcDir":"src","url":"https://github.com/zevv/npeg/archive/26d62fdc40feb84c6533956dc11d5ee9ea9b6c09.tar.gz"}]}
|
12
shell.nix
12
shell.nix
|
@ -1,5 +1,7 @@
|
|||
let
|
||||
syndicate = builtins.getFlake "syndicate";
|
||||
pkgs =
|
||||
import <nixpkgs> { overlays = builtins.attrValues syndicate.overlays; };
|
||||
in pkgs.libnotify_actor
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
pkgs.nim2Packages.buildNimPackage {
|
||||
name = "dummy";
|
||||
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||
buildInputs = [ pkgs.libnotify ];
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
include ./protocol
|
||||
|
||||
from std/strutils import normalize
|
||||
import syndicate
|
||||
import syndicate, syndicate/relays
|
||||
|
||||
{.passC: staticExec("pkg-config --cflags libnotify").}
|
||||
{.passL: staticExec("pkg-config --libs libnotify").}
|
||||
|
@ -25,25 +25,19 @@ proc g_error_free(err: ptr GError) {.importc, header: "glib/gerror.h".}
|
|||
proc init(appName: cstring): bool {.notify.}
|
||||
proc uninit() {.notify.}
|
||||
|
||||
proc get_server_info(name, vendor, version, specVersion: ptr cstring): bool {.notify.}
|
||||
proc is_initted: bool {.notify.}
|
||||
|
||||
proc get_server_info(name, vendor, version, specVersion: ptr (ptr char)): bool {.notify.}
|
||||
|
||||
proc notification_new(summary, body, icon: cstring = nil): Notification {.notify.}
|
||||
|
||||
proc set_app_name(n: Notification; s: string) {.notification.}
|
||||
proc set_category(n: Notification; s: string) {.notification.}
|
||||
proc set_app_name(n: Notification; s: cstring) {.notification.}
|
||||
proc set_category(n: Notification; s: cstring) {.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"
|
||||
|
||||
proc show(n: Notification; err: ptr (ptr GError)): bool {.notification.}
|
||||
var err: ptr GError
|
||||
if not show(n, addr err):
|
||||
|
@ -53,28 +47,25 @@ if not init(appName):
|
|||
if not err.isNil:
|
||||
g_error_free(err)
|
||||
|
||||
proc assertServerInfo(turn: var Turn; ds: Ref) =
|
||||
proc assertServerInfo(turn: var Turn; ds: Cap) =
|
||||
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)
|
||||
if get_server_info(nil, nil, nil, nil):
|
||||
discard
|
||||
else:
|
||||
stderr.writeLine "failed to get server info!"
|
||||
|
||||
type Args {.preservesDictionary.} = object
|
||||
dataspace: Ref
|
||||
dataspace: Cap
|
||||
|
||||
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:
|
||||
runActor("libnotify_actor") do (ds: Cap; turn: var Turn):
|
||||
connectStdio(ds, turn)
|
||||
during(turn, ds, dropType Args) do:
|
||||
doAssert init("libnotify_actor"), "failed to initialize libnotify"
|
||||
|
||||
during(turn, ds, ?Args) do (ds: Cap):
|
||||
assertServerInfo(turn, ds)
|
||||
onMessage(turn, ds, ?Notify) do (summary: string, attrs: Attrs):
|
||||
doAssert isInitted()
|
||||
let
|
||||
body = getOrDefault(attrs, Symbol"body")
|
||||
icon = getOrDefault(attrs, Symbol"icon")
|
||||
|
@ -87,15 +78,10 @@ runActor("main") do (root: Ref; turn: var Turn):
|
|||
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)
|
||||
|
||||
do:
|
||||
uninit()
|
||||
|
|
Loading…
Reference in New Issue