                  (not= (:id last-focused) (:windowId tab)))
         (dispatch [::window-focus {:windowId (:id last-focused)}])))))
 
-(defn process-tab
-  "Filters a tab down to the relevant keys, and adds a start time which is
-  now if the tab is active, or 0 otherwise.
-
-  Keeping the time on the tab itself, since we may end up with multiple tabs
-  open to the same URL. Might make sense to track it all in one, using always
-  the last one... but for now I'm assuming that if you have it active in two
-  tabs, it's doubly important (you found it twice and forgot about it)."
-  [tab]
-  (->
-    tab
-    select-tab-keys
-    add-tab-times))
-
-
-(defn tab-list-to-map
-  [tabs]
-  (reduce #(assoc % (:id %2) %2) {} tabs))
-
-(defn process-tabs
-  "Take the tabs we have, filter them down and return them grouped by id."
-  [tabs]
-  (->>
-    tabs
-    (map process-tab)
-    tab-list-to-map))
+
+(defn hook-to-channels
+  "Hooks up to the various events we'll need to set up to.
+  We won't call it until after the initial import is done, so that we
+  don't end up receiving events when we don't yet have the environment
+  set up to handle them."
+  []
+  (on-channel alarms/on-alarm dispatch-sync ::on-alarm)
+  (on-channel runtime/on-suspend dispatch-sync :suspend)
+  (on-channel runtime/on-suspend-canceled dispatch-sync :log-content)
+  (on-channel tabs/on-activated dispatch ::tab-activated)
+  (on-channel tabs/on-updated dispatch ::tab-updated)
+  (on-channel windows/on-focus-changed dispatch ::window-focus)
+  (idle/set-detection-interval 60)
+  (on-channel idle/on-state-changed dispatch :idle-state-change))
 
 
 ;;;;-------------------------------------

          is-same?     (and (= (:id old-tab) (:id current-tab))
                            (= (:url old-tab) (:url current-tab))
                            (= (:windowId old-tab) (:windowId current-tab)))]
      ;; De-activate every inactive tab
      (if is-same?
        (dispatch [:handle-deactivation old-tab (:time suspend-info)])
        (dispatch [:handle-activation old-tab (:start-time old-tab)]))
      (console/trace "From suspend:" is-same? suspend-info)
      (dispatch [:data-set :suspend-info] nil)
      app-state
      )




;;;;-------------------------------------
;;;; Settings
;;;;-------------------------------------


(def window-alarm "window-alarm")

(defn now [] (.now js/Date))


(def relevant-tab-keys [:windowId :id :active :url :selected :start-time :title :favIconUrl])

(def select-tab-keys #(select-keys % relevant-tab-keys))
(def url-time-path [:data :url-times])

;;;;-------------------------------------
;;;; Functions
;;;;-------------------------------------


(defn check-window-status
