Compare commits

..

1 Commits

Author SHA1 Message Date
Andrey Antukh
931afe912a 💄 Add minor cosmetic refactor on how plugin flags are stored
The main idea behind this, is move all plugin related stuff from
app.main.data.plugins into app.plugins.* and make them more consistent.
Also the intention that put all plugins related state under specific
prefix on the state.
2026-02-24 14:29:51 +01:00
9 changed files with 46 additions and 59 deletions

View File

@@ -100,14 +100,12 @@
(def browser-pool-factory
(letfn [(create []
(-> (p/let [opts #js {:args #js ["--allow-insecure-localhost" "--font-render-hinting=none"]}
browser (.launch pw/chromium opts)
id (swap! pool-browser-id inc)]
(l/info :origin "factory" :action "create" :browser-id id)
(unchecked-set browser "__id" id)
browser)
(p/catch (fn [cause]
(l/error :hint "Cannot launch the headless browser" :cause cause)))))
(p/let [opts #js {:args #js ["--allow-insecure-localhost" "--font-render-hinting=none"]}
browser (.launch pw/chromium opts)
id (swap! pool-browser-id inc)]
(l/info :origin "factory" :action "create" :browser-id id)
(unchecked-set browser "__id" id)
browser))
(destroy [obj]
(let [id (unchecked-get obj "__id")]

View File

@@ -47,13 +47,12 @@
(s/def ::params
(s/keys :req-un [::exports ::profile-id]
:opt-un [::wait ::name ::skip-children ::force-multiple]))
:opt-un [::wait ::name ::skip-children]))
(defn handler
[{:keys [:request/auth-token] :as exchange} {:keys [exports force-multiple] :as params}]
[{:keys [:request/auth-token] :as exchange} {:keys [exports] :as params}]
(let [exports (prepare-exports exports auth-token)]
(if (and (not force-multiple)
(= 1 (count exports))
(if (and (= 1 (count exports))
(= 1 (count (-> exports first :objects))))
(handle-single-export exchange (-> params
(assoc :export (first exports))

View File

@@ -195,7 +195,7 @@
params {:exports exports
:cmd cmd
:profile-id profile-id
:force-multiple true}
:wait false}
progress-stream
(->> (ws/get-rcv-stream ws-conn)

View File

@@ -14,6 +14,7 @@
[app.main.data.modal :as modal]
[app.main.data.notifications :as ntf]
[app.main.store :as st]
[app.plugins.flags :as pflag]
[app.plugins.register :as preg]
[app.util.globals :as ug]
[app.util.http :as http]
@@ -44,20 +45,6 @@
(update [_ state]
(update-in state [:workspace-local :open-plugins] (fnil conj #{}) id))))
(defn reset-plugin-flags
[id]
(ptk/reify ::reset-plugin-flags
ptk/UpdateEvent
(update [_ state]
(update-in state [:workspace-local :plugin-flags] assoc id {}))))
(defn set-plugin-flag
[id key value]
(ptk/reify ::set-plugin-flag
ptk/UpdateEvent
(update [_ state]
(update-in state [:workspace-local :plugin-flags id] assoc key value))))
(defn remove-current-plugin
[id]
(ptk/reify ::remove-current-plugin
@@ -68,8 +55,8 @@
(defn- load-plugin!
[{:keys [plugin-id name description host code icon permissions]}]
(try
(st/emit! (save-current-plugin plugin-id)
(reset-plugin-flags plugin-id))
(st/emit! (pflag/clear plugin-id)
(save-current-plugin plugin-id))
(.ɵloadPlugin
^js ug/global

View File

@@ -1173,7 +1173,8 @@
(when add-component-to-variant?
(rx/of (ev/event {::ev/name "add-component-to-variant"})))
(when add-new-variant?
(rx/of (ev/event {::ev/name "add-new-variant" ::ev/origin "workspace:move-shapes-to-frame"}))))))))
(rx/of (ev/event {::ev/name "add-new-variant"
::ev/origin "workspace:move-shapes-to-frame"}))))))))
(defn- get-displacement
"Retrieve the correct displacement delta point for the

View File

@@ -6,10 +6,30 @@
(ns app.plugins.flags
(:require
[app.main.data.plugins :as dp]
[app.common.data.macros :as dm]
[app.main.store :as st]
[app.plugins.utils :as u]
[app.util.object :as obj]))
[app.util.object :as obj]
[potok.v2.core :as ptk]))
(defn natural-child-ordering?
[plugin-id]
(boolean
(dm/get-in @st/state [:plugins :flags plugin-id :natural-child-ordering])))
(defn clear
[id]
(ptk/reify ::reset
ptk/UpdateEvent
(update [_ state]
(update-in state [:plugins :flags] assoc id {}))))
(defn- set-flag
[id key value]
(ptk/reify ::set-flag
ptk/UpdateEvent
(update [_ state]
(update-in state [:plugins :flags id] assoc key value))))
(defn flags-proxy
[plugin-id]
@@ -17,11 +37,7 @@
:naturalChildOrdering
{:this false
:get
(fn []
(boolean
(get-in
@st/state
[:workspace-local :plugin-flags plugin-id :natural-child-ordering])))
(fn [] (natural-child-ordering? plugin-id))
:set
(fn [value]
@@ -30,4 +46,4 @@
(u/display-not-valid :naturalChildOrdering value)
:else
(st/emit! (dp/set-plugin-flag plugin-id :natural-child-ordering value))))}))
(st/emit! (set-flag plugin-id :natural-child-ordering value))))}))

