import { shell } from 'electron' ; import contextMenu from 'electron-context-menu' ; export function initContextMenu ( createNewWindow , createNewTab , mainUrl , window ? ) { const options = { showInspectElement : false , prepend : ( actions , params ) => { const items = [ ] ; const showOpenLink = ! params . pageURL . startsWith ( mainUrl ) ; if ( params . linkURL && showOpenLink ) { items . push ( { label : 'Open Link in Default Browser' , click : ( ) => { shell . openExternal ( params . linkURL ) ; } , } ) ; items . push ( { label : 'Open Link in New Window' , click : ( ) => { createNewWindow ( params . linkURL ) ; } , } ) ; if ( createNewTab ) { items . push ( { label : 'Open Link in New Tab' , click : ( ) => { createNewTab ( params . linkURL , false ) ; } , } ) ; } } return items ; } , } ; if ( window ) { ( options . window as any ) = window ; } contextMenu ( options ) ; }