Commit d1aeda19 authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Handling idle state

parent dac0f052
......@@ -92,6 +92,31 @@
:start-time 0)))))
(fn [app-state [_ message]]
(let [state (:newState message)
all-tabs (get-in app-state tab-data-path)
active-tabs (if (= "active" state)
(get-in app-state [:app-state :idle])
(filter :active (vals all-tabs)))
message (if (= "active" state) :handle-activation :handle-deactivation)]
(console/log "State changed to" state message)
(doseq [tab active-tabs]
(dispatch [message tab]))
;; We only store the idle tabs on the app state if we actually idled any.
;; That way we avoid losing the originally stored idled tabs when we
;; first go from active->idle and then from idle->locked (the first one
;; would find tabs, the second one would and would overwrite the original
;; saved set with an empty list).
(if active-tabs
(assoc-in app-state [:app-state :idle] active-tabs)
(fn [app-state [_ {:keys [activeInfo]}]]
......@@ -161,23 +161,6 @@
(fn [app-state [_ message]]
(let [path [:app-state :interval]
handler (get-in app-state path)
state (:newState message)]
(console/log "Idle state change:" state handler)
(and (nil? handler)
(= state "active")) (assoc-in app-state path (js/setInterval #(dispatch [:snapshot-take]) 60000))
(and (some? handler)
(not= state "active")) (do
(js/clearInterval handler)
(assoc-in app-state path nil))
:else app-state
......@@ -528,8 +511,7 @@
(console/log api-uri)
(go (let [window (<! (windows/get-current))
state (<! (idle/query-state 30))]
(dispatch-sync [:initialize (:tabs window)])
(dispatch-sync [:idle-state-change {:newState state}])))
(dispatch-sync [:initialize (:tabs window)])))
(let [bg (runtime/connect)]
(dispatch-on-channel :log-content storage/on-changed)
(dispatch-on-channel :tab-created tabs/on-created)
......@@ -537,7 +519,6 @@
(dispatch-on-channel :tab-updated tabs/on-updated)
(dispatch-on-channel :tab-replaced tabs/on-replaced)
(idle/set-detection-interval 60)
(dispatch-on-channel :idle-state-change idle/on-state-changed)
(go (>! bg :lol-i-am-a-popup)
(console/log "Background said: " (<! bg))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment