Skip to content
This repository has been archived by the owner on Nov 13, 2017. It is now read-only.

Commit

Permalink
Finish new update system and fix issue caused by delayed preference w…
Browse files Browse the repository at this point in the history
…rites
  • Loading branch information
oakes committed Jun 30, 2013
1 parent 6034850 commit a00dbe1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion desktop/resources/nw.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ if (currentParams.userhash) {
}

// display the update button if necessary
if (latest && latest.indexOf(version) < 0) {
if (latest && latest.indexOf(current) < 0) {
$('#update-button').attr('href', latest);
$('#update-button').show();
}
2 changes: 1 addition & 1 deletion desktop/src/nightweb_desktop/pages.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
[:script {:src "spin.min.js"}]
[:script (format "var latest = null;\nvar current = '%s';"
(utils/get-version))]
(when (utils/read-pref :update)
(when @utils/update?
[:script {:src "https://nightweb.net/latest.js"}])
[:script {:src "nw.js"}]]))

Expand Down
4 changes: 1 addition & 3 deletions desktop/src/nightweb_desktop/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
(when @server (.stop @server))
(reset! server (jetty/run-jetty (multi/wrap-multipart-params handler)
{:port @port
:host (if (utils/read-pref :remote)
nil
"127.0.0.1")
:host (if @utils/remote? nil "127.0.0.1")
:join? false})))

(defn set-port
Expand Down
15 changes: 11 additions & 4 deletions desktop/src/nightweb_desktop/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
[ring.util.codec :as codec]))

(def prefs (.node (java.util.prefs.Preferences/userRoot) "nightweb"))
(def strings (-> (java.io/resource "strings.xml")
(.toString)
(xml/parse)
(:content)))

(defn write-pref
[k v]
Expand All @@ -21,6 +17,17 @@
(when-let [string (.get prefs (name k) nil)]
(read-string string)))

(def update? (atom (read-pref :update)))
(def remote? (atom (read-pref :remote)))

(when (nil? @update?)
(write-pref :update true))

(def strings (-> (java.io/resource "strings.xml")
(.toString)
(xml/parse)
(:content)))

(defn get-string
"Returns the localized string for the given keyword."
[res-name]
Expand Down
42 changes: 20 additions & 22 deletions desktop/src/nightweb_desktop/window.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[nightweb-desktop.server :as server]
[nightweb-desktop.utils :as utils]))

(def external-ip (delay (try (slurp "http://checkip.amazonaws.com/")
(def external-ip (delay (try (-> (slurp "http://checkip.amazonaws.com/")
(clojure.string/replace "\n" ""))
(catch Exception e nil))))

(declare update-window-content)
Expand All @@ -25,22 +26,24 @@
(defn get-main-items
"Returns items to always display in the window."
[ui-root]
(let [update? (utils/read-pref :update)
remote? (utils/read-pref :remote)]
[(s/button :text (utils/get-string :open_in_browser)
[(s/button :text (utils/get-string :open_in_browser)
:listen [:action (fn [e]
(-> (str "http://localhost:" @server/port)
open-in-browser))])
(s/checkbox :text (utils/get-string :check_for_updates)
:selected? @utils/update?
:listen [:action (fn [e]
(-> (str "http://localhost:" @server/port)
open-in-browser))])
(s/checkbox :text (utils/get-string :check_for_updates)
:selected? update?
:listen [:action (fn [e]
(utils/write-pref :update (not update?)))])
(s/checkbox :text (utils/get-string :enable_remote)
:selected? remote?
:listen [:action (fn [e]
(utils/write-pref :remote (not remote?))
(server/start-server)
(update-window-content ui-root))])]))
(->> (not @utils/update?)
(reset! utils/update?)
(utils/write-pref :update)))])
(s/checkbox :text (utils/get-string :enable_remote)
:selected? @utils/remote?
:listen [:action (fn [e]
(->> (not @utils/remote?)
(reset! utils/remote?)
(utils/write-pref :remote))
(server/start-server)
(update-window-content ui-root))])])

(defn get-remote-items
"Returns items to only display when remote access is enabled."
Expand All @@ -60,7 +63,7 @@
"Updates the items in the window."
[ui-root]
(let [main-items (get-main-items ui-root)
items (if (utils/read-pref :remote)
items (if @utils/remote?
(concat main-items (get-remote-items ui-root))
main-items)]
(s/config! (s/select ui-root [:#grid])
Expand All @@ -72,14 +75,9 @@
(defn start-window
"Launches the main window."
[]
; set the look-and-feel
(s/native!)
(org.pushingpixels.substance.api.SubstanceLookAndFeel/setSkin
(org.pushingpixels.substance.api.skin.GraphiteSkin.))
; default update checking to true
(when (nil? (utils/read-pref :update))
(utils/write-pref :update true))
; display the window
(s/invoke-later
(-> (s/frame :title (str (utils/get-string :app_name)
" "
Expand Down

0 comments on commit a00dbe1

Please sign in to comment.