Browse Source

enhance(plugin): unlink plugins for web

charlie 1 year ago
parent
commit
ca03681754

+ 2 - 2
libs/src/LSPlugin.core.ts

@@ -927,7 +927,7 @@ class PluginLocal extends EventEmitter<
     if (unregister) {
     if (unregister) {
       await this.unload()
       await this.unload()
 
 
-      if (this.isInstalledInDotRoot) {
+      if (this.isWebPlugin || this.isInstalledInDotRoot) {
         this._ctx.emit('unlink-plugin', this.id)
         this._ctx.emit('unlink-plugin', this.id)
       }
       }
 
 
@@ -1393,7 +1393,7 @@ class LSPluginCore
     for (const identity of plugins) {
     for (const identity of plugins) {
       const p = this.ensurePlugin(identity)
       const p = this.ensurePlugin(identity)
 
 
-      if (!p.isInstalledInDotRoot) {
+      if (!p.isWebPlugin && !p.isInstalledInDotRoot) {
         unregisteredExternals.push(p.options.url)
         unregisteredExternals.push(p.options.url)
       }
       }
 
 

+ 11 - 9
src/main/frontend/components/plugins.cljs

@@ -255,18 +255,20 @@
             #(-> (shui/dialog-confirm!
             #(-> (shui/dialog-confirm!
                   [:b (t :plugin/delete-alert name)])
                   [:b (t :plugin/delete-alert name)])
                  (p/then (fn []
                  (p/then (fn []
-                           (plugin-common-handler/unregister-plugin id)
-                           (plugin-config-handler/remove-plugin id))))}
+                          (plugin-common-handler/unregister-plugin id)
+
+                          (when (util/electron?)
+                           (plugin-config-handler/remove-plugin id)))))}
        (t :plugin/uninstall)]]]
        (t :plugin/uninstall)]]]
 
 
     (when (seq sponsors)
     (when (seq sponsors)
-      [:div.de.sponsors
-       [:strong (ui/icon "coffee")]
-       [:ul.menu-list
-        (for [link sponsors]
-          [:li {:key link}
-           [:a {:href link :target "_blank"}
-            [:span.flex.items-center link (ui/icon "external-link")]]])]])]
+     [:div.de.sponsors
+      [:strong (ui/icon "coffee")]
+      [:ul.menu-list
+       (for [link sponsors]
+        [:li {:key link}
+         [:a {:href link :target "_blank"}
+          [:span.flex.items-center link (ui/icon "external-link")]]])]])]
 
 
    [:div.r.flex.items-center
    [:div.r.flex.items-center
     (when (and unpacked? (not disabled?))
     (when (and unpacked? (not disabled?))

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

@@ -62,6 +62,11 @@
     (let [^js e (js/window.EventEmitter3.)]
     (let [^js e (js/window.EventEmitter3.)]
       (set! (. js/window -apis) e))))
       (set! (. js/window -apis) e))))
 
 
+(defn unlink-plugin-for-web!
+  [key]
+  (invoke-exported-api :unlink_installed_web_plugin key)
+  (invoke-exported-api :unlink_plugin_user_settings key))
+
 (defn load-plugin-preferences
 (defn load-plugin-preferences
   []
   []
   (-> (invoke-exported-api :load_user_preferences)
   (-> (invoke-exported-api :load_user_preferences)
@@ -817,7 +822,9 @@
 
 
                   (.on "unlink-plugin" (fn [pid]
                   (.on "unlink-plugin" (fn [pid]
                                          (let [pid (keyword pid)]
                                          (let [pid (keyword pid)]
-                                           (ipc/ipc "uninstallMarketPlugin" (name pid)))))
+                                           (if (util/electron?)
+                                             (ipc/ipc :uninstallMarketPlugin (name pid))
+                                             (unlink-plugin-for-web! pid)))))
 
 
                   (.on "beforereload" (fn [^js pl]
                   (.on "beforereload" (fn [^js pl]
                                         (let [pid (.-id pl)]
                                         (let [pid (.-id pl)]

+ 15 - 7
src/main/logseq/api.cljs

@@ -393,13 +393,21 @@
         (some-> (getter :all) (p/then second))))
         (some-> (getter :all) (p/then second))))
 
 
 (defn ^:export save_installed_web_plugin
 (defn ^:export save_installed_web_plugin
- [^js plugin]
- (when-let [id (some-> plugin (.-key))]
-  (let [setter (plugin-handler/make-fn-to-save-dotdir-json "installed-plugins-for-web")
-        plugin (js/JSON.parse (js/JSON.stringify plugin))]
-   (p/let [^js plugins (or (load_installed_web_plugins) #js {})]
-          (gobj/set plugins id plugin)
-          (setter :all plugins)))))
+ ([^js plugin] (save_installed_web_plugin plugin false))
+ ([^js plugin remove?]
+  (when-let [id (some-> plugin (.-key) (name))]
+   (let [setter (plugin-handler/make-fn-to-save-dotdir-json "installed-plugins-for-web")
+         plugin (js/JSON.parse (js/JSON.stringify plugin))]
+    (p/let [^js plugins (or (load_installed_web_plugins) #js {})]
+           (if (true? remove?)
+            (when (aget plugins id)
+             (js-delete plugins id))
+            (gobj/set plugins id plugin))
+           (setter :all plugins))))))
+
+(defn ^:export unlink_installed_web_plugin
+ [key]
+ (save_installed_web_plugin #js {:key key} true))
 
 
 (def ^:export unlink_plugin_user_settings
 (def ^:export unlink_plugin_user_settings
   (plugin-handler/make-fn-to-unlink-dotdir-json "settings"))
   (plugin-handler/make-fn-to-unlink-dotdir-json "settings"))