@@ -7,13 +7,13 @@ const webContents = (win: BrowserWindow) => win.webContents ?? (win.id && win);
77type DecoratedMenuItem = MenuItem & Partial < { transform : ( text : string ) => string ; click : ( menuItem : MenuItem ) => void } > ;
88
99const decorateMenuItem =
10- < T extends MenuItem > ( menuItem : T ) =>
11- ( options : { transform ?: ( text : string ) => string ; click ?: ( ) => void } = { } ) : T => {
10+ < T extends MenuItem > ( menuItem : Partial < T > & { id : string ; label : string } ) =>
11+ ( options : { transform ?: ( text : string ) => string ; click ?: ( ) => void } = { } ) : MenuItem => {
1212 if ( options . transform && ! ( "transform" in menuItem ) ) {
1313 ( menuItem as unknown as DecoratedMenuItem ) . transform = options . transform ;
1414 }
1515
16- return menuItem ;
16+ return menuItem as unknown as MenuItem ;
1717 } ;
1818const removeUnusedMenuItems = ( menuTemplate : DecoratedMenuItem [ ] ) => {
1919 let notDeletedPreviousElement ;
@@ -130,10 +130,10 @@ const create = (win: BrowserWindow, options: ContextMenuOptions) => {
130130 defaultActions . copy ( ) ,
131131 defaultActions . paste ( ) ,
132132 shouldShowSelectAll && defaultActions . selectAll ( ) ,
133- ] ;
133+ ] . filter ( Boolean ) as unknown as MenuItem [ ] ;
134134
135135 if ( options . menu ) {
136- menuTemplate = options . menu ( defaultActions , properties , win , dictionarySuggestions , event ) ;
136+ menuTemplate = options . menu ( defaultActions , properties , win , [ ] , event ) ;
137137 }
138138
139139 if ( options . prepend ) {
@@ -154,7 +154,7 @@ const create = (win: BrowserWindow, options: ContextMenuOptions) => {
154154
155155 // Filter out leading/trailing separators
156156 // TODO: https://github.com/electron/electron/issues/5869
157- menuTemplate = removeUnusedMenuItems ( menuTemplate ) ;
157+ menuTemplate = removeUnusedMenuItems ( menuTemplate as unknown as DecoratedMenuItem [ ] ) ;
158158
159159 for ( const menuItem of menuTemplate ) {
160160 // Apply custom labels for default menu items
@@ -170,17 +170,17 @@ const create = (win: BrowserWindow, options: ContextMenuOptions) => {
170170 }
171171
172172 if ( menuTemplate . length > 0 ) {
173- const menu = electron . Menu . buildFromTemplate ( menuTemplate ) ;
173+ const menu = electron . Menu . buildFromTemplate ( menuTemplate as unknown as MenuItem [ ] ) ;
174174
175175 if ( typeof options . onShow === "function" ) {
176- menu . on ( "menu-will-show" , options . onShow ) ;
176+ menu . on ( "menu-will-show" , options . onShow as any ) ;
177177 }
178178
179179 if ( typeof options . onClose === "function" ) {
180- menu . on ( "menu-will-close" , options . onClose ) ;
180+ menu . on ( "menu-will-close" , options . onClose as any ) ;
181181 }
182182
183- menu . popup ( win ) ;
183+ menu . popup ( { window : win } ) ;
184184 }
185185 } ;
186186
0 commit comments