1- import type { MenuItemConstructorOptions , PopupOptions } from 'electron'
1+ import type { BaseWindow , KeyboardEvent , MenuItemConstructorOptions , PopupOptions } from 'electron'
22import { app , BrowserWindow , globalShortcut , Menu , nativeImage , TouchBar } from 'electron'
33import { ipcMain } from '@commas/electron-ipc'
44import type { TranslationVariables } from '@commas/types/i18n'
@@ -40,6 +40,17 @@ const terminalKeyBindings: MenuItem[] = require(resourceFile('terminal.menu.json
4040const focusedWindow = $ ( useFocusedWindow ( ) )
4141const hasFocusedWindow = $computed ( ( ) => Boolean ( focusedWindow ) )
4242
43+ interface CommandSource {
44+ $window : BaseWindow | undefined ,
45+ $event : KeyboardEvent ,
46+ }
47+
48+ function replaceCommandArgs ( args : unknown [ ] , source : CommandSource ) {
49+ return args . map ( value => {
50+ return typeof value === 'string' && Object . hasOwn ( source , value ) ? source [ value ] : value
51+ } )
52+ }
53+
4354function resolveBindingCommand ( binding : MenuItem ) {
4455 const result : MenuItemConstructorOptions = { ...binding }
4556 if ( binding . label ) {
@@ -48,12 +59,19 @@ function resolveBindingCommand(binding: MenuItem) {
4859 if ( binding . command ) {
4960 if ( binding . command . startsWith ( 'global-main:' ) ) {
5061 result . click = ( self , frame , event ) => {
51- globalHandler . invoke ( binding . command as never , ...( binding . args ?? [ ] ) as never , frame , event )
62+ globalHandler . invoke (
63+ binding . command as never ,
64+ ...replaceCommandArgs ( binding . args ?? [ ] , { $window : frame , $event : event } ) as never ,
65+ )
5266 }
5367 } else {
5468 result . click = ( self , frame , event ) => {
5569 if ( frame ) {
56- send ( ( frame as BrowserWindow ) . webContents , binding . command as never , ...( binding . args ?? [ ] ) as never , event )
70+ send (
71+ ( frame as BrowserWindow ) . webContents ,
72+ binding . command as never ,
73+ ...replaceCommandArgs ( binding . args ?? [ ] , { $window : frame , $event : event } ) as never ,
74+ )
5775 }
5876 }
5977 result . enabled = hasFocusedWindow
0 commit comments