Skip to content

Commit

Permalink
Show info about pending update
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadalm committed Jan 19, 2024
1 parent ae8c911 commit 231a5ff
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 4 deletions.
4 changes: 4 additions & 0 deletions resources/private/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ body {
user-select: none;
}

.message {
font-size: 1.2rem;
}

.form-label {
font-size: 1.2rem;
margin-bottom: 2rem;
Expand Down
2 changes: 1 addition & 1 deletion shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:compiler-options {:source-map true}
:dev {:closure-defines {"re_frame.trace.trace_enabled_QMARK_" true}}
:release {:module-hash-names true}
:devtools {:preloads [day8.re-frame-10x.preload]}
:devtools {:preloads [day8.re-frame-10x.preload.react-18]}
:build-hooks [(build.hook/hook {:public-dir "resources/public"})]
:target :browser}
:test {:target :node-test
Expand Down
19 changes: 18 additions & 1 deletion src/app/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@
(defn register-worker []
(some-> js/navigator
.-serviceWorker
(.register "worker.js")))
(.register "worker.js")
(.then
(fn [registration]
(if (and (.-waiting registration)
js/navigator.serviceWorker.controller)
(re-frame/dispatch [::events/update-available])
(.addEventListener
registration
"updatefound"
(fn []
(when-let [installing (.-installing registration)]
(.addEventListener
installing
"statechange"
(fn []
(when (and (.-waiting registration)
js/navigator.serviceWorker.controller)
(re-frame/dispatch [::events/update-available]))))))))))))

(defn- dev-setup []
(when config/debug?
Expand Down
5 changes: 5 additions & 0 deletions src/app/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@
(merge db data)
(reset-game data))})))

(re-frame/reg-event-fx
::update-available
(fn [{:keys [db]} _]
{:db (assoc-in db [:app-info :update-available] true)}))

(re-frame/reg-event-db
::reset
(fn [db _]
Expand Down
6 changes: 6 additions & 0 deletions src/app/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@
::settings
(fn [db _]
(:settings db)))

(re-frame/reg-sub
::messages
(fn [db _]
(cond-> []
(get-in db [:app-info :update-available]) (conj {:text "New version is available."}))))
8 changes: 7 additions & 1 deletion src/app/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,18 @@

(defn menu []
(let [settings @(re-frame/subscribe [::subs/settings])
app-info @(re-frame/subscribe [::subs/app-info])]
app-info @(re-frame/subscribe [::subs/app-info])
messages @(re-frame/subscribe [::subs/messages])]
[:div.menu
[:div.menu--header
[:button.close
{:on-click (fn [_] (re-frame/dispatch [::events/open-page :game]))}
[i/close]]]
(when (seq messages)
[:div.messages
(for [message messages]
^{:key (:text message)} [:div.message (:text message)])
[:hr]])
[:form
{:on-submit (fn [e]
(.preventDefault e)
Expand Down
2 changes: 1 addition & 1 deletion src/nenadalm/clojure_utils/re_frame/autosave.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
::ls/remove [autosave-key]}
{})))

(re-frame/dispatch [::autosave-load])
(re-frame/dispatch-sync [::autosave-load])
(js/document.addEventListener
"visibilitychange"
(fn []
Expand Down

0 comments on commit 231a5ff

Please sign in to comment.