瀏覽代碼

improve(plugin): add theme changed hook

charlie 3 年之前
父節點
當前提交
f3bedb200e

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

@@ -1126,7 +1126,7 @@ class LSPluginCore
     | 'registered'
     | 'error'
     | 'unregistered'
-    | 'theme-changed'
+    | 'themes-changed'
     | 'theme-selected'
     | 'reset-custom-theme'
     | 'settings-changed'
@@ -1510,7 +1510,7 @@ class LSPluginCore
     }
 
     themes.push(opt)
-    this.emit('theme-changed', this.themes, { id, ...opt })
+    this.emit('themes-changed', this.themes, { id, ...opt })
   }
 
   async selectTheme(
@@ -1571,7 +1571,7 @@ class LSPluginCore
     }
 
     this._registeredThemes.delete(id)
-    this.emit('theme-changed', this.themes, { id })
+    this.emit('themes-changed', this.themes, { id })
     if (effect && this._currentTheme?.pid === id) {
       this._currentTheme.eject()
       this._currentTheme = null

+ 1 - 0
libs/src/LSPlugin.ts

@@ -410,6 +410,7 @@ export interface IAppProxy {
   // hook events
   onCurrentGraphChanged: IUserHook
   onThemeModeChanged: IUserHook<{ mode: 'dark' | 'light' }>
+  onThemeChanged: IUserHook<Partial<{name: string, mode: string, pid: string, url: string}>>
   onBlockRendererSlotted: IUserSlotHook<{ uuid: BlockUUID }>
 
   /**

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


+ 1 - 1
resources/js/lsplugin.core.js.LICENSE.txt

@@ -1 +1 @@
-/*! @license DOMPurify 2.3.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.1/LICENSE */
+/*! @license DOMPurify 2.3.8 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.8/LICENSE */

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

@@ -605,7 +605,7 @@
                                   (clear-commands! pid)
                                   (unregister-plugin-themes pid)))
 
-                (.on "theme-changed" (fn [^js themes]
+                (.on "themes-changed" (fn [^js themes]
                                        (swap! state/state assoc :plugin/installed-themes
                                               (vec (mapcat (fn [[pid vs]] (mapv #(assoc % :pid pid) (bean/->clj vs))) (bean/->clj themes))))))
 
@@ -616,6 +616,7 @@
                                           (when mode
                                             (state/set-custom-theme! mode theme)
                                             (state/set-theme-mode! mode))
+                                          (hook-plugin-app :theme-changed theme)
                                           (state/set-state! :plugin/selected-theme url))))
 
                 (.on "reset-custom-theme" (fn [^js themes]

+ 1 - 1
src/main/frontend/ui.cljs

@@ -296,7 +296,7 @@
     (when-let [custom-theme (state/sub [:ui/custom-theme (keyword theme)])]
       (when-let [url (:url custom-theme)]
         (js/LSPluginCore.selectTheme (bean/->js custom-theme)
-                                     (bean/->js {:emit false}))
+                                     (bean/->js {:emit true}))
         (state/set-state! :plugin/selected-theme url)))))
 
 (defn setup-system-theme-effect!

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