mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 17:41:38 +02:00
✨ Change local storage access
This commit is contained in:
parent
60c63e4558
commit
4d57f33371
1 changed files with 25 additions and 32 deletions
|
@ -10,7 +10,8 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.util.object :as obj]))
|
[app.util.object :as obj]
|
||||||
|
[app.util.storage :refer [storage]]))
|
||||||
|
|
||||||
;; Stores the installed plugins information
|
;; Stores the installed plugins information
|
||||||
(defonce ^:private registry (atom {}))
|
(defonce ^:private registry (atom {}))
|
||||||
|
@ -57,21 +58,13 @@
|
||||||
:icon icon
|
:icon icon
|
||||||
:permissions (into #{} (map str) permissions)}))
|
:permissions (into #{} (map str) permissions)}))
|
||||||
|
|
||||||
(defn format-plugin-data
|
;; FIXME: LEGACY version of the load from store
|
||||||
"Format into a JS object the plugin data. This will be used to be stored in the local storage."
|
;; can be removed before deploying plugins to production
|
||||||
[{:keys [plugin-id name description host code icon permissions]}]
|
;; Needs to be preserved for the beta users
|
||||||
#js {:plugin-id plugin-id
|
(defn legacy-load-from-store
|
||||||
:name name
|
[]
|
||||||
:description description
|
(let [parse-plugin-data
|
||||||
:host host
|
(fn [^js data]
|
||||||
:code code
|
|
||||||
:icon icon
|
|
||||||
:permissions (apply array permissions)})
|
|
||||||
|
|
||||||
(defn parse-plugin-data
|
|
||||||
"Parsers the JS plugin data into a CLJS data structure. This will be used primarily when the local storage
|
|
||||||
data is retrieved"
|
|
||||||
[^js data]
|
|
||||||
{:plugin-id (obj/get data "plugin-id")
|
{:plugin-id (obj/get data "plugin-id")
|
||||||
:name (obj/get data "name")
|
:name (obj/get data "name")
|
||||||
:description (obj/get data "description")
|
:description (obj/get data "description")
|
||||||
|
@ -80,9 +73,7 @@
|
||||||
:icon (obj/get data "icon")
|
:icon (obj/get data "icon")
|
||||||
:permissions (into #{} (obj/get data "permissions"))})
|
:permissions (into #{} (obj/get data "permissions"))})
|
||||||
|
|
||||||
(defn load-from-store
|
ls (.-localStorage js/window)
|
||||||
[]
|
|
||||||
(let [ls (.-localStorage js/window)
|
|
||||||
plugins-val (.getItem ls "plugins")]
|
plugins-val (.getItem ls "plugins")]
|
||||||
(when plugins-val
|
(when plugins-val
|
||||||
(let [stored (->> (.parse js/JSON plugins-val)
|
(let [stored (->> (.parse js/JSON plugins-val)
|
||||||
|
@ -93,12 +84,14 @@
|
||||||
|
|
||||||
(defn save-to-store
|
(defn save-to-store
|
||||||
[]
|
[]
|
||||||
(->> (:ids @registry)
|
(swap! storage assoc :plugins @registry))
|
||||||
(map #(dm/get-in @registry [:data %]))
|
|
||||||
(map format-plugin-data)
|
(defn load-from-store
|
||||||
(apply array)
|
[]
|
||||||
(.stringify js/JSON)
|
(if (:plugins @storage)
|
||||||
(.setItem (.-localStorage js/window) "plugins")))
|
(reset! registry (:plugins @storage))
|
||||||
|
(do (legacy-load-from-store)
|
||||||
|
(save-to-store))))
|
||||||
|
|
||||||
(defn init
|
(defn init
|
||||||
[]
|
[]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue