Skip to content

Commit

Permalink
Merge branch 'master' of github.com:oakmac/cuttle
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunlebron committed Jan 28, 2015
2 parents 7750fd6 + f0e05da commit 6414dfe
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 14 deletions.
6 changes: 3 additions & 3 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name" : "Cuttle",
"version" : "DEV",
"build-commit" : "",
"build-timestamp" : "",
"version" : "0.0-DEV",
"build-commit" : "0000000000000000000000000000000000000000",
"build-date" : "0000-00-00",
"main" : "app.js"
}
29 changes: 29 additions & 0 deletions less/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -702,3 +702,32 @@ body {
padding: 12px;
opacity: 0.50;
}

.info-bar-b38b4 {
background: #ff6;
color: #000;
.font-normal(16px);
padding: 15px 20px;

.fa {
margin-right: 8px;
}
}

.show-me-btn-16a12 {
background: @primaryGreen;
border: 0;
border-radius: 2px;
color: #fff;
display: inline-block;
margin-left: 10px;
padding: 6px 12px;
}

.ignore-link-ff917 {
color: @activeBlue;
color: #20c;
cursor: pointer;
display: inline-block;
margin-left: 10px;
}
6 changes: 3 additions & 3 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fi
META=`head -n 1 project.clj`
NAME=`echo $META | cut -d' ' -f2`
VERSION=`echo $META | cut -d' ' -f3 | tr -d '"'`
BUILD_TIMESTAMP=`date`
BUILD_COMMIT=`git rev-parse HEAD`
BUILD_DATE=`date +'%F'`

BUILDS=builds
mkdir -p $BUILDS
Expand All @@ -71,8 +71,8 @@ cp -R app $RELEASE_RSRC
# write build version, timestamp, and commit hash
json -I -f $RELEASE_RSRC/app/package.json \
-e "this[\"version\"]=\"$VERSION\"" \
-e "this[\"build-timestamp\"]=\"$BUILD_TIMESTAMP\"" \
-e "this[\"build-commit\"]=\"$BUILD_COMMIT\""
-e "this[\"build-commit\"]=\"$BUILD_COMMIT\"" \
-e "this[\"build-date\"]=\"$BUILD_DATE\""

# copy node_modules
mkdir $RELEASE_RSRC/app/node_modules
Expand Down
86 changes: 79 additions & 7 deletions src-cljs/cuttle/main_page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
[cljs.core.async.macros :refer [go]])
(:require
[cljs.core.async :refer [<!]]
[clojure.string :refer [blank? join replace]]
[clojure.string :refer [blank? join replace split trim]]
[clojure.walk :refer [keywordize-keys]]
[cuttle.config :refer [app-data-path config]]
[cuttle.dom :refer [by-id hide-el! show-el!]]
[cuttle.exec :as exec]
[cuttle.projects :as projects :refer [load-project-file]]
[cuttle.util :refer [current-version date-format file-exists? homedir log
js-log now on-linux? on-mac? on-windows? uuid
write-file-async!]
:refer-macros [while-let]]
[cuttle.util :refer [
build-commit build-date current-version date-format file-exists? homedir
js-log log now on-linux? on-mac? on-windows? uuid write-file-async!]
:refer-macros [while-let]]
goog.events.KeyCodes
[quiescent :include-macros true]
[sablono.core :as sablono :include-macros true]))

