From b270cec6376041514faee2c02533287d2cffd4a3 Mon Sep 17 00:00:00 2001 From: niten Date: Tue, 18 Apr 2023 17:21:35 -0700 Subject: [PATCH] About to repurpose this library... --- build.clj | 2 +- deps.edn | 14 +++--- src/clj/tattler/core.clj | 38 +++++++++++++--- src/java/org/freedesktop/Notifications.java | 48 ++++++++++----------- src/java/org/freedesktop/Quad.java | 22 ---------- 5 files changed, 65 insertions(+), 59 deletions(-) delete mode 100644 src/java/org/freedesktop/Quad.java diff --git a/build.clj b/build.clj index ffdb022..164b5d0 100644 --- a/build.clj +++ b/build.clj @@ -30,7 +30,7 @@ (b/javac {:src-dirs [java-src] :class-dir (class-dir params) :basis basis - :javac-opts ["-source" "12" "-target" "12"]}) + :javac-opts ["-source" "16" "-target" "16"]}) params) (defn compile-clj [{:keys [verbose clj-src] :as params}] diff --git a/deps.edn b/deps.edn index 48e73aa..2bced84 100644 --- a/deps.edn +++ b/deps.edn @@ -2,13 +2,15 @@ :paths ["src/clj" "src/java"] :deps { org.clojure/clojure { :mvn/version "1.11.1" } - ;;org.freedesktop/libdbus-java { :mvn/version "2.7" } - ;;com.github.hypfvieh/libmatthew { :mvn/version "0.8.3" } - com.github.hypfvieh/dbus-java { :mvn/version "3.3.2" } + com.github.hypfvieh/dbus-java-core { :mvn/version "4.3.0" } + com.github.hypfvieh/dbus-java-transport-native-unixsocket { :mvn/version "4.3.0" } + org.fudo/milquetoast { + :git/url "https://git.fudo.org/fudo-public/milquetoast.git" + :git/sha "ae81b91f0c710632f55b43f0193e16ab0dd81dde" + } + metosin/malli { :mvn/version "0.11.0" } + org.fudo/notifier { :mvn/version "0.1" } } - ;; :mvn/repos { - ;; "in2p3" {:url "https://maven.in2p3.fr/"} - ;; } :aliases { :build { :extra-deps { diff --git a/src/clj/tattler/core.clj b/src/clj/tattler/core.clj index 5799c04..707bb17 100644 --- a/src/clj/tattler/core.clj +++ b/src/clj/tattler/core.clj @@ -1,17 +1,43 @@ (ns tattler.core - (:import [org.freedesktop.dbus DBusConnection] - [org.freedesktop Notifications]) + (:import [org.freedesktop Notifications] + [org.freedesktop.dbus.connections.impl + DBusConnectionBuilder] + org.freedesktop.dbus.types.UInt32) (:gen-class)) (def ^:private ^:const NOTIFICATIONS_PATH "/org/freedesktop/Notifications") (def ^:private ^:const NOTIFICATIONS_BUS "org.freedesktop.Notifications") -(defn get-server-capabilities [] - (let [dbus (DBusConnection/getConnection DBusConnection/SESSION)] - (.getRemoteObject dbus NOTIFICATIONS_BUS NOTIFICATIONS_PATH (.class Notifications)))) +(defn connect-session-bus [] + (-> (DBusConnectionBuilder/forSessionBus) + (.build) + (.getRemoteObject NOTIFICATIONS_BUS NOTIFICATIONS_PATH Notifications))) + +(defn send-notification + [bus + {:keys [app replace-id icon summary body actions timeout urgency] + :or {replace-id 0 + icon "" + actions [] + timeout -1} + :as args}] + (doseq [arg [:app :summary :body]] + (when (not (contains? args arg)) + (throw (ex-info (format "Missing required argument: %s" arg) + {:arg arg})))) + (.Notify bus + app + (UInt32. replace-id) + icon + summary + body + actions + hints + timeout)) #_(defn send [{app :app conn :conn} notification] (let [])) (defn -main [& args] - (println (get-server-capabilities))) + (send-notification (connect-session-bus) + {:app "my_app" :summary "Hey there" :body "How's it going now?"})) diff --git a/src/java/org/freedesktop/Notifications.java b/src/java/org/freedesktop/Notifications.java index 2944c6c..2909e8d 100644 --- a/src/java/org/freedesktop/Notifications.java +++ b/src/java/org/freedesktop/Notifications.java @@ -2,38 +2,38 @@ package org.freedesktop; import java.util.List; import java.util.Map; -import org.freedesktop.dbus.DBusInterface; -import org.freedesktop.dbus.DBusSignal; -import org.freedesktop.dbus.UInt32; -import org.freedesktop.dbus.Variant; +import org.freedesktop.dbus.interfaces.DBusInterface; +// import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.types.UInt32; +import org.freedesktop.dbus.types.Variant; import org.freedesktop.dbus.exceptions.DBusException; public interface Notifications extends DBusInterface { - public static class ActionInvoked extends DBusSignal { - public final UInt32 id; - public final String action_key; + // public static class ActionInvoked extends DBusSignal { + // public final UInt32 id; + // public final String action_key; - public ActionInvoked(String path, UInt32 id, String action_key) throws DBusException { - super(path, id, action_key); - this.id = id; - this.action_key = action_key; - } - } + // public ActionInvoked(String path, UInt32 id, String action_key) throws DBusException { + // super(path, id, action_key); + // this.id = id; + // this.action_key = action_key; + // } + // } - public static class NotificationClosed extends DBusSignal { - public final UInt32 id; - public final UInt32 reason; + // public static class NotificationClosed extends DBusSignal { + // public final UInt32 id; + // public final UInt32 reason; - public NotificationClosed(String path, UInt32 id, UInt32 reason) throws DBusException { - super(path, id, reason); - this.id = id; - this.reason = reason; - } - } + // public NotificationClosed(String path, UInt32 id, UInt32 reason) throws DBusException { + // super(path, id, reason); + // this.id = id; + // this.reason = reason; + // } + // } - public void CloseNotification(UInt32 id); + // public void CloseNotification(UInt32 id); public List GetCapabilities(); - public Quad GetServerInformation(); + // public Quad GetServerInformation(); public UInt32 Notify( String app_name, diff --git a/src/java/org/freedesktop/Quad.java b/src/java/org/freedesktop/Quad.java deleted file mode 100644 index 09108ad..0000000 --- a/src/java/org/freedesktop/Quad.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.freedesktop; - -import org.freedesktop.dbus.Position; -import org.freedesktop.dbus.Tuple; - -public final class Quad extends Tuple { - @Position(0) - public final A a; - @Position(1) - public final B b; - @Position(3) - public final C c; - @Position(4) - public final D d; - - public Quad(A a, B b, C c, D d) { - this.a = a; - this.b = b; - this.c = c; - this.d = d; - } -}