Skip to content

Commit

Permalink
Flashing Support & Re-org
Browse files Browse the repository at this point in the history
Flashing support (flash right after a download) Also a whole lot of reorg on code to try
and bring it more in line with the intent for code organization.
  • Loading branch information
jbondeson committed Oct 31, 2017
1 parent 38d0fc7 commit 21ce26c
Show file tree
Hide file tree
Showing 44 changed files with 612 additions and 186 deletions.
5 changes: 4 additions & 1 deletion build.boot
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
[funcool/cuerdas "2.0.4"]
[com.taoensso/timbre "4.10.0"]
[cljsjs/chroma "1.1.1-0"]
[cljsjs/jszip "3.1.3-0"]
[cljs-node-io "0.5.0"]
[cljsjs/localforage "1.5.3-0"]
]
:source-paths #{"src"}
;;:asset-paths #{"assets"}
Expand All @@ -61,7 +64,7 @@
(comp (cljs :ids #{"main"}
:optimizations :simple)
(cljs :ids #{"renderer"}
;; TODO -Some odd munging happening in advanced mode.
;; TODO - Need to figure out all the different externs needed.
:optimizations :none ;:advanced
:compiler-options {:load-tests false})
;; Right now an npm-install will call a naked `target` call clearing everything
Expand Down
58 changes: 30 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kiibohd-configurator",
"productName": "Kiibohd Configurator",
"version": "0.1.0-alpha6",
"version": "0.1.0-alpha7",
"description": "Configuration utility for Input Club keyboards",
"keywords": [],
"dependencies": {
Expand All @@ -13,7 +13,7 @@
},
"devDependencies": {
"cross-env": "^5.1.0",
"electron": "1.7.9",
"electron": "1.8.2-beta.1",
"electron-builder": "^19.39.0"
},
"author": "Jeremy Bondeson <jbondeson@gmail.com> (https://input.club)",
Expand Down
4 changes: 3 additions & 1 deletion resources/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kiibohd-configurator",
"productName": "Kiibohd Configurator",
"version": "0.1.0-alpha6",
"version": "0.1.0-alpha7",
"main": "main.js",
"description": "Configuration utility for Input Club keyboards",
"author": "Jeremy Bondeson <jbondeson@gmail.com> (https://input.club)",
Expand All @@ -11,7 +11,9 @@
"url": "https://github.com/kiibohd/configurator"
},
"dependencies": {
"mkdirp": "^0.5.1",
"electron-dl": "^1.10.0",
"command-exists": "^1.2.2",
"usb": "https://github.com/tessel/node-usb.git#1.3.0",
"react": "^15.6.2",
"react-dom": "^15.6.2",
Expand Down
2 changes: 1 addition & 1 deletion resources/renderer.cljs.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:require [kii.ui.core]
{:require [kii.ui.startup]
:init-fns [kii.ui.startup/init]
:compiler-options {:language-in :ecmascript5
:language-out :ecmascript5}}
4 changes: 3 additions & 1 deletion src/kii/bindings/cljsjs.cljs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(ns kii.bindings.cljsjs
(:require [cljsjs.chroma :as chroma]))
(:require [cljsjs.chroma]
[cljsjs.jszip]))

(def chroma js/chroma)
(def jszip js/JSZip)
6 changes: 6 additions & 0 deletions src/kii/bindings/electron_renderer.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(ns kii.bindings.electron-renderer)

(defonce electron (js/require "electron"))
(defonce child-process (js/require "child_process"))
(def remote (.-remote electron))
(def ipc (.-ipcRenderer electron))
(def shell (.-shell electron))
(def dialog (.-dialog remote))
(def app (.-app remote))

(def user-data-dir (.getPath app "userData"))

(defn send-to-main [event]
(.send ipc (:name event) (:arg event)))
Expand Down
38 changes: 38 additions & 0 deletions src/kii/bindings/node/fs.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(ns kii.bindings.node.fs
(:require [cljs.core.async :refer [chan <! >! put! close!]]
[kii.bindings.cljsjs :refer [jszip]]
[kii.macros :refer-macros [<? go-try p->chan cb->chan]])
)

(def -fs (js/require "fs"))
(def -mkdirp (js/require "mkdirp"))

(defn read-file
([path] (cb->chan (.readFile -fs path)))
([path opts] (cb->chan (.readFile -fs path (clj->js opts)))))

(defn read-file!
([path] (.readFileSync -fs path))
([path opts] (.readFileSync -fs path (clj->js opts))))

(defn write-file
([path contents] (cb->chan (.writeFile -fs path contents)))
([path contents opts] (cb->chan (.writeFile -fs path (clj->js opts)))))

(defn write-file!
([path contents] (.writeFileSync -fs path contents))
([path contents opts] (.writeFileSync -fs path (clj->js opts))))

;; TODO - CLJSJS mkdirp
(defn mkdirp
[path]
(cb->chan (-mkdirp path)))

(defn make-dir!
([path]
(try
(.mkdirSync -fs path)
(catch js/Error e
))))


12 changes: 12 additions & 0 deletions src/kii/bindings/node/path.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns kii.bindings.node.path
(:require [kii.util :as util]))

