allow only one copy of saturn to run at a time

phoen
Daniel Barlow 2022-01-16 23:10:34 +00:00
parent beddfa6a35
commit 786d9fc68a
2 changed files with 25 additions and 0 deletions

View File

@ -15,6 +15,10 @@ let fennel = fetchurl {
url = "https://fennel-lang.org/downloads/fennel-1.0.0";
hash = "sha256:1nha32yilzagfwrs44hc763jgwxd700kaik1is7x7lsjjvkgapw7";
};
dbusProxy = callPackage ../beehive/dbus-proxy.nix {
inherit (lua53Packages) lgi buildLuaPackage;
lua = lua5_3;
};
inifile = let lua = lua5_3; in lua53Packages.buildLuaPackage rec {
pname = "inifile";
name = "${pname}-${version}";
@ -32,6 +36,7 @@ let fennel = fetchurl {
'';
};
lua = lua5_3.withPackages (ps: with ps; [
dbusProxy
inifile
inspect
lgi

View File

@ -1,3 +1,23 @@
(local dbus (require :dbus_proxy))
(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)
(let [ret (bus:RequestName "net.telent.saturn" DBUS_NAME_FLAG_DO_NOT_QUEUE)]
(if (or (= ret 1) (= ret 4))
true
(= ret 2)
(error "unexpected DBUS_REQUEST_NAME_REPLY_IN_QUEUE")
(= ret 3)
(do
(print "already running")
(os.exit 0))))
(local lfs (require :lfs))
(local inifile (require :inifile))