Sfoglia il codice sorgente

enhance(plugins): simplify state for the installed web plugins

charlie 1 anno fa
parent
commit
d3b68f1ff7

+ 7 - 10
libs/src/LSPlugin.core.ts

@@ -1101,10 +1101,10 @@ class PluginLocal extends EventEmitter<
     json.iir = this.isInstalledInDotRoot
     json.lsr = this._resolveResourceFullUrl('/')
 
-    if (settings) {
-      json.settings = json.settings?.toJSON()
-    } else {
+    if (settings === false) {
       delete json.settings
+    } else {
+      json.settings = json.settings?.toJSON()
     }
 
     return json
@@ -1205,10 +1205,10 @@ class LSPluginCore
 
     // If there is currently a theme that has been set
     if (currentTheme) {
-      await this.selectTheme(currentTheme, { effect: false })
+      await this.selectTheme(currentTheme, { effect: false, emit: false })
     } else if (legacyTheme) {
       // Otherwise compatible with older versions
-      await this.selectTheme(legacyTheme, { effect: false })
+      await this.selectTheme(legacyTheme, { effect: false, emit: false })
     }
   }
 
@@ -1571,10 +1571,7 @@ class LSPluginCore
     } = {}
   ) {
     const { effect, emit } = Object.assign(
-      {},
-      { effect: true, emit: true },
-      options
-    )
+      { effect: true, emit: true }, options)
 
     // Clear current theme before injecting.
     if (this._currentTheme) {
@@ -1609,7 +1606,7 @@ class LSPluginCore
     }
 
     if (emit) {
-      this.emit('theme-selected', theme)
+      this.emit('theme-selected', theme, options)
     }
   }
 

+ 63 - 62
src/main/frontend/components/plugins.cljs

