Skip to content

Instantly share code, notes, and snippets.

@ponkore
Created August 4, 2012 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ponkore/3254119 to your computer and use it in GitHub Desktop.
Save ponkore/3254119 to your computer and use it in GitHub Desktop.
[misaki] テンプレート保存時にコンパイルエラーが発生した時に、Mac の Growl に通知を出してみる。
diff --git a/project.clj b/project.clj
index 99624f3..5b53fba 100644
--- a/project.clj
+++ b/project.clj
@@ -9,6 +9,7 @@
[clj-time "0.3.7"]
[clj-text-decoration "0.0.1"]
[clj-pretty-error "0.0.5"]
+ [clj-gntp "0.0.1"] ; https://github.com/mattn/clj-gntp
[uochan/watchtower "0.1.2"]
[de.ubercode.clostache/clostache "1.3.0"]]
diff --git a/src/misaki/core.clj b/src/misaki/core.clj
index 27ddb23..50ad9cc 100644
--- a/src/misaki/core.clj
+++ b/src/misaki/core.clj
@@ -6,6 +6,8 @@
[hiccup.core :only [html]]
[hiccup.page :only [html5 xhtml html4]]
[pretty-error.core :only [print-pretty-stack-trace]]
+ [clj-gntp.core :only [growl-notify]]
+ [clojure.java.shell :as shell]
[cljs.closure :only [build]])
(:require
[clojure.string :as str]
@@ -14,7 +16,20 @@
(declare file->template-sexp)
+;;; TODO: 下記関数類を整理する(utilあたりに統合?)
+;;; TODO: growl-notify 関数の仕様、実装、があまりイケてない。要 rewrite?
+(def linux? (= "Linux" (System/getProperty "os.name")))
+(defn- notify-send [title body] (shell/sh "notify-send" title body))
+(defn- growl [title body] (growl-notify title body "url" "icon"))
+
+(defn- notify-error [e]
+ "Notify the error message to desktop notification service."
+ (let [notify-fn (if linux? notify-send growl)
+ message (.getMessage e)]
+ (notify-fn "misaki" message)))
+
(defn- print-misaki-stack-trace [e]
+ (notify-error e)
(print-pretty-stack-trace
e :filter #(str-contains? (:str %) "misaki")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment