Răsfoiți Sursa

enhance(plugin): add support for invoking external plugin commands

charlie 3 zile în urmă
părinte
comite
55216f36f0

+ 5 - 0
src/electron/electron/url.cljs

@@ -77,6 +77,11 @@
                                                             (= append "true"))}
                                   win))
 
+      (= action "/invokeCommand")
+      (let [[action payload] (get-URL-decoded-params parsed-url ["action" "payload"])]
+        (send-to-focused-renderer "invokeCommand" {:action action
+                                                   :payload payload} win))
+
       :else
       (send-to-focused-renderer "notification" {:type "error"
                                                 :payload (str "Unimplemented x-callback-url action: `"

+ 4 - 0
src/main/electron/listener.cljs

@@ -88,6 +88,10 @@
                  (fn [args]
                    (state/pub-event! [:editor/quick-capture args])))
 
+  (safe-api-call "invokeCommand"
+                 (fn [args]
+                   (state/pub-event! [:editor/invoke-command args])))
+
   (safe-api-call "openNewWindowOfGraph"
                  ;; Handle open new window in renderer, until the destination graph doesn't rely on setting local storage
                  ;; No db cache persisting ensured. Should be handled by the caller

+ 13 - 1
src/main/frontend/handler/events.cljs

@@ -43,6 +43,7 @@
             [frontend.quick-capture :as quick-capture]
             [frontend.state :as state]
             [frontend.util :as util]
+            [logseq.api.plugin :as plugin-api]
             [goog.dom :as gdom]
             [lambdaisland.glogi :as log]
             [logseq.db.frontend.schema :as db-schema]
@@ -236,9 +237,20 @@
   (when (and command (not (string/blank? content)))
     (shell-handler/run-cli-command-wrapper! command content)))
 
-(defmethod handle :editor/quick-capture [[_ args]]
+(defmethod handle :editor/quick-capture [[_ ^js args]]
   (quick-capture/quick-capture args))
 
+(defmethod handle :editor/invoke-command [[_ ^js args]]
+  (when-let [{:keys [action payload]} (bean/->clj args)]
+    ;; parse "plugin.vibe-clipper.models.onReceiveClipperData"
+    (let [keys' (string/split action #"\.")
+          [type id group] keys'
+          action (last keys')]
+      (case (keyword type)
+        :plugin (plugin-api/invoke_external_plugin_cmd id group action [payload])
+        (log/warn :unknown-invoke-command-type action))
+      )))
+
 (defmethod handle :modal/keymap [[_]]
   (state/open-settings! :keymap))