View File

@@ -12,6 +12,7 @@
[app.main.data.workspace.shape-layout :as dwsl]
[app.main.data.workspace.transforms :as dwt]
[app.main.store :as st]
[app.plugins.flags :refer [natural-child-ordering?]]
[app.plugins.register :as r]
[app.plugins.utils :as u]
[app.util.object :as obj]
@@ -259,11 +260,10 @@
(u/display-not-valid :appendChild child)
:else
(let [child-id (obj/get child "$id")]
(let [child-id (obj/get child "$id")]
(st/emit! (dwt/move-shapes-to-frame #{child-id} id nil nil)
(ptk/data-event :layout/update {:ids [id]})))))))
(defn layout-child-proxy? [p]
(obj/type-of? p "LayoutChildProxy"))

View File

@@ -47,13 +47,13 @@
[app.main.data.workspace.variants :as dwv]
[app.main.repo :as rp]
[app.main.store :as st]
[app.plugins.flags :refer [natural-child-ordering?]]
[app.plugins.flex :as flex]
[app.plugins.format :as format]
[app.plugins.grid :as grid]
[app.plugins.parser :as parser]
[app.plugins.register :as r]
[app.plugins.ruler-guides :as rg]
[app.plugins.state :refer [natural-child-ordering?]]
[app.plugins.text :as text]
[app.plugins.utils :as u]
[app.util.http :as http]
@@ -960,9 +960,11 @@
(u/display-not-valid :appendChild "Plugin doesn't have 'content:write' permission")
:else
(let [child-id (obj/get child "$id")
(let [child-id (obj/get child "$id")
is-reversed? (ctl/flex-layout? shape)
index (if (and (natural-child-ordering? plugin-id) is-reversed?) 0 (count (:shapes shape)))]
index (if (and (natural-child-ordering? plugin-id) is-reversed?)
0
(count (:shapes shape)))]
(st/emit! (dwsh/relocate-shapes #{child-id} id index))))))
:insertChild

View File

@@ -1,16 +0,0 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.plugins.state
(:require
[app.main.store :as st]))
(defn natural-child-ordering?
[plugin-id]
(boolean
(get-in
@st/state
[:workspace-local :plugin-flags plugin-id :natural-child-ordering])))