Initial checkin
This commit is contained in:
commit
9142e3d8e9
|
@ -0,0 +1,9 @@
|
|||
.DS_Store
|
||||
.idea
|
||||
*.log
|
||||
tmp/
|
||||
|
||||
.cpcache/
|
||||
.nrepl-port
|
||||
target/
|
||||
result
|
|
@ -0,0 +1,126 @@
|
|||
(ns build
|
||||
(:require [clojure.tools.build.api :as b]
|
||||
[clojure.pprint :refer [pprint]]
|
||||
[clojure.edn :as edn]))
|
||||
|
||||
(def lib 'org.fudo/notifier)
|
||||
(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" "16" "-target" "16"]})
|
||||
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- read-metadata [filename]
|
||||
(-> filename
|
||||
(slurp)
|
||||
(edn/read-string)))
|
||||
|
||||
(defn- process-params [base-params]
|
||||
(-> base-params
|
||||
(merge (read-metadata (or (:metadata base-params)
|
||||
"metadata.edn")))
|
||||
(update :target str)
|
||||
(update :version str)
|
||||
(update :java-src str)
|
||||
(update :clj-src str)))
|
||||
|
||||
(defn jar [base-params]
|
||||
(let [params (process-params base-params)
|
||||
{:keys [java-src clj-src 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}))
|
||||
(when verbose (println "done!"))
|
||||
params))
|
||||
|
||||
(defn uberjar [base-params]
|
||||
(let [params (process-params base-params)
|
||||
{:keys [java-src clj-src 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}))
|
||||
(when verbose (println "done!"))
|
||||
params))
|
||||
|
||||
(defn install [base-params]
|
||||
(let [params (process-params base-params)
|
||||
{:keys [version verbose]} params
|
||||
target-file (jar-file params)]
|
||||
(jar params)
|
||||
(when verbose (println (format "installing %s..." target-file)))
|
||||
(b/install {
|
||||
:basis basis
|
||||
:lib lib
|
||||
:version (str version)
|
||||
:jar-file target-file
|
||||
:class-dir (class-dir params)
|
||||
})
|
||||
params))
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
: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" }
|
||||
}
|
||||
:aliases {
|
||||
:install {
|
||||
:extra-deps {
|
||||
io.github.clojure/tools.build {:mvn/version "0.9.4"}
|
||||
}
|
||||
:ns-default build
|
||||
:exec-fn install
|
||||
}
|
||||
:build {
|
||||
:extra-deps {
|
||||
io.github.clojure/tools.build {:mvn/version "0.9.4"}
|
||||
}
|
||||
:ns-default build
|
||||
:exec-fn uberjar
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
:version "0.1"
|
||||
:target "target"
|
||||
:java-src "src/java"
|
||||
:clj-src "src/clj"
|
||||
:main-ns "notifier.core"
|
||||
:verbose true
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
(ns notifier.core
|
||||
(:import org.freedesktop.Notifications
|
||||
org.freedesktop.dbus.connections.impl.DBusConnectionBuilder
|
||||
org.freedesktop.dbus.types.UInt32))
|
||||
|
||||
(def ^:private ^:const NOTIFICATIONS_PATH "/org/freedesktop/Notifications")
|
||||
(def ^:private ^:const NOTIFICATIONS_BUS "org.freedesktop.Notifications")
|
||||
|
||||
(def urgencies {:low 0 :normal 1 :critical 2})
|
||||
|
||||
(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
|
||||
urgency :low}
|
||||
:as args}]
|
||||
(doseq [arg [:app :summary :body]]
|
||||
(when (not (contains? args arg))
|
||||
(throw (ex-info (format "missing required argument: %s" arg)
|
||||
{:arg arg}))))
|
||||
(let [urgency-lvl (get urgencies urgency)]
|
||||
(when (nil? urgency-lvl)
|
||||
(throw (ex-info (format "bad urgency level: %s" urgency) {}))
|
||||
(.Notify bus
|
||||
app
|
||||
(UInt32. replace-id)
|
||||
icon
|
||||
summary
|
||||
body
|
||||
actions
|
||||
{ "urgency" urgency-lvl }
|
||||
timeout))))
|
|
@ -0,0 +1,47 @@
|
|||
package org.freedesktop;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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 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 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 List<String> GetCapabilities();
|
||||
// public Quad<String, String, String, String> GetServerInformation();
|
||||
|
||||
public UInt32 Notify(
|
||||
String app_name,
|
||||
UInt32 replaces_id,
|
||||
String app_icon,
|
||||
String summary,
|
||||
String body,
|
||||
List<String> actions,
|
||||
Map<String, Variant<?>> hints,
|
||||
int expire_timeout);
|
||||
}
|
Loading…
Reference in New Issue