initial commit creates service and listens for Notify

phoen
Daniel Barlow 2022-02-10 00:29:21 +00:00
parent 7dc57ae8fd
commit 42d5d8f4e6
5 changed files with 209 additions and 0 deletions

94
crier/crier.fnl Normal file
View File

@ -0,0 +1,94 @@
(local lgi (require :lgi))
(local dbus (require :dbus_proxy))
(local Gio lgi.Gio)
(local GLib lgi.GLib)
(local GV lgi.GLib.Variant)
(local variant dbus.variant)
(local inspect (require :inspect))
(local Gtk lgi.Gtk)
(local dbus-service-attrs
{
:bus dbus.Bus.SESSION
:name "org.freedesktop.Notifications"
:interface "org.freedesktop.Notifications"
:path "/org/freedesktop/Notifications"
})
(local bus (dbus.Proxy:new
{
:bus dbus.Bus.SESSION
:name "org.freedesktop.DBus"
:interface "org.freedesktop.DBus"
:path "/org/freedesktop/DBus"
}))
(local DBUS_NAME_FLAG_DO_NOT_QUEUE 4)
(local DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER 1)
(local DBUS_REQUEST_NAME_REPLY_IN_QUEUE 2)
(local DBUS_REQUEST_NAME_REPLY_EXISTS 3)
(local DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER 4)
(let [ret (bus:RequestName dbus-service-attrs.name
DBUS_NAME_FLAG_DO_NOT_QUEUE)]
(match ret
DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
true
DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER
true
DBUS_REQUEST_NAME_REPLY_IN_QUEUE
(error "unexpected DBUS_REQUEST_NAME_REPLY_IN_QUEUE")
DBUS_REQUEST_NAME_REPLY_EXISTS
(error "already running")))
(var notification-id 10)
(fn next-id []
(set notification-id (+ notification-id 1))
notification-id)
(fn handle-dbus-method-call [conn sender path interface method params invocation]
(when (and (= path dbus-service-attrs.path)
(= interface dbus-service-attrs.interface))
(match method
"GetCapabilities"
(invocation:return_value (GV "as" ["actions"]))
"GetServerInformation"
(invocation:return_value
(GV "(ssss)" ["crier"
"telent"
"0.1"
"1.2"]))
"Notify"
(let [p params]
(print (inspect (dbus.variant.strip p)))
(invocation:return_value (GV "(u)" [(next-id)]))))))
(fn handle-dbus-get [conn sender path interface name]
(when (and (= path dbus-service-attrs.path)
(= interface dbus-service-attrs.interface)
(= name "Visible"))
(lgi.GLib.Variant "b" true)))
(local interface-info
(let [xml (: (io.open "interface.xml" "r") :read "*a")
node-info (Gio.DBusNodeInfo.new_for_xml xml)]
(. node-info.interfaces 1)))
(Gio.DBusConnection.register_object
bus.connection
dbus-service-attrs.path
interface-info
(lgi.GObject.Closure handle-dbus-method-call)
(lgi.GObject.Closure handle-dbus-get)
(lgi.GObject.Closure (fn [a] (print "set"))))
(Gtk:main)

29
crier/dbus-proxy.nix Normal file
View File

@ -0,0 +1,29 @@
{ lua, lgi, buildLuaPackage, fetchFromGitHub }:
let
simpleName = "dbus_proxy";
in
# TODO: add busted and checkPhase?
buildLuaPackage rec {
version = "0.10.2";
pname = simpleName; # nixpkgs unstable needs this
name = "${pname}-${version}"; # nixpkgs 21.11 needs this
src = fetchFromGitHub {
owner = "stefano-m";
repo = "lua-${simpleName}";
rev = "v${version}";
sha256 = "0kl8ff1g1kpmslzzf53cbzfl1bmb5cb91w431hbz0z0vdrramh6l";
};
propagatedBuildInputs = [ lgi ];
buildPhase = ":";
installPhase = ''
mkdir -p "$out/share/lua/${lua.luaversion}"
cp -r src/${pname} "$out/share/lua/${lua.luaversion}/"
'';
}

43
crier/default.nix Normal file
View File

@ -0,0 +1,43 @@
{ stdenv
, callPackage
, fetchFromGitHub
, fetchurl
, gobject-introspection
, gtk3
, lib
, librsvg
, lua53Packages
, lua5_3
, makeWrapper
, writeText
}:
let fennel = fetchurl {
name = "fennel.lua";
url = "https://fennel-lang.org/downloads/fennel-1.0.0";
hash = "sha256:1nha32yilzagfwrs44hc763jgwxd700kaik1is7x7lsjjvkgapw7";
};
dbusProxy = callPackage ./dbus-proxy.nix {
inherit (lua53Packages) lgi buildLuaPackage;
lua = lua5_3;
};
lua = lua5_3.withPackages (ps: with ps; [
dbusProxy
inspect
lgi
luafilesystem
luaposix
readline
]);
in stdenv.mkDerivation {
pname = "crier";
version = "0.1";
src =./.;
inherit fennel;
buildInputs = [ lua gtk3 gobject-introspection.dev ];
nativeBuildInputs = [ lua makeWrapper ];
makeFlags = [ "PREFIX=${placeholder "out"}" ];
}

42
crier/interface.xml Normal file
View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/freedesktop/Notifications">
<interface name="org.freedesktop.Notifications">
<method name="GetCapabilities">
<arg direction="out" name="capabilities" type="as"/>
</method>
<method name="Notify">
<arg direction="in" name="app_name" type="s"/>
<arg direction="in" name="replaces_id" type="u"/>
<arg direction="in" name="app_icon" type="s"/>
<arg direction="in" name="summary" type="s"/>
<arg direction="in" name="body" type="s"/>
<arg direction="in" name="actions" type="as"/>
<arg direction="in" name="hints" type="a{sv}"/>
<arg direction="in" name="expire_timeout" type="i"/>
<arg direction="out" name="id" type="u"/>
</method>
<method name="CloseNotification">
<arg direction="in" name="id" type="u"/>
</method>
<method name="GetServerInformation">
<arg direction="out" name="name" type="s"/>
<arg direction="out" name="vendor" type="s"/>
<arg direction="out" name="version" type="s"/>
<arg direction="out" name="spec_version" type="s"/>
</method>
<signal name="NotificationClosed">
<arg name="id" type="u"/>
<arg name="reason" type="u"/>
</signal>
<signal name="ActionInvoked">
<arg name="id" type="u"/>
<arg name="action_key" type="s"/>
</signal>
</interface>
</node>

1
crier/shell.nix Normal file
View File

@ -0,0 +1 @@
with import <nixpkgs> {} ; callPackage ./. {}