-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from brianium/feature/tray
Adds tray support
- Loading branch information
Showing
12 changed files
with
137 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(ns tomaat.main.tray | ||
(:require [electron :refer [Tray nativeImage]] | ||
[tomaat.util :as u])) | ||
|
||
(defonce *tray (atom nil)) | ||
|
||
(defn update-tray! | ||
[event url] | ||
(let [img (.createFromDataURL nativeImage url)] | ||
(when (nil? @*tray) | ||
(reset! *tray (Tray. img))) | ||
(.setImage @*tray img))) | ||
|
||
(defn remove-tray! | ||
[event] | ||
(when @*tray | ||
(.destroy @*tray) | ||
(reset! *tray nil))) | ||
|
||
(defn listen! [] | ||
(u/on-ipc-main "update-tray" update-tray!) | ||
(u/on-ipc-main "remove-tray" remove-tray!) | ||
(u/on-app "window-all-closed" remove-tray!)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(ns tomaat.ui.tray | ||
"Handles generating a data url for the tomaat tray" | ||
(:require [tomaat.util :as u] | ||
[tomaat.ui.timer :refer [time->string]])) | ||
|
||
(defn- make-canvas [width height] | ||
(let [canvas (.createElement js/document "canvas")] | ||
(set! (.-width canvas) width) | ||
(set! (.-height canvas) height) | ||
canvas)) | ||
|
||
(defonce *canvas (atom (make-canvas 40 14))) | ||
|
||
(defn- data-uri | ||
[canvas] | ||
(let [url (.toDataURL canvas) | ||
context (.getContext canvas "2d")] | ||
(.clearRect context 0 0 (.-width canvas) (.-height canvas)) | ||
url)) | ||
|
||
(defn- write-text | ||
[canvas text] | ||
(let [ctx (.getContext canvas "2d")] | ||
(set! (.-font ctx) "14px Lato") | ||
(set! (.-fillStyle ctx) "#444") | ||
(set! (.-textAlign ctx) "start") | ||
(set! (.-textBaseline ctx) "middle") | ||
(.fillText ctx text 2 7) | ||
(data-uri canvas))) | ||
|
||
(defn time->url | ||
"Given a time vector - generate a data url for it" | ||
[time] | ||
(->> (time->string time) | ||
(write-text @*canvas))) | ||
|
||
(defn update! | ||
"Update the tray with a new time value" | ||
[time] | ||
(->> time | ||
time->url | ||
(u/send-ipc "update-tray"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.