@@ -18,7 +18,7 @@ import {
1818 asyncPool ,
1919} from '@/utils'
2020
21- import type { Plugin , Subscription } from '@/types/app'
21+ import type { Plugin , Subscription , TrayContent , MenuItem } from '@/types/app'
2222
2323const PluginsCache : Recordable < { plugin : Plugin ; code : string } > = { }
2424
@@ -32,6 +32,10 @@ const PluginsTriggerMap: {
3232 fnName : PluginTriggerEvent . OnManual ,
3333 observers : [ ] ,
3434 } ,
35+ [ PluginTrigger . OnTrayUpdate ] : {
36+ fnName : PluginTriggerEvent . OnTrayUpdate ,
37+ observers : [ ] ,
38+ } ,
3539 [ PluginTrigger . OnSubscribe ] : {
3640 fnName : PluginTriggerEvent . OnSubscribe ,
3741 observers : [ ] ,
@@ -125,7 +129,7 @@ export const usePluginsStore = defineStore('plugins', () => {
125129 configuration [ key ] = value
126130 }
127131 Object . assign ( configuration , appSettingsStore . app . pluginSettings [ plugin . id ] ?? { } )
128- return { ...plugin , ...configuration }
132+ return deepClone ( { ...plugin , ...configuration } )
129133 }
130134
131135 const isPluginUnavailable = (
@@ -465,6 +469,35 @@ export const usePluginsStore = defineStore('plugins', () => {
465469 }
466470 }
467471
472+ const onTrayUpdateTrigger = async ( tray : TrayContent , menus : MenuItem [ ] ) => {
473+ const { fnName, observers } = PluginsTriggerMap [ PluginTrigger . OnTrayUpdate ]
474+
475+ let finalTray = tray
476+ let finalMenus = menus
477+ for ( const observer of observers ) {
478+ const cache = PluginsCache [ observer ]
479+
480+ if ( isPluginUnavailable ( cache ) ) continue
481+
482+ const metadata = getPluginMetadata ( cache . plugin )
483+ try {
484+ const fn = new window . AsyncFunction (
485+ 'Plugin' ,
486+ 'tray' ,
487+ 'menus' ,
488+ `${ cache . code } ; return await ${ fnName } (tray, menus)` ,
489+ )
490+ const { tray, menus } = await fn ( metadata , finalTray , finalMenus )
491+ finalTray = tray
492+ finalMenus = menus
493+ } catch ( error : any ) {
494+ throw `${ cache . plugin . name } : ` + ( error . message || error )
495+ }
496+ }
497+
498+ return [ finalTray , finalMenus ] as const
499+ }
500+
468501 const _watchDisabled = computed ( ( ) =>
469502 plugins . value
470503 . map ( ( v ) => v . disabled )
@@ -496,6 +529,7 @@ export const usePluginsStore = defineStore('plugins', () => {
496529 updatePlugins,
497530 getPluginById,
498531 reloadPlugin,
532+ onTrayUpdateTrigger,
499533 onSubscribeTrigger,
500534 onGenerateTrigger,
501535 onStartupTrigger : ( ) => noParamsTrigger ( PluginTrigger . OnStartup ) ,
0 commit comments