From 53d3b2abbc6a6df69558c1b29e8d28464babb1d6 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 4 Jul 2024 15:05:28 +0200 Subject: [PATCH] :sparkles: Add events for plugins --- .../app/main/data/workspace/shortcuts.cljs | 7 ++++-- .../src/app/main/ui/workspace/main_menu.cljs | 20 ++++++++++++---- .../src/app/main/ui/workspace/plugins.cljs | 24 +++++++++++++++++-- .../app/main/ui/workspace/top_toolbar.cljs | 5 +++- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index bd0071602..87346de67 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -27,7 +27,8 @@ [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.hooks.resize :as r] - [app.util.dom :as dom])) + [app.util.dom :as dom] + [potok.v2.core :as ptk])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Shortcuts @@ -563,7 +564,9 @@ :command (ds/c-mod "alt+p") :subsections [:basics] :fn #(when (features/active-feature? @st/state "plugins/runtime") - (st/emit! (modal/show :plugin-management {})))}}) + (st/emit! + (ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:shortcuts"}) + (modal/show :plugin-management {})))}}) (def debug-shortcuts ;; PREVIEW diff --git a/frontend/src/app/main/ui/workspace/main_menu.cljs b/frontend/src/app/main/ui/workspace/main_menu.cljs index 135cdc1b5..ea0fc54f4 100644 --- a/frontend/src/app/main/ui/workspace/main_menu.cljs +++ b/frontend/src/app/main/ui/workspace/main_menu.cljs @@ -630,13 +630,23 @@ (when (d/not-empty? plugins) [:div {:class (stl/css :separator)}]) - (for [[idx {:keys [name] :as manifest}] (d/enumerate plugins)] + (for [[idx {:keys [name host] :as manifest}] (d/enumerate plugins)] [:> dropdown-menu-item* {:key (dm/str "plugins-menu-" idx) - :on-click #(uwp/open-plugin! manifest) + :on-click #(do + (st/emit! (ptk/event ::ev/event {::ev/name "start-plugin" + ::ev/origin "workspace:menu" + :name name + :host host})) + (uwp/open-plugin! manifest)) :class (stl/css :submenu-item) :on-key-down (fn [event] (when (kbd/enter? event) - #(uwp/open-plugin! manifest)))} + #(do + (st/emit! (ptk/event ::ev/event {::ev/name "start-plugin" + ::ev/origin "workspace:menu" + :name name + :host host})) + (uwp/open-plugin! manifest))))} [:span {:class (stl/css :item-name)} name]])]))) (mf/defc menu @@ -699,7 +709,9 @@ (dom/stop-propagation event) (reset! show-menu* false) (reset! sub-menu* nil) - (st/emit! (modal/show :plugin-management {}))))] + (st/emit! + (ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:menu"}) + (modal/show :plugin-management {}))))] [:* diff --git a/frontend/src/app/main/ui/workspace/plugins.cljs b/frontend/src/app/main/ui/workspace/plugins.cljs index 53c41282a..7a71cf4a0 100644 --- a/frontend/src/app/main/ui/workspace/plugins.cljs +++ b/frontend/src/app/main/ui/workspace/plugins.cljs @@ -10,6 +10,7 @@ [app.common.data :as d] [app.common.data.macros :as dm] [app.config :as cf] + [app.main.data.events :as ev] [app.main.data.modal :as modal] [app.main.store :as st] [app.main.ui.components.search-bar :refer [search-bar]] @@ -21,6 +22,8 @@ [app.util.http :as http] [app.util.i18n :as i18n :refer [tr]] [beicon.v2.core :as rx] + [cuerdas.core :as str] + [potok.v2.core :as ptk] [rumext.v2 :as mf])) (def ^:private close-icon @@ -111,6 +114,7 @@ (rx/subs! (fn [body] (let [plugin (plugins/parser-manifest plugin-url body)] + (st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url})) (modal/show! :plugin-permissions {:plugin plugin @@ -126,6 +130,10 @@ handle-open-plugin (mf/use-callback (fn [manifest] + (st/emit! (ptk/event ::ev/event {::ev/name "start-plugin" + ::ev/origin "workspace:plugins" + :name (:name manifest) + :host (:host manifest)})) (open-plugin! manifest) (modal/hide!))) @@ -134,6 +142,9 @@ (mf/deps plugins-state) (fn [plugin-index] (let [plugin (nth @plugins/pluginsdb plugin-index)] + (st/emit! (ptk/event ::ev/event {::ev/name "remove-plugin" + :name (:name plugin) + :host (:host plugin)})) (plugins/remove-plugin! plugin) (reset! plugins-state* @plugins/pluginsdb))))] @@ -162,7 +173,10 @@ [:div {:class (stl/css :plugins-empty)} [:div {:class (stl/css :plugins-empty-logo)} i/puzzle] [:div {:class (stl/css :plugins-empty-text)} (tr "workspace.plugins.empty-plugins")] - [:a {:class (stl/css :plugins-link) :href cf/plugins-list-uri :target "_blank"} + [:a {:class (stl/css :plugins-link) + :href cf/plugins-list-uri + :target "_blank" + :on-click #(st/emit! (ptk/event ::ev/event {::ev/name "open-plugins-list"}))} (tr "workspace.plugins.plugin-list-link") i/external-link]] [:* @@ -182,7 +196,7 @@ ::mf/register-as :plugin-permissions} [{:keys [plugin on-accept]}] - (let [{:keys [permissions]} plugin + (let [{:keys [host permissions]} plugin permissions (set permissions) handle-accept-dialog @@ -190,12 +204,18 @@ (fn [event] (dom/prevent-default event) (st/emit! (modal/hide)) + (ptk/event ::ev/event {::ev/name "allow-plugin-permissions" + :host host + :permissions (->> permissions (str/join ", "))}) (on-accept))) handle-close-dialog (mf/use-callback (fn [event] (dom/prevent-default event) + (ptk/event ::ev/event {::ev/name "reject-plugin-permissions" + :host host + :permissions (->> permissions (str/join ", "))}) (st/emit! (modal/hide))))] [:div {:class (stl/css :modal-overlay)} diff --git a/frontend/src/app/main/ui/workspace/top_toolbar.cljs b/frontend/src/app/main/ui/workspace/top_toolbar.cljs index dfbb3fe1a..82e344445 100644 --- a/frontend/src/app/main/ui/workspace/top_toolbar.cljs +++ b/frontend/src/app/main/ui/workspace/top_toolbar.cljs @@ -27,6 +27,7 @@ [app.util.i18n :as i18n :refer [tr]] [app.util.timers :as ts] [okulary.core :as l] + [potok.v2.core :as ptk] [rumext.v2 :as mf])) (mf/defc image-upload @@ -200,7 +201,9 @@ {:title (tr "workspace.toolbar.plugins" (sc/get-tooltip :plugins)) :aria-label (tr "workspace.toolbar.plugins" (sc/get-tooltip :plugins)) :class (stl/css :main-toolbar-options-button) - :on-click #(modal/show! :plugin-management {}) + :on-click #(st/emit! + (ptk/event ::ev/event {::ev/name "open-plugins-manager" ::ev/origin "workspace:toolbar"}) + (modal/show :plugin-management {})) :data-tool "plugins" :data-testid "plugins-btn"} i/puzzle]])