-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
notify.cljs
36 lines (29 loc) · 1.05 KB
/
notify.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(ns cljs-test-display.notify
(:require
[cljs-test-display.favicon :as favicon]
[goog.object :as gobj]))
(def notification (gobj/get goog.global "Notification"))
(defn with-permission [perm thunk]
(when notification
(when (= perm (gobj/get notification "permission"))
(thunk))))
(defn ask-permission! []
(with-permission "default"
#(.requestPermission notification)))
(def red-url (favicon/color-data-url "#d00" 512))
(def green-url (favicon/color-data-url "#0d0" 512))
(defn success []
(with-permission "granted"
#(js/Notification. "All CLJS Tests Passed"
#js {:icon green-url})))
(defn failure [{:keys [error fail]}]
(with-permission "granted"
#(js/Notification. "CLJS Tests Failed"
#js {:icon red-url
:body (str
(when fail
(str fail " failures "))
(when error
(str error " errors")))})))
#_(success)
#_(failure {})