@@ -39,16 +39,16 @@ export class ButtonActionRunner {
3939 * Run the action(s) defined in the button config.
4040 * Will show a notice if an error occurs.
4141 *
42- * @param buttonConfig
42+ * @param config
4343 * @param filePath
4444 */
45- async runButtonAction ( buttonConfig : ButtonConfig , filePath : string ) : Promise < void > {
45+ async runButtonAction ( config : ButtonConfig , filePath : string ) : Promise < void > {
4646 try {
47- if ( buttonConfig . action ) {
48- await this . plugin . api . buttonActionRunner . runAction ( buttonConfig . action , filePath ) ;
49- } else if ( buttonConfig . actions ) {
50- for ( const action of buttonConfig . actions ) {
51- await this . plugin . api . buttonActionRunner . runAction ( action , filePath ) ;
47+ if ( config . action ) {
48+ await this . plugin . api . buttonActionRunner . runAction ( config , config . action , filePath ) ;
49+ } else if ( config . actions ) {
50+ for ( const action of config . actions ) {
51+ await this . plugin . api . buttonActionRunner . runAction ( config , action , filePath ) ;
5252 }
5353 } else {
5454 console . warn ( 'meta-bind | ButtonMDRC >> no action defined' ) ;
@@ -101,15 +101,16 @@ export class ButtonActionRunner {
101101 * Run a specific button action.
102102 * Will throw.
103103 *
104+ * @param config
104105 * @param action
105106 * @param filePath
106107 */
107- async runAction ( action : ButtonAction , filePath : string ) : Promise < void > {
108+ async runAction ( config : ButtonConfig , action : ButtonAction , filePath : string ) : Promise < void > {
108109 if ( action . type === ButtonActionType . COMMAND ) {
109110 await this . runCommandAction ( action ) ;
110111 return ;
111112 } else if ( action . type === ButtonActionType . JS ) {
112- await this . runJSAction ( action , filePath ) ;
113+ await this . runJSAction ( config , action , filePath ) ;
113114 return ;
114115 } else if ( action . type === ButtonActionType . OPEN ) {
115116 await this . runOpenAction ( action , filePath ) ;
@@ -135,8 +136,12 @@ export class ButtonActionRunner {
135136 this . plugin . internal . executeCommandById ( action . command ) ;
136137 }
137138
138- async runJSAction ( action : JSButtonAction , filePath : string ) : Promise < void > {
139- const unloadCallback = await this . plugin . internal . jsEngineRunFile ( action . file , filePath ) ;
139+ async runJSAction ( config : ButtonConfig , action : JSButtonAction , filePath : string ) : Promise < void > {
140+ const configOverrides : Record < string , unknown > = {
141+ buttonConfig : config ,
142+ args : action . args ,
143+ } ;
144+ const unloadCallback = await this . plugin . internal . jsEngineRunFile ( action . file , filePath , configOverrides ) ;
140145 unloadCallback ( ) ;
141146 }
142147
0 commit comments