Browse Source

improve(plugin): clear theme effects before update plugin

charlie 4 years ago
parent
commit
0530a345a7
3 changed files with 24 additions and 774 deletions
  1. 4 3
      libs/src/LSPlugin.core.ts
  2. 0 758
      resources/js/lsplugin.core.js
  3. 20 13
      src/main/frontend/handler/plugin.cljs

+ 4 - 3
libs/src/LSPlugin.core.ts

@@ -621,6 +621,7 @@ class PluginLocal
       return
     }
 
+    this._ctx.emit('beforereload', this)
     await this.unload()
     await this.load()
     this._ctx.emit('reloaded', this)
@@ -788,7 +789,7 @@ class PluginLocal
  */
 class LSPluginCore
   extends EventEmitter<'beforeenable' | 'enabled' | 'beforedisable' | 'disabled' | 'registered' | 'error' | 'unregistered' |
-    'theme-changed' | 'theme-selected' | 'settings-changed' | 'unlink-plugin' | 'reloaded'>
+    'theme-changed' | 'theme-selected' | 'settings-changed' | 'unlink-plugin' | 'beforereload' | 'reloaded'>
   implements ILSPluginThemeManager {
 
   private _isRegistering = false
@@ -1103,13 +1104,13 @@ class LSPluginCore
     }
   }
 
-  async unregisterTheme (id: PluginLocalIdentity): Promise<void> {
+  async unregisterTheme (id: PluginLocalIdentity, effect: boolean = true): Promise<void> {
     debug('unregistered Theme #', id)
 
     if (!this._registeredThemes.has(id)) return
     this._registeredThemes.delete(id)
     this.emit('theme-changed', this.themes, { id })
-    if (this._currentTheme?.pid == id) {
+    if (effect && this._currentTheme?.pid == id) {
       this._currentTheme.dis?.()
       this._currentTheme = null
       // reset current theme

File diff suppressed because it is too large
+ 0 - 758
resources/js/lsplugin.core.js


+ 20 - 13
src/main/frontend/handler/plugin.cljs

@@ -126,7 +126,7 @@
                              (p/then
                                (.reload pl)
                                #(do
-                                  (if theme (select-a-plugin-theme id))
+                                  ;;(if theme (select-a-plugin-theme id))
                                   (notifications/show!
                                     (str (t :plugin/update) (t :plugins) ": " name " - " (.-version (.-options pl))) :success))))
 
@@ -214,8 +214,9 @@
   (swap! state/state assoc-in [:plugin/installed-ui-items (keyword pid)] []))
 
 (defn unregister-plugin-themes
-  [pid]
-  (js/LSPluginCore.unregisterTheme pid))
+  ([pid] (unregister-plugin-themes pid true))
+  ([pid effect]
+   (js/LSPluginCore.unregisterTheme (name pid) effect)))
 
 (defn select-a-plugin-theme
   [pid]
@@ -335,6 +336,13 @@
   (p/then
     (p/let [root (get-ls-dotdir-root)
             _ (.setupPluginCore js/LSPlugin (bean/->js {:localUserConfigRoot root :dotConfigRoot root}))
+
+            clear-commands! (fn [pid]
+                              ;; commands
+                              (unregister-plugin-slash-command pid)
+                              (unregister-plugin-simple-command pid)
+                              (unregister-plugin-ui-items pid))
+
             _ (doto js/LSPluginCore
                 (.on "registered"
                      (fn [^js pl]
@@ -349,25 +357,24 @@
                 (.on "unregistered" (fn [pid]
                                       (let [pid (keyword pid)]
                                         ;; effects
-                                        (unregister-plugin-themes (name pid))
+                                        (unregister-plugin-themes pid)
                                         ;; plugins
                                         (swap! state/state md/dissoc-in [:plugin/installed-plugins pid])
                                         ;; commands
-                                        (unregister-plugin-slash-command pid)
-                                        (unregister-plugin-simple-command pid)
-                                        (unregister-plugin-ui-items pid))))
+                                        (clear-commands!))))
 
                 (.on "unlink-plugin" (fn [pid]
                                        (let [pid (keyword pid)]
                                          (ipc/ipc "uninstallMarketPlugin" (name pid)))))
 
+                (.on "beforereload" (fn [^js pl]
+                                      (let [pid (.-id pl)]
+                                        (clear-commands! pid)
+                                        (unregister-plugin-themes pid false))))
+
                 (.on "disabled" (fn [pid]
-                                  ;; effects
-                                  (unregister-plugin-themes pid)
-                                  ;; commands
-                                  (unregister-plugin-slash-command pid)
-                                  (unregister-plugin-simple-command pid)
-                                  (unregister-plugin-ui-items pid)))
+                                  (clear-commands! pid)
+                                  (unregister-plugin-themes pid)))
 
                 (.on "theme-changed" (fn [^js themes]
                                        (swap! state/state assoc :plugin/installed-themes

Some files were not shown because too many files changed in this diff