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: ` Window 1

🪟 Window 1

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 šŸ‘†

`, }); // Create second window with different custom menu const window2 = app.createBrowserWindow({ title: 'Window 2 - Different Menu', width: 400, height: 300, x: 520, y: 100, menu: { items: [ { label: 'Window 2', submenu: { items: [ { id: 'window-2-action', label: 'Window 2 Action', accelerator: 'Ctrl+2' }, { role: 'separator' }, { id: 'close-window', label: 'Close Window', accelerator: 'Ctrl+W' }, ], }, }, { label: 'Tools', submenu: { items: [{ role: 'selectall' }, { role: 'separator' }, { id: 'tool-action', label: 'Special Tool' }], }, }, ], }, }); const _webview2 = window2.createWebview({ html: ` Window 2

🪟 Window 2

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 šŸ‘ˆ

`, }); // Create third window that uses the global menu (no custom menu specified) const window3 = app.createBrowserWindow({ title: 'Window 3 - Global Menu', width: 400, height: 300, x: 310, y: 420, show_menu: true, // Uses global menu }); const _webview3 = window3.createWebview({ html: ` Window 3

šŸŒ Window 3

Global Menu:

• App → Global Action (Ctrl+G)

• App → Quit (Ctrl+Q)


This window uses the global menu!

Set with app.setMenu()

`, }); // Log menu status for each window console.log(`Window 1 has menu: ${window1.hasMenu()}`); console.log(`Window 2 has menu: ${window2.hasMenu()}`); console.log(`Window 3 has menu: ${window3.hasMenu()}`); console.log('\nšŸŽÆ Try different menu items in each window!'); console.log('Notice how each window responds to different menu items.'); console.log('Use Ctrl+Q to quit the application.\n'); // Run the application app.run();