From 6a5f2ecb18d0bd2ac8e530de9f0cb71dc855c483 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 17 Jan 2022 20:57:26 -0500 Subject: [PATCH 1/2] saturn: Provide more dbus constant names Makes reading the code easier^W possible. --- saturn/main.fnl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/saturn/main.fnl b/saturn/main.fnl index fe8650f..9707cbd 100644 --- a/saturn/main.fnl +++ b/saturn/main.fnl @@ -25,12 +25,17 @@ (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 "net.telent.saturn" DBUS_NAME_FLAG_DO_NOT_QUEUE)] - (if (or (= ret 1) (= ret 4)) + (if (or (= ret DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) (= ret DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)) true - (= ret 2) + (= ret DBUS_REQUEST_NAME_REPLY_IN_QUEUE) (error "unexpected DBUS_REQUEST_NAME_REPLY_IN_QUEUE") - (= ret 3) + (= ret DBUS_REQUEST_NAME_REPLY_EXISTS) (do (print "already running") (os.exit 0)))) From 38f62baa82d7c86aa83466977bc7846fa6a609d2 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Mon, 17 Jan 2022 21:13:11 -0500 Subject: [PATCH 2/2] saturn: Show current instance on re-exec Allows "less dbus-enthusiastic" setups to *just* re-run the saturn executable to show it. --- saturn/main.fnl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/saturn/main.fnl b/saturn/main.fnl index 9707cbd..55a96f4 100644 --- a/saturn/main.fnl +++ b/saturn/main.fnl @@ -36,9 +36,17 @@ (= ret DBUS_REQUEST_NAME_REPLY_IN_QUEUE) (error "unexpected DBUS_REQUEST_NAME_REPLY_IN_QUEUE") (= ret DBUS_REQUEST_NAME_REPLY_EXISTS) - (do - (print "already running") - (os.exit 0)))) + ;; Show the currently running instance + (let [saturn (dbus.Proxy:new + { + :bus dbus.Bus.SESSION + :name "net.telent.saturn" + :interface "net.telent.saturn" + :path "/net/telent/saturn" + })] + (saturn:SetVisible true) + (os.exit 0) + ))) (local lfs (require :lfs))