Browse Source

enhance(plugin): add load events

charlie 11 months ago
parent
commit
23166186b0
2 changed files with 11 additions and 3 deletions
  1. 6 0
      libs/src/LSPlugin.core.ts
  2. 5 3
      src/main/frontend/handler/plugin.cljs

+ 6 - 0
libs/src/LSPlugin.core.ts

@@ -864,6 +864,8 @@ class PluginLocal extends EventEmitter<
         return
       }
 
+      this._ctx.emit('beforeload', this)
+
       await this._tryToNormalizeEntry()
 
       this._caller = new LSPluginCaller(this)
@@ -884,6 +886,8 @@ class PluginLocal extends EventEmitter<
       })
 
       this._dispose(cleanInjectedScripts.bind(this))
+
+      this._ctx.emit('loadeded', this)
     } catch (e) {
       this.logger.error('load', e, true)
 
@@ -1129,6 +1133,8 @@ class LSPluginCore
     | 'reset-custom-theme'
     | 'settings-changed'
     | 'unlink-plugin'
+    | 'beforeload'
+    | 'loadeded'
     | 'beforereload'
     | 'reloaded'
   >

+ 5 - 3
src/main/frontend/handler/plugin.cljs

@@ -767,7 +767,7 @@
   (let [text (state/sub :plugin/indicator-text)]
     (when-not (= text "END")
       [:div.flex.align-items.justify-center.h-screen.w-full.preboot-loading
-       [:span.flex.items-center.justify-center.w-60.flex-col
+       [:span.flex.items-center.justify-center.flex-col
         [:small.scale-250.opacity-70.mb-10.animate-pulse (svg/logo)]
         [:small.block.text-sm.relative.opacity-50 {:style {:right "-8px"}} text]]])))
 
@@ -779,8 +779,6 @@
     (rum/mount
       (lsp-indicator) el))
 
-  (state/set-state! :plugin/indicator-text "LOADING")
-
   (-> (p/let [root (init-ls-dotdir-root)
               _ (.setupPluginCore js/LSPlugin (bean/->js {:localUserConfigRoot root :dotConfigRoot root}))
 
@@ -799,6 +797,10 @@
                          (register-plugin
                            (bean/->clj (.parse js/JSON (.stringify js/JSON pl))))))
 
+                  (.on "beforeload"
+                       (fn [^js pl]
+                         (state/set-state! :plugin/indicator-text (util/format "Load plugin: %s..." (.-id pl)))))
+
                   (.on "reloaded"
                        (fn [^js pl]
                          (register-plugin