(def http (js/require "http"))
(def ipc (js/require "ipc"))
(def open (js/require "open"))
(def path (js/require "path"))
Expand All @@ -42,6 +43,8 @@
:new-project-error nil
:new-project-name ""
:new-project-step 1
:new-version-bar-showing? false
:new-version-num nil
:projects {:order []}
:settings-modal-showing? false
})
Expand All @@ -55,6 +58,41 @@
(let [proj-keys (-> project-map :order)]
(mapv #(get project-map %) proj-keys)))

;;------------------------------------------------------------------------------
;; Check for Updates
;;------------------------------------------------------------------------------

(def latest-version-url "http://cljs.info/cuttle-latest.json")

;; NOTE: I was sick while writing this function; please don't judge ;)
;; TODO: should do some simple checking that the version number is in a valid
;; format
(defn- check-version2 [new-version]
(when (string? new-version)
(let [arr (split (trim new-version) ".")
new-major (int (first arr))
new-minor (int (second arr))
new-num (+ (* new-major 10000) new-minor)

arr2 (split (trim current-version) ".")
our-major (int (first arr2))
our-minor (int (second arr2))
our-num (+ (* our-major 10000) our-minor)]
(when (> new-num our-num)
(swap! state assoc :new-version-bar-showing? true
:new-version-num (trim new-version))))))

(defn- check-version! []
(.get http latest-version-url (fn [js-res]
(let [data (atom "")]
(.setEncoding js-res "utf8")
(.on js-res "data" #(swap! data str %))
(.on js-res "end" (fn []
(when-let [result (try (.parse js/JSON @data)
(catch js/Error _error nil))]
(js-log result)
(check-version2 (aget result "version")))))))))

;;------------------------------------------------------------------------------
;; Project State
;;------------------------------------------------------------------------------
Expand Down Expand Up @@ -495,6 +533,9 @@
;; Events
;;------------------------------------------------------------------------------

(defn- click-maybe-later []
(swap! state assoc :new-version-bar-showing? false))

;; TODO: this will not work if they click outside the app root element
;; need to refactor
(defn- click-root []
Expand Down Expand Up @@ -597,6 +638,11 @@
(defn- click-go-back-btn []
(swap! state assoc :new-project-step 1))

(def releases-url "https://github.com/oakmac/cuttle/releases")

(defn- click-show-me-btn []
(open releases-url))

(defn- click-open-project-folder!
[filename]
(let [dirname (.dirname path filename)]
Expand Down Expand Up @@ -799,10 +845,18 @@
[:span.link-e7e58 {:on-click show-new-project-modal}
"add one"] "?"]]])

(defn- version-tooltip []
(str
"Version: " current-version "\n"
"Released: " build-date "\n"
"Commit: " (subs build-commit 0 10)))

(sablono/defhtml header []
[:div.header-a4c14
[:img.logo-0a166 {:src "img/cuttle-logo.svg"}]
[:div.title-8749a "Cuttle" [:span.version-8838a (str "v" current-version)]]
[:div.title-8749a
"Cuttle"
[:span.version-8838a {:title (version-tooltip)} (str "v" current-version)]]
[:div.title-links-42b06
[:span.link-3d3ad
{:on-click click-settings-link}
Expand Down Expand Up @@ -873,6 +927,18 @@
; [:div.modal-bottom-050c3
; [:button {:on-click close-add-project-modal} "Got it!"]]])

;; TODO: make this a quiescent component
(sablono/defhtml new-version-bar [new-version]
[:div.info-bar-b38b4
[:i.fa.fa-info-circle]
(str "A new version of Cuttle (v" new-version ") is available!")
[:button.show-me-btn-16a12
{:on-click click-show-me-btn}
"Show me"]
[:span.ignore-link-ff917
{:on-click click-maybe-later}
"Maybe later"]])

;;------------------------------------------------------------------------------
;; Quiescent Components
;;------------------------------------------------------------------------------
Expand Down Expand Up @@ -1002,6 +1068,8 @@
(when (:settings-modal-showing? app-state)
(list (modal-overlay click-settings-modal-overlay)
(SettingsModal (select-keys app-state settings-modal-keys))))
(when (:new-version-bar-showing? app-state)
(new-version-bar (:new-version-num app-state)))
[:div.app-ca3cd {:on-click click-root}
(header)
(let [projects (-> app-state :projects get-ordered-projects)]
Expand Down Expand Up @@ -1071,4 +1139,8 @@

;; trigger initial UI render even if proj-filenames is empty
;; TODO: probably should change the way init-projects! works
(swap! state identity))
(swap! state identity)

;; check for updates if we are not in dev mode
(when (neg? (.indexOf current-version "DEV"))
(check-version!)))
5 changes: 4 additions & 1 deletion src-cljs/cuttle/util.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
;; Version
;;------------------------------------------------------------------------------

(def current-version (aget (js/require "./package.json") "version"))
(def package-json (js/require "./package.json"))
(def current-version (aget package-json "version"))
(def build-date (aget package-json "build-date"))
(def build-commit (aget package-json "build-commit"))

;;------------------------------------------------------------------------------
;; Util Functions
Expand Down

0 comments on commit 6414dfe

Please sign in to comment.