@@ -302,69 +302,70 @@
     url item (if repo remote-readme-display local-markdown-display)))
 
 (rum/defc plugin-item-card < rum/static
-  [t {:keys [id name title version url description author icon iir repo sponsors] :as item}
-   disabled? market? *search-key has-other-pending?
-   installing-or-updating? installed? stat coming-update]
-
-  (let [name        (or title name "Untitled")
-        unpacked?   (not iir)
-        new-version (state/coming-update-new-version? coming-update)]
-    [:div.cp__plugins-item-card
-     {:key   (str "lsp-card-" id)
-      :class (util/classnames
-              [{:market          market?
-                :installed       installed?
-                :updating        installing-or-updating?
-                :has-new-version new-version}])}
-
-     [:div.l.link-block.cursor-pointer
+ [t {:keys [id name title version url description author icon iir repo sponsors webPkg] :as item}
+  disabled? market? *search-key has-other-pending?
+  installing-or-updating? installed? stat coming-update]
+
+ (let [name (or title name "Untitled")
+       web? (not (nil? webPkg))
+       unpacked? (and (not web?) (not iir))
+       new-version (state/coming-update-new-version? coming-update)]
+  [:div.cp__plugins-item-card
+   {:key   (str "lsp-card-" id)
+    :class (util/classnames
+            [{:market          market?
+              :installed       installed?
+              :updating        installing-or-updating?
+              :has-new-version new-version}])}
+
+   [:div.l.link-block.cursor-pointer
+    {:on-click (get-open-plugin-readme-handler url item repo)}
+    (if (and icon (not (string/blank? icon)))
+     [:img.icon {:src (if market? (plugin-handler/pkg-asset id icon) icon)}]
+     svg/folder)
+
+    (when (and (not market?) unpacked?)
+     [:span.flex.justify-center.text-xs.text-error.pt-2 (t :plugin/unpacked)])]
+
+   [:div.r
+    [:h3.head.text-xl.font-bold.pt-1.5
+
+     [:span.l.link-block.cursor-pointer
       {:on-click (get-open-plugin-readme-handler url item repo)}
-      (if (and icon (not (string/blank? icon)))
-        [:img.icon {:src (if market? (plugin-handler/pkg-asset id icon) icon)}]
-        svg/folder)
-
-      (when (and (not market?) unpacked?)
-        [:span.flex.justify-center.text-xs.text-error.pt-2 (t :plugin/unpacked)])]
-
-     [:div.r
-      [:h3.head.text-xl.font-bold.pt-1.5
-
-       [:span.l.link-block.cursor-pointer
-        {:on-click (get-open-plugin-readme-handler url item repo)}
-        name]
-       (when (not market?) [:sup.inline-block.px-1.text-xs.opacity-50 version])]
-
-      [:div.desc.text-xs.opacity-70
-       [:p description]
-       ;;[:small (js/JSON.stringify (bean/->js settings))]
-       ]
-
-      ;; Author & Identity
-      [:div.flag
-       [:p.text-xs.pr-2.flex.justify-between
-        [:small {:on-click #(when-let [^js el (js/document.querySelector ".cp__plugins-page .search-ctls input")]
-                              (reset! *search-key (str "@" author))
-                              (.select el))} author]
-        [:small {:on-click #(do
-                              (notification/show! "Copied!" :success)
-                              (util/copy-to-clipboard! id))}
-         (str "ID: " id)]]]
-
-      ;; Github repo
-      [:div.flag.is-top.opacity-50
-       (when repo
-         [:a.flex {:target "_blank"
-                   :href   (plugin-handler/gh-repo-url repo)}
-          (svg/github {:width 16 :height 16})])]
-
-      (if market?
-        ;; market ctls
-        (card-ctls-of-market item stat installed? installing-or-updating?)
-
-        ;; installed ctls
-        (card-ctls-of-installed
-         id name url sponsors unpacked? disabled?
-         installing-or-updating? has-other-pending? new-version item))]]))
+      name]
+     (when (not market?) [:sup.inline-block.px-1.text-xs.opacity-50 version])]
+
+    [:div.desc.text-xs.opacity-70
+     [:p description]
+     ;;[:small (js/JSON.stringify (bean/->js settings))]
+     ]
+
+    ;; Author & Identity
+    [:div.flag
+     [:p.text-xs.pr-2.flex.justify-between
+      [:small {:on-click #(when-let [^js el (js/document.querySelector ".cp__plugins-page .search-ctls input")]
+                           (reset! *search-key (str "@" author))
+                           (.select el))} author]
+      [:small {:on-click #(do
+                           (notification/show! "Copied!" :success)
+                           (util/copy-to-clipboard! id))}
+       (str "ID: " id)]]]
+
+    ;; Github repo
+    [:div.flag.is-top.opacity-50
+     (when repo
+      [:a.flex {:target "_blank"
+                :href   (plugin-handler/gh-repo-url repo)}
+       (svg/github {:width 16 :height 16})])]
+
+    (if market?
+     ;; market ctls
+     (card-ctls-of-market item stat installed? installing-or-updating?)
+
+     ;; installed ctls
+     (card-ctls-of-installed
+      id name url sponsors unpacked? disabled?
+      installing-or-updating? has-other-pending? new-version item))]]))
 
 (rum/defc panel-tab-search < rum/static
   [search-key *search-key *search-ref]

+ 2 - 1
src/main/frontend/handler/plugin.cljs

@@ -830,8 +830,9 @@
                                           (swap! state/state assoc :plugin/installed-themes
                                                  (vec (mapcat (fn [[pid vs]] (mapv #(assoc % :pid pid) (bean/->clj vs))) (bean/->clj themes))))))
 
-                  (.on "theme-selected" (fn [^js theme]
+                  (.on "theme-selected" (fn [^js theme ^js opts]
                                           (let [theme (bean/->clj theme)
+                                                _opts (bean/->clj opts)
                                                 url (:url theme)
                                                 mode (:mode theme)]
                                             (when mode