Add a warning when the host page unloads

Fixes #102
This commit is contained in:
Daniel Compton 2017-11-10 16:08:04 +13:00
parent e418ca820c
commit 4a0c4e2673
6 changed files with 35 additions and 6 deletions

View File

@ -474,6 +474,10 @@
#--re-frame-trace-- .re-frame-trace--object > span {
vertical-align: text-top;
}
#--re-frame-trace-- .host-closed {
font-size: 4em;
background-color: rgba(255, 255, 0, 0.8);
}
#--re-frame-trace-- .expansion-button {
font-family: sans-serif;
width: 16px;

View File

@ -575,6 +575,10 @@
}
}
.host-closed {
font-size: 4em;
background-color: fade(@yellow, 80%);
}
.expansion-button {
font-family: sans-serif;

View File

@ -7,10 +7,14 @@
[reagent.core :as r]))
(defn devtools-inner [traces opts]
(let [selected-tab (rf/subscribe [:settings/selected-tab])
panel-type (:panel-type opts)]
(let [selected-tab (rf/subscribe [:settings/selected-tab])
panel-type (:panel-type opts)
external-window? (= panel-type :popup)
unloading? (rf/subscribe [:global/unloading?])]
[:div.panel-content
{:style {:width "100%" :display "flex" :flex-direction "column"}}
(when (and external-window? @unloading?)
[:h1.host-closed "Host window has closed. Reopen external window to continue tracing."])
[:div.panel-content-top
[:div.nav
[:button {:class (str "tab button " (when (= @selected-tab :traces) "active"))
@ -20,10 +24,10 @@
#_[:button {:class (str "tab button " (when (= @selected-tab :subvis) "active"))
:on-click #(reset! selected-tab :subvis)} "SubVis"]
(when-not (= panel-type :popup)
(when-not external-window?
[:img.popout-icon
{:src (str "data:image/svg+xml;utf8,"
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 8 8\" x=\"0px\" y=\"0px\">\n <path fill=\"#444444\" d=\"M0 0v8h8v-2h-1v1h-6v-6h1v-1h-2zm4 0l1.5 1.5-2.5 2.5 1 1 2.5-2.5 1.5 1.5v-4h-4z\"/>\n</svg>\n")
{:src (str "data:image/svg+xml;utf8,"
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 8 8\" x=\"0px\" y=\"0px\">\n <path fill=\"#444444\" d=\"M0 0v8h8v-2h-1v1h-6v-6h1v-1h-2zm4 0l1.5 1.5-2.5 2.5 1 1 2.5-2.5 1.5 1.5v-4h-4z\"/>\n</svg>\n")
:on-click #(rf/dispatch-sync [:global/launch-external])}])]]
(case @selected-tab
:traces [traces/render-trace-panel traces]

View File

@ -13,5 +13,6 @@
(rf/dispatch [:settings/selected-tab selected-tab])
(rf/dispatch [:traces/filter-items filter-items])
(rf/dispatch [:app-db/paths app-db-paths])
(rf/dispatch [:global/add-unload-hook])
(when show-panel?
(rf/dispatch [:global/enable-tracing]))))

View File

@ -61,7 +61,7 @@
",resizable=yes,scrollbars=yes,status=no,directories=no,toolbar=no,menubar=no"))
d (.-document w)]
(.open d)
(.write d "<head></head><body><div id=\"--re-frame-trace--\" class=\"external-window\"></div></body>")
(.write d "<head></head><body style=\"margin: 0px;\"><div id=\"--re-frame-trace--\" class=\"external-window\"></div></body>")
(aset w "onload" #(mount w d))
(.close d)))
@ -91,6 +91,17 @@
(utils.traces/disable-tracing!)
nil))
(rf/reg-event-fx
:global/add-unload-hook
(fn [_ _]
(js/window.addEventListener "beforeunload" #(rf/dispatch-sync [:global/unloading? true]))
nil))
(rf/reg-event-db
:global/unloading?
(fn [db [_ unloading?]]
(assoc-in db [:global :unloading?] unloading?)))
;; Traces
(defn save-filter-items [filter-items]

View File

@ -25,3 +25,8 @@
:traces/filter-items
(fn [db _]
(get-in db [:traces :filter-items])))
(rf/reg-sub
:global/unloading?
(fn [db _]
(get-in db [:global :unloading?])))