improve(plugin): pin or unpin for plugin ui button from toolbar

This commit is contained in:
charlie
2022-06-15 13:01:54 +08:00
committed by Tienson Qin
parent f3bedb200e
commit 6029a2998f
6 changed files with 517 additions and 409 deletions

View File

@@ -14,6 +14,7 @@
[clojure.string :as string]
[lambdaisland.glogi :as log]
[frontend.components.svg :as svg]
[frontend.context.i18n :refer [t]]
[frontend.format :as format]))
(defonce lsp-enabled?
@@ -42,6 +43,23 @@
(defonce stats-url (str central-endpoint "stats.json"))
(declare select-a-plugin-theme)
(defn load-plugin-preferences
[]
(-> (invoke-exported-api "load_user_preferences")
(p/then #(bean/->clj %))
(p/then #(state/set-state! :plugin/preferences %))
(p/catch
#(js/console.error %))))
(defn save-plugin-preferences!
([input] (save-plugin-preferences! input true))
([input reload-state?]
(when-let [^js input (and (map? input) (bean/->js input))]
(p/then
(js/LSPluginCore.saveUserPreferences input)
#(when reload-state?
(load-plugin-preferences))))))
(defn gh-repo-url [repo]
(str "https://github.com/" repo))
@@ -159,7 +177,7 @@
(filter #(has-setting-schema? (:id %)) plugins)))
(defn setup-install-listener!
[t]
[]
(let [channel (name :lsp-installed)
listener (fn [^js _ ^js e]
(js/console.debug :lsp-installed e)
@@ -540,6 +558,15 @@
[^js pl req-id payload]
(call-plugin pl :#lsp#request#callback {:requestId req-id :payload payload}))
(defn op-pinned-toolbar-item!
[key op]
(let [pinned (state/sub [:plugin/preferences :pinnedToolbarItems])
pinned (into #{} pinned)]
(when-let [op-fn (case op
:add conj
:remove disj)]
(save-plugin-preferences! {:pinnedToolbarItems (op-fn pinned (name key))}))))
;; components
(rum/defc lsp-indicator < rum/reactive
[]