import { app , Menu , MenuItemConstructorOptions , BrowserWindow , shell } from 'electron' ; import { WINDOW_TYPE } from './constants' ; import * as background from './background' ; import { ShaderType } from './scripts/renderer/_constants' ; const ___ = 'separator' ; function sendAction ( action , payload ? ) { const focusedWindow = BrowserWindow . getFocusedWindow ( ) ; if ( focusedWindow ) { focusedWindow . webContents . send ( action , payload ) ; } } function getMenuTemplate ( type ) { const isPlayground = type === WINDOW_TYPE . PLAYGROUND ; const appSubmenu = { label : app . getName ( ) , submenu : [ { role : 'about' } , { type : ___ } , { role : 'hide' } , { role : 'hideothers' } , { role : 'unhide' } , { type : ___ } , { role : 'quit' } ] } ; const fileSubmenu = { label : 'File' , submenu : [ { label : 'New' , accelerator : 'CmdOrCtrl+N' , click ( ) { background . newFile ( ) ; } } , { label : 'Open...' , accelerator : 'CmdOrCtrl+O' , click ( ) { background . showOpenFileDialog ( ) ; } } , { role : 'recentDocuments' , submenu : [ { type : ___ } , { label : 'Clear Menu' , click : ( ) => { background . clearRecentDocuments ( ) ; } } ] } , { type : ___ } , { label : 'Close' , enabled : isPlayground , role : 'close' } , { label : 'Save' , enabled : isPlayground , accelerator : 'CmdOrCtrl+S' , click : ( ) => { sendAction ( 'save' ) ; } } ] } ; const editSubmenu = { label : 'Edit' , submenu : [ { role : 'undo' , enabled : isPlayground } , { role : 'redo' , enabled : isPlayground } , { type : ___ } , { role : 'cut' , enabled : isPlayground } , { role : 'copy' , enabled : isPlayground } , { role : 'paste' , enabled : isPlayground } ] } ; const toolsSubmenu = { label : 'Tools' , submenu : [ { label : 'Compile and Run' , enabled : isPlayground , accelerator : 'CmdOrCtrl+R' , click : ( ) => { sendAction ( 'compile-and-run' ) ; } } ] } ; const viewSubmenu = { label : 'View' , submenu : [ { label : 'Vertex Shader' , enabled : isPlayground , accelerator : 'CmdOrCtrl+1' , click : ( ) => { sendAction ( 'set-active-shader' , ShaderType . Vertex ) ; } } , { label : 'Fragment Shader' , enabled : isPlayground , accelerator : 'CmdOrCtrl+2' , click : ( ) => { sendAction ( 'set-active-shader' , ShaderType . Fragment ) ; } } , { type : ___ } , { label : 'Toggle Scene View' , enabled : isPlayground , accelerator : 'CmdOrCtrl+3' , click : ( ) => { sendAction ( 'toggle-scene-view' ) ; } } , { type : ___ } , { role : 'resetzoom' } , { role : 'zoomin' } , { role : 'zoomout' } , { type : ___ } , { label : 'Toggle Full Screen' , enabled : isPlayground , accelerator : process . platform === 'darwin' ? 'Ctrl+Cmd+F' : 'F11' , click : ( menuItem , window ) => { window . setFullScreen ( ! window . isFullScreen ( ) ) ; } } ] } ; const windowSubmenu = { role : 'window' , submenu : ( process . platform === 'darwin' ) ? [ { role : 'minimize' } , { role : 'close' } , { role : 'zoom' } , { type : ___ } , { label : 'Welcome' , click : ( ) => { background . showWelcomeWindow ( ) ; } } , { type : ___ } , { role : 'front' } ] : [ { role : 'minimize' } , { role : 'close' } , { type : ___ } , { label : 'Welcome' , click : ( ) => { background . showWelcomeWindow ( ) ; } } ] } ; const helpSubmenu = { role : 'help' , submenu : [ { label : 'Source Code' , click : ( ) => { shell . openExternal ( 'https://github.com/AgustinBrst/Shader-Playgrounds' ) ; } } , { label : 'Send Feedback' , click : ( ) => { shell . openExternal ( 'https://github.com/AgustinBrst/Shader-Playgrounds/issues/new' ) ; } } , { type : ___ } , { label : `What's New in ${ app . getName ( ) }` , click : ( ) => { shell . openExternal ( 'https://github.com/AgustinBrst/Shader-Playgrounds/releases' ) ; } } , { type : ___ } , { role : 'toggledevtools' } ] } ; const template = [ fileSubmenu , editSubmenu , toolsSubmenu , viewSubmenu , windowSubmenu , helpSubmenu ] ; if ( process . platform === 'darwin' ) { template . unshift ( appSubmenu ) ; } return template ; } function setAppMenu ( type ) { const menu = Menu . buildFromTemplate ( getMenuTemplate ( type ) ) ; Menu . setApplicationMenu ( menu ) ; } function setWindowMenu ( window , type ) { const menu = Menu . buildFromTemplate ( getMenuTemplate ( type ) ) ; window . setMenu ( menu ) ; } export { setAppMenu , setWindowMenu } ;