From f10de92455a78882142ad3b5a2efc209c73d405c Mon Sep 17 00:00:00 2001 From: niten Date: Sat, 15 Apr 2023 03:42:05 -0700 Subject: [PATCH] Initial checkin, broken, with freedesktop api --- .gitignore | 9 +++ build.clj | 122 +++++++++++++++++++++++++++++++++++++++ deps.edn | 21 +++++++ metadata.edn | 8 +++ src/clj/tattler/core.clj | 17 ++++++ 5 files changed, 177 insertions(+) create mode 100644 .gitignore create mode 100644 build.clj create mode 100644 deps.edn create mode 100644 metadata.edn create mode 100644 src/clj/tattler/core.clj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1b9f7c3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.idea +*.log +tmp/ + +.cpcache/ +.nrepl-port +target/ +result diff --git a/build.clj b/build.clj new file mode 100644 index 0000000..ffdb022 --- /dev/null +++ b/build.clj @@ -0,0 +1,122 @@ +(ns build + (:require [clojure.tools.build.api :as b] + [clojure.pprint :refer [pprint]] + [clojure.edn :as edn])) + +(def lib 'org.fudo/tattler) +(def default-version "DEV") +(defn- class-dir [{:keys [target]}] (format "%s/classes" target)) +(def basis (b/create-basis {:project "deps.edn"})) +(defn- jar-file [{:keys [target version] + :or {version default-version}}] + (format "%s/%s-%s.jar" target (name lib) version)) + +(defn- uberjar-file [{:keys [target version] + :or {version default-version}}] + (format "%s/%s-uber-%s.jar" target (name lib) version)) + +(def default-params + { + :verbose false + :version "DEV" + }) + +(defn clean [{:keys [target] :as params}] + (b/delete {:path target}) + params) + +(defn compile-java [{:keys [verbose java-src] :as params}] + (when verbose (println (format "compiling java files in %s..." java-src))) + (b/javac {:src-dirs [java-src] + :class-dir (class-dir params) + :basis basis + :javac-opts ["-source" "12" "-target" "12"]}) + params) + +(defn compile-clj [{:keys [verbose clj-src] :as params}] + (when verbose (println (format "compiling clj files in %s..." clj-src))) + (b/compile-clj {:basis basis + :src-dirs [clj-src] + :class-dir (class-dir params)})) + +(defn- pthru [o] (pprint o) o) + +(defn- read-metadata [filename] + (-> filename + (slurp) + (edn/read-string))) + +(defn jar [base-params] + (let [params (-> (merge default-params + (read-metadata (or (:metadata base-params) + "metadata.edn")) + base-params) + (update :target str) + (update :version str) + (update :java-src str) + (update :clj-src str) + (update :main-ns str)) + {:keys [java-src clj-src main-ns version verbose]} params + classes (class-dir params)] + (when verbose + (print "parameters: ") + (pprint params)) + (compile-java params) + (compile-clj params) + (when verbose (println (format "writing POM file to %s..." classes))) + (b/write-pom { + :class-dir classes + :lib lib + :version (str version) + :basis basis + :src-dirs [java-src clj-src] + }) + (when verbose (println (format "copying source files from %s to %s..." + [java-src clj-src] classes))) + (b/copy-dir {:src-dirs [java-src clj-src] + :target-dir classes}) + (let [jar (jar-file params)] + (when verbose (println (format "writing JAR file to %s..." jar))) + (b/jar {:class-dir classes + :jar-file jar + :main main-ns})) + (when verbose (println "done!")) + params)) + +(defn uberjar [base-params] + (let [params (-> (merge default-params + (read-metadata (or (:metadata base-params) + "metadata.edn")) + base-params) + (update :target str) + (update :version str) + (update :java-src str) + (update :clj-src str) + (update :main-ns str)) + {:keys [java-src clj-src main-ns version verbose]} params + classes (class-dir params)] + (when verbose + (print "parameters: ") + (pprint params)) + (compile-java params) + (compile-clj params) + (when verbose (println (format "writing POM file to %s..." classes))) + (b/write-pom { + :class-dir classes + :lib lib + :version (str version) + :basis basis + :src-dirs [java-src clj-src] + }) + (when verbose (println (format "copying source files from %s to %s..." + [java-src clj-src] classes))) + (b/copy-dir {:src-dirs [java-src clj-src] + :target-dir classes}) + (let [uberjar (uberjar-file params)] + (when verbose (println (format "writing uberjar file to %s..." uberjar))) + (b/uber {:class-dir classes + :uber-file uberjar + :basis basis + :main main-ns})) + (when verbose (println "done!")) + params)) diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000..48e73aa --- /dev/null +++ b/deps.edn @@ -0,0 +1,21 @@ +{ + :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" } + } + ;; :mvn/repos { + ;; "in2p3" {:url "https://maven.in2p3.fr/"} + ;; } + :aliases { + :build { + :extra-deps { + io.github.clojure/tools.build {:mvn/version "0.9.4"} + } + :ns-default build + :exec-fn uberjar + } + } + } diff --git a/metadata.edn b/metadata.edn new file mode 100644 index 0000000..e5baa26 --- /dev/null +++ b/metadata.edn @@ -0,0 +1,8 @@ +{ + :version "0.1" + :target "target" + :java-src "src/java" + :clj-src "src/clj" + :main-ns "tattler.core" + :verbose true + } diff --git a/src/clj/tattler/core.clj b/src/clj/tattler/core.clj new file mode 100644 index 0000000..5799c04 --- /dev/null +++ b/src/clj/tattler/core.clj @@ -0,0 +1,17 @@ +(ns tattler.core + (:import [org.freedesktop.dbus DBusConnection] + [org.freedesktop Notifications]) + (: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 send [{app :app conn :conn} notification] + (let [])) + +(defn -main [& args] + (println (get-server-capabilities)))