0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Merge pull request #4788 from penpot/alotor-plugins-2

Fix problem with plugins initialization
This commit is contained in:
Andrey Antukh 2024-06-21 14:58:42 +02:00 committed by GitHub
commit b9e40b4d82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 16 deletions

View file

@ -105,8 +105,7 @@
(rx/map deref)
(rx/filter du/is-authenticated?)
(rx/take 1)
(rx/map #(ws/initialize))
(rx/tap #(plugins/init!)))))))
(rx/map #(ws/initialize)))))))
(defn ^:export init
[]
@ -116,7 +115,8 @@
(cur/init-styles)
(thr/init!)
(init-ui)
(st/emit! (initialize)))
(st/emit! (plugins/initialize)
(initialize)))
(defn ^:export reinit
([]

View file

@ -131,7 +131,7 @@
(rx/merge-map svg->clj)
(rx/tap on-svg)))))
(defn- process-blobs
(defn process-blobs
[{:keys [file-id local? name blobs force-media on-image on-svg]}]
(letfn [(svg-blob? [blob]
(and (not force-media)

View file

@ -16,15 +16,20 @@
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]))
(defn init!
(defn init-plugins-runtime!
[]
(->> st/stream
(rx/filter (ptk/type? ::features/initialize))
(rx/take 1)
;; We need to wait to the init event to finish
(rx/observe-on :async)
(rx/subs!
(fn []
(when (features/active-feature? @st/state "plugins/runtime")
(when-let [init-runtime (obj/get global "initPluginsRuntime")]
(init-runtime (fn [plugin-id] (api/create-context plugin-id)))))))))
(when-let [init-runtime (obj/get global "initPluginsRuntime")]
(init-runtime (fn [plugin-id] (api/create-context plugin-id)))))
(defn initialize
[]
(ptk/reify ::initialize
ptk/WatchEvent
(watch [_ _ stream]
(->> stream
(rx/filter (ptk/type? ::features/initialize))
(rx/observe-on :async)
(rx/filter #(features/active-feature? @st/state "plugins/runtime"))
(rx/take 1)
(rx/tap init-plugins-runtime!)
(rx/ignore)))))

View file

@ -124,6 +124,22 @@
(rx/take 1)
(rx/subs! resolve reject)))))))
(uploadMediaData
[_ name data mime-type]
(let [file-id (:current-file-id @st/state)]
(p/create
(fn [resolve reject]
(->> (dwm/process-blobs
{:file-id file-id
:local? false
:name name
:blobs [(js/Blob. #js [data] #js {:type mime-type})]
:on-image identity
:on-svg identity})
(rx/take 1)
(rx/map u/to-js)
(rx/subs! resolve reject))))))
(group
[_ shapes]
(cond

View file

@ -27,6 +27,6 @@
(defn ^:export plugins []
(st/emit! (features/enable-feature "plugins/runtime"))
(plugins/init!)
(plugins/init-plugins-runtime!)
nil)