Commit 2b9ba786 authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Opening a window to list the open tabs

- Hooking up to tab modification events
- Removed the content script since we won't actually be modifying a
  page's content
- Added re-frame
- Maintaining open tab list updated through re-frame and reagent

https://app.asana.com/0/50978096561390/51083312127811
parent 2df44bc8
......@@ -5,15 +5,21 @@
[org.clojure/clojurescript "1.7.122"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[khroma "0.0.3-SNAPSHOT"]
[prismatic/dommy "1.1.0"]]
[prismatic/dommy "1.1.0"]
[re-frame "0.4.1"]]
:source-paths ["src"]
:profiles {:dev {:plugins [[lein-cljsbuild "1.1.0"]
[lein-chromebuild "0.3.0"]]
:profiles {:dev {:plugins [[lein-cljsbuild "1.1.0"]
[lein-chromebuild "0.3.0"]]
:cljsbuild {:builds {:main
{:source-paths ["src"]
:compiler {:output-to "target/unpacked/tabler.js"
:output-dir "target/js"
:optimizations :whitespace
:pretty-print true}}}}
:cljsbuild {:builds {:main
{:source-paths ["src"]
:compiler {:output-to "target/unpacked/tabler.js"
:output-dir "target/js"
:optimizations :whitespace
:pretty-print true}}}}
:chromebuild {:resource-paths ["resources/js"
"resources/html"
"resources/images"
"resources/css"]
:target-path "target/unpacked"}
}})
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tabler</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="shortcut icon" href="/favicon.png">
<link rel="stylesheet" href="/bootstrap.min.css" media="screen">
</head>
<body>
<div class="bs-component" id="navbar">
<!-- Sample content
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<li class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
</ul>
</div>
</div>
</nav>
-->
</div>
<div class="container">
<div id="tab-list">
To replace
</div>
<footer>
<div class="row">
<div class="col-sm-6 col-sm-offset-3" style="text-align: center">
<p>&copy <a href="http://numergent.com" target="_new">Numergent Limited</a></p>
</div>
</div>
</footer>
</div>
<script type="text/javascript" src="/tabler.js"></script>
<script type="text/javascript" src="/core.js"></script>
</body>
</html>
<script type="text/javascript" src="tabler.js"></script>
<script type="text/javascript" src="popup.js"></script>
A wild tabler appears
tabler.content.init();
tabler.core.init();
tabler.handler.init();
\ No newline at end of file
......@@ -3,7 +3,7 @@
"version": "0.1",
"browser_action": {
"default_title": "Show the popup",
"scripts": ["handler.js"],
"scripts": ["tabler.js", "handler.js"],
"default_icon": {
"19": "icon19.png",
"38": "icon38.png"
......@@ -17,22 +17,11 @@
"permissions": [
"tabs"
],
"content_scripts": [
{
"matches": [
"*://*/*"
],
"js": [
"tabler.js",
"content.js"
],
"run_at": "document_end"
}
],
"background": {
"scripts": [
"tabler.js",
"background.js"
"background.js",
"handler.js"
],
"persistent": false
},
......
(ns tabler.background
(:require [khroma.log :as console]
(:require [cljs.core.async :refer [>! <!]]
[khroma.log :as console]
[khroma.runtime :as runtime]
[cljs.core.async :refer [>! <!]])
[khroma.windows :as windows])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn init []
(go (let [conns (runtime/connections)
(go (let [conns (runtime/connections)
content (<! conns)]
(console/log "Content script said: " (<! content))
(>! content :fml-i-am-the-background-script)
(console/log "On background. Got message: " (<! content))
(>! content (.-tabs (<! (windows/get-current))))
(init))))
(ns tabler.content
(:require [khroma.runtime :as runtime]
[khroma.log :as console]
[khroma.tabs :as tabs]
[cljs.core.async :refer [>! <!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn init []
(let [bg (runtime/connect)]
(go (>! bg :lol-i-am-a-content-script)
(console/log "On content")
(console/log "Background said: " (<! bg)))))
(ns tabler.core
(:require [cljs.core.async :refer [>! <!]]
[clojure.walk :as walk]
[khroma.runtime :as runtime]
[khroma.log :as console]
[khroma.tabs :as tabs]
[reagent.core :as reagent]
[re-frame.core :refer [dispatch register-sub register-handler subscribe dispatch-sync]]
[khroma.windows :as windows])
(:require-macros [cljs.core.async.macros :refer [go]]
[reagent.ratom :refer [reaction]]))
;;;;------------------------------
;;;; Queries
;;;;------------------------------
(defn general-query
[db path]
(reaction (get-in @db path)))
(register-sub :tabs general-query)
;;;;----------------------------
;;;; Handlers
;;;;----------------------------
(register-handler
:initialize
(fn [_ [_ tabs]]
(.log js/console tabs)
(console/log "Initialized" tabs)
{:tabs tabs}))
(register-handler
:tab-created
(fn [app-state [_ msg]]
(console/log "Created" (:tab msg))
(assoc app-state :tabs (conj (:tabs app-state) (:tab msg)))))
(defn remove-tab
"Removed a tab from a collection by id"
[col id]
(remove #(= (:id %) id) col))
(register-handler
:tab-updated
(fn [app-state [_ msg]]
(console/log "Updated:" msg)
(assoc app-state
:tabs
(-> (:tabs app-state)
(remove-tab (:tabId msg))
(conj (:tab msg))))
))
(register-handler
:tab-removed
(fn [app-state [_ msg]]
(console/log "Removed:" (:tabId msg) msg)
(assoc app-state :tabs (remove-tab (:tabs app-state) (:tabId msg)))))
(register-handler
:tab-replaced
(fn [app-state [_ msg]]
(console/log "Replaced:" msg)
app-state))
;;;;----------------------------
;;;; Components
;;;;----------------------------
(defn list-tabs [tabs]
(for [tab (sort-by :index tabs)]
^{:key (:id tab)}
[:tr
[:td (:id tab)]
[:td (:title tab)]
[:td (:url tab)]]))
(defn tab-list []
(let [tabs (subscribe [:tabs])]
(fn []
[:table {:class "table table-striped table-hover"}
[:thead
[:tr
[:th "#"]
[:th "Title"]
[:th "URL"]]]
[:tbody
(list-tabs @tabs)]
])))
;;;;----------------------------
;;;; Chrome subscriptions
;;;;----------------------------
(defn dispatch-on-channel
"Dispatched msg when there's content received on the channel returned by
function chan-f."
[msg chan-f]
(go (while true
(let [content (<! (chan-f))]
(dispatch [msg content])))))
(defn mount-components []
(reagent/render-component [tab-list] (.getElementById js/document "tab-list")))
(defn init []
(console/log "Initialized tabler.core")
(go (let [c (<! (windows/get-current))]
(dispatch [:initialize (:tabs c)])))
(let [bg (runtime/connect)]
(dispatch-on-channel :tab-created tabs/tab-created-events)
(dispatch-on-channel :tab-removed tabs/tab-removed-events)
(dispatch-on-channel :tab-updated tabs/tab-updated-events)
(dispatch-on-channel :tab-replaced tabs/tab-replaced-events)
(go (>! bg :lol-i-am-a-popup)
(console/log "Background said: " (<! bg))))
(mount-components))
......@@ -2,6 +2,7 @@
(:require [khroma.log :as console]
[khroma.browser :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]]))
......@@ -12,8 +13,8 @@
(go (while true
(let [tab (<! conns)]
(console/log "On click handler. Tab: " tab)
(console/log "On window: " (<! (windows/get-current)))
(console/log "Active tab:" (<! (tabs/get-active-tab))))
(console/log "Listing tabs for the current window...")
(tabs/create {:url (str (ext/get-url "/" ) "index.html")})
(doseq [t (.-tabs (<! (windows/get-current)))]
(console/log "Tab: " t)))
))))
(init)
\ No newline at end of file
(ns tabler.popup
(:require [khroma.runtime :as runtime]
[khroma.log :as console]
[cljs.core.async :refer [>! <!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn init []
(let [bg (runtime/connect)]
(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