-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
44 changed files
with
612 additions
and
186 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 |
---|---|---|
@@ -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}} |
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 |
---|---|---|
@@ -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) |
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,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 | ||
)))) | ||
|
||
|
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,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))) |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
(ns kii.bindings.npm) | ||
|
||
(defonce usb (js/require "usb")) | ||
(defonce command-exists (js/require "command-exists")) |
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,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))) |
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,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) | ||
) |
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
Oops, something went wrong.