(def -path (js/require "path"))

(defn parse
[path]
(util/jsx->clj (.parse -path path)))

(defn join
[& paths]
(apply (.-join -path) (clj->js paths)))
1 change: 1 addition & 0 deletions src/kii/bindings/npm.cljs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(ns kii.bindings.npm)

(defonce usb (js/require "usb"))
(defonce command-exists (js/require "command-exists"))
2 changes: 1 addition & 1 deletion src/kii/config/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
:y (- (:y %) min-top)
:layers (normalize-layers (:layers %))})
matrix))
:defines (mapv #({:id (random-uuid) :data %})
:defines (mapv (fn [d] {:id (random-uuid) :data d})
defines)
:leds leds
:custom custom
Expand Down
75 changes: 75 additions & 0 deletions src/kii/macros.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
(ns kii.macros)

(defmacro <?
[ch]
`(let [~'res (~'<! ~ch)]
(when (instance? js/Error ~'res)
(throw ~'res))
~'res))

(defmacro go-try
[& body]
`(~'go
(try
~@body
(catch js/Error e# e#))))

(defmacro cb->chan*
[form cb]
`(let [~'c (~'chan)]
(~@form ~cb)
~'c))

(defmacro cb->chan
"Convert a promise into a core.async channel, dump the results to the channel."
([form]
(let [cb `(fn [~'e ~'data]
(cond
(some? ~'e) (~'put! ~'c ~'e)
(some? ~'data) (~'put! ~'c ~'data))
(~'close! ~'c))]
`(cb->chan* ~form ~cb)))
([form transform]
(let [cb `(fn [~'e ~'data]
(cond
(some? ~'e) (~'put! ~'c ~'e)
(some? ~'data) (~'put! ~'c (~transform ~'data)))
(~'close! ~'c))]
`(cb->chan* ~form ~cb)))
)

(defmacro p->chan*
[form on-fulfilled on-rejected]
`(let [~'c (~'chan)
~'p (~@form)]
(.then ~'p ~on-fulfilled)
(.catch ~'p ~on-rejected)
~'c)
)

(defmacro p->chan
"Convert a promise into a core.async channel, dump the results to the channel."
([form]
(let [cb `(fn [~'data]
(when (some? ~'data) (~'put! ~'c ~'data))
(~'close! ~'c))
err `(fn [~'e]
(when (some? ~'e) (~'put! ~'c ~'e))
(~'close! ~'c))]
`(p->chan* ~form ~cb ~err))
)
([form transform]
(let [cb `(fn [~'data]
(when (some? ~'data) (~'put! ~'c (~transform ~'data)))
(~'close! ~'c))
err `(fn [~'e]
(when (some? ~'e) (~'put! ~'c ~'e))
(~'close! ~'c))]
`(p->chan* ~form ~cb ~err))
)
)


(defmacro go-let
[bindings & body]
`(~'go (let ~bindings ~@body)))
37 changes: 37 additions & 0 deletions src/kii/store.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(ns kii.store
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [taoensso.timbre :as timbre :refer-macros [log logf]]
[cljs.core.async :refer [chan <! >! put! close!]]
[kii.bindings.cljsjs :refer [jszip]]
[kii.macros :refer-macros [<? go-try p->chan cb->chan]]
[kii.bindings.node.fs :as fs]
[kii.bindings.node.path :as path]
[kii.bindings.electron-renderer :refer [user-data-dir]]
))

(def bin-file "kiibohd.dfu.bin")
(def cache-dir "firmware-cache")

;; TODO - Parse Filename
(defn cache-firmware
[zip-file]
(let [c (chan)]
(go
(try
(let [out-dir (path/join user-data-dir cache-dir (-> zip-file path/parse :name))
bin-out (path/join out-dir bin-file)
_ (<? (fs/mkdirp out-dir))
file (<? (fs/read-file zip-file))
zip (<? (p->chan (.loadAsync jszip file)))
data (<? (p->chan (-> zip (.file bin-file) (.async "nodebuffer"))))
]
(fs/write-file! bin-out data)
(logf :info "Successfully extracted firmware to local cache: %s" bin-out)

(put! c bin-out)
)
(catch js/Error e
(logf :error e "Error extracting firmware")))
)
c)
)
2 changes: 1 addition & 1 deletion src/kii/test/runner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [cljs.test :as test :include-macros true :refer [report]]
[kii.device.keyboard-test]
[kii.ui.alert.handlers-test]
[kii.ui.base.handlers-test]
[kii.ui.handlers-test]
[kii.ui.device.handlers-test]))

(defn run []
Expand Down
6 changes: 5 additions & 1 deletion src/kii/ui/alert/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
(let [alerts (vec (:alerts db))]
(assoc db :alerts (filterv (complement #{alert}) alerts))))

(rf/reg-event-db :alert/remove remove-alert)
(rf/reg-event-db :alert/remove remove-alert)

(rf/reg-event-db :alert/remove-all
(fn [db _]
(assoc db :alerts [])))
Loading

0 comments on commit 21ce26c

Please sign in to comment.