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

Unified background and handler, background now handles clicks

https://app.asana.com/0/50978096561390/60848515380707
parent 5d075684
booklet.handler.init();
\ No newline at end of file
......@@ -3,7 +3,6 @@
"version": "0.2",
"browser_action": {
"default_title": "Show history",
"scripts": ["booklet.js", "handler.js"],
"default_icon": {
"19": "icon19.png",
"38": "icon38.png"
......@@ -20,8 +19,7 @@
"background": {
"scripts": [
"booklet.js",
"background.js",
"handler.js"
"background.js"
],
"persistent": false
},
......
......@@ -10,7 +10,9 @@
[khroma.storage :as storage]
[khroma.idle :as idle]
[khroma.tabs :as tabs]
[re-frame.core :refer [dispatch register-sub register-handler subscribe dispatch-sync]])
[re-frame.core :refer [dispatch register-sub register-handler subscribe dispatch-sync]]
[khroma.extension :as ext]
[khroma.browser-action :as browser])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
......@@ -300,5 +302,21 @@
(dispatch-sync [::initialize])
)
(defn init-click-handling []
(go-loop
[channel (browser/on-clicked)]
(when (<! channel)
(let [ext-url (str (ext/get-url "/") "index.html")
;; We could just get the window-id from the tab, but that still
;; requires us to make an extra call for the other tabs
window (<! (windows/get-current))
our-tab (first (filter #(= ext-url (:url %)) (:tabs window)))]
(if our-tab
(tabs/activate (:id our-tab))
(tabs/create {:url ext-url}))))
(recur channel)
))
(defn init []
(init-time-tracking))
(init-time-tracking)
(init-click-handling))
(ns booklet.handler
(:require [khroma.log :as console]
[khroma.browser-action :as browser]
[khroma.tabs :as tabs]
[khroma.extension :as ext]
[khroma.windows :as windows]
[cljs.core.async :refer [>! <!]])
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
(defn init []
(console/log "booklet.handler.init")
(go-loop
[channel (browser/on-clicked)]
(when (<! channel)
(let [ext-url (str (ext/get-url "/") "index.html")
;; We could just get the window-id from the tab, but that still
;; requires us to make an extra call for the other tabs
window (<! (windows/get-current))
our-tab (first (filter #(= ext-url (:url %)) (:tabs window)))]
(if our-tab
(tabs/activate (:id our-tab))
(tabs/create {:url ext-url}))))
(recur channel)
))
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