import { Application } from '../index.js'; const app = new Application(); // Handle menu events app.on('custom-menu-click', ({ customMenuEvent: menuEvent }) => { console.log(`Menu "${menuEvent.id}" clicked on window ${menuEvent.windowId}`); switch (menuEvent.id) { case 'close-window': console.log('Closing window...'); // In a real app, you would close the specific window break; case 'window-1-action': console.log('Window 1 specific action!'); break; case 'window-2-action': console.log('Window 2 specific action!'); break; case 'global-action': console.log('Global action from any window!'); break; case 'quit': console.log('Quitting application...'); app.exit(); break; } }); // Set a global application menu app.setMenu({ items: [ { label: 'App', submenu: { items: [ { id: 'global-action', label: 'Global Action', accelerator: 'CmdOrCtrl+G' }, { role: 'separator' }, { id: 'quit', label: 'Quit', accelerator: 'CmdOrCtrl+Q' }, ], }, }, ], }); console.log('šŖ Window-Specific Menu Example'); console.log('Creating two windows with different menus...\n'); // Create first window with custom menu const window1 = app.createBrowserWindow({ title: 'Window 1 - Custom Menu', width: 400, height: 300, x: 100, y: 100, menu: { items: [ { label: 'Window 1', submenu: { items: [ { id: 'window-1-action', label: 'Window 1 Action', accelerator: 'Ctrl+1' }, { role: 'separator' }, { id: 'close-window', label: 'Close Window', accelerator: 'Ctrl+W' }, ], }, }, { label: 'Edit', submenu: { items: [{ role: 'copy' }, { role: 'paste' }], }, }, ], }, }); const _webview1 = window1.createWebview({ html: `
Custom Menu:
⢠Window 1 ā Window 1 Action (Ctrl+1)
⢠Window 1 ā Close Window (Ctrl+W)
⢠Edit ā Copy, Paste
This window has its own menu!
Try the menu items above š
Different Menu:
⢠Window 2 ā Window 2 Action (Ctrl+2)
⢠Window 2 ā Close Window (Ctrl+W)
⢠Tools ā Select All, Special Tool
This window has a different menu!
Compare with Window 1 š
Global Menu:
⢠App ā Global Action (Ctrl+G)
⢠App ā Quit (Ctrl+Q)
This window uses the global menu!
Set with app.setMenu()