Commit 0ef6c4b0 authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Trivial local storage implementation

https://app.asana.com/0/50978096561390/51318224220896
parent 2b9ba786
......@@ -15,7 +15,7 @@
"128": "icon128.png"
},
"permissions": [
"tabs"
"tabs", "storage"
],
"background": {
"scripts": [
......
......@@ -9,5 +9,5 @@
(go (let [conns (runtime/connections)
content (<! conns)]
(console/log "On background. Got message: " (<! content))
(>! content (.-tabs (<! (windows/get-current))))
(>! content "Hello from background")
(init))))
......@@ -3,6 +3,7 @@
[clojure.walk :as walk]
[khroma.runtime :as runtime]
[khroma.log :as console]
[khroma.storage :as storage]
[khroma.tabs :as tabs]
[reagent.core :as reagent]
[re-frame.core :refer [dispatch register-sub register-handler subscribe dispatch-sync]]
......@@ -44,6 +45,12 @@
[col id]
(remove #(= (:id %) id) col))
(register-handler
:log-content
(fn [app-state [_ content]]
(console/log "Log event:" content)
app-state
))
(register-handler
:tab-updated
......@@ -85,14 +92,20 @@
(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)]
[:div
[:table {:class "table table-striped table-hover"}
[:thead
[:tr
[:th "#"]
[:th "Title"]
[:th "URL"]]]
[:tbody
(list-tabs @tabs)]
]
[:button {:on-click #(storage/set {:links (map (fn [m] (select-keys m [:index :url])) @tabs)})} "Save me"]
[:button {:on-click #(go (console/log (<! (storage/get nil))))} "Get"]
[:button {:on-click #(go (console/log "Usage: " (<! (storage/bytes-in-use nil))))} "Usage"]
[:button {:on-click #(storage/clear)} "Clear"]
])))
......@@ -118,6 +131,7 @@
(go (let [c (<! (windows/get-current))]
(dispatch [:initialize (:tabs c)])))
(let [bg (runtime/connect)]
(dispatch-on-channel :log-content storage/on-changed)
(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)
......
......@@ -9,7 +9,7 @@
(defn init []
(console/log "tabler.handler.init")
(let [conns (browser/on-click)]
(let [conns (browser/on-clicked)]
(go (while true
(let [tab (<! conns)]
(console/log "On click handler. Tab: " tab)
......
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