Enhance/plugin APIs (#7555)

* feat: WIP native cli command support

* Add :shell/command-whitelist option

* Integrate cli to code block

* Add :code-block/command-whitelist option

* fix: size of icon

* improve(shell): cache user shell whitelist on application configures file

* improve(electron): promisify run cli command

* chore(libs): update version

* fix(plugin): incorrect payload of pdf highlights section hook

* improve(plugin): block renderer with specific block uuid

* improve(plugin): expose logger for user lib

* improve(plugin): block hooks type

* improve(plugin): block slot hook with specific block

* improve(plugin): auto generate key for provide UI options

* improve(plugin): style of injected ui container

* improve(plugin): types

* improve(plugin): async messaging api from host to plugin

* improve(plugin): add types

* improve(apis): get external plugin metadata

* improve(apis): invoke external plugin impls

* improve(apis): call external plugin impls for simple commands

* enhance(apis): datascript query api for predicate inputs

* enhance(apis): datascript query api for predicate inputs

* fix(apis): redundant args of datascript query api

* enhance(plugins): position of float ui container

* enhance(plugins): style of setting options

* enhance(plugins): layouts data for float ui

* chore(plugins): update CHANGELOG.md

* improve(apis): add types

* chore: fix some inclusive terms

* improve(apis): types

* chore(plugins): update CHANGELOG.md

* chore(plugins): build libs

* chore: update CHANGELOG.md

* chore: remove experiemental alda integration

* fix(lint): remove unused methods

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
Co-authored-by: Andelf <andelf@gmail.com>
This commit is contained in:
Charlie
2022-12-19 20:23:25 +08:00
committed by GitHub
parent dfe1d65f31
commit 020317911f
28 changed files with 781 additions and 417 deletions

View File

@@ -7,7 +7,8 @@
[promesa.core :as p]
[frontend.db :as db]
[frontend.state :as state]
[frontend.config :as config]))
[frontend.config :as config]
[frontend.util :as util]))
(defn run-git-command!
[command]
@@ -17,14 +18,15 @@
[command]
(ipc/ipc "runGitWithinCurrentGraph" command))
;; TODO: export to pdf/html/word
(defn run-pandoc-command!
[command]
(ipc/ipc "runPandoc" command))
(defn run-cli-command!
[command args]
(ipc/ipc :runCli {:command command
:args args
:returnResult true}))
(defn wrap-notification!
[command f args]
(p/let [result (f args)]
(p/let [result (f command args)]
(notification/show!
(if (string/blank? result)
[:p [:code.mr-1 (str command " " args) ]
@@ -33,22 +35,29 @@
:success
false)))
(def commands-denylist
#{"rm" "mv" "rename" "dd" ">" "command" "sudo"})
(defn run-command!
[command]
(let [[command args] (gp-util/split-first " " command)
command (and command (string/lower-case command))]
(when (and (not (string/blank? command)) (not (string/blank? args)))
(let [args (string/trim args)]
(case (keyword command)
:git
(wrap-notification! command run-git-command! args)
(let [[command args]
(if (and (string? command) (string/includes? command " "))
(gp-util/split-first " " command)
[command ""])
command (and command (string/lower-case command))
args (-> args str string/trim)]
(when-not (string/blank? command)
(cond
(contains? commands-denylist command)
(notification/show!
[:div (str command " is too dangerous!")]
:error)
;; :pandoc
;; (wrap-notification! command run-pandoc-command! args)
(= "git" command)
(wrap-notification! command (fn [_ args] (run-git-command! args)) args)
(notification/show!
[:div (str command " is not supported yet!")]
:error))))))
:else
(run-cli-command! command args)))))
;; git show $REV:$FILE
(defn- get-versioned-file-content
@@ -90,3 +99,11 @@
(notification/show!
[:div "git config successfully!"]
:success)))
(defn run-cli-command-wrapper!
[command content]
(let [args (case command
"alda" (util/format "play -c \"%s\"" content)
;; TODO: plugin slot
content)]
(run-cli-command! command args)))