From baae218b5ca439470447298218b7d2c08212451d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Tue, 26 Nov 2024 14:16:09 +0000 Subject: [PATCH] MenuBars continued (#137) * Destroy the existing menu bar * Standardise events --- .../electron-plugin/src/server/api/menuBar.ts | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/resources/js/electron-plugin/src/server/api/menuBar.ts b/resources/js/electron-plugin/src/server/api/menuBar.ts index 8d9b19a6..012e3afc 100644 --- a/resources/js/electron-plugin/src/server/api/menuBar.ts +++ b/resources/js/electron-plugin/src/server/api/menuBar.ts @@ -56,7 +56,7 @@ router.post("/create", (req, res) => { res.sendStatus(200); if (state.activeMenuBar) { - return; + state.activeMenuBar.tray.destroy(); } const { @@ -83,19 +83,6 @@ router.post("/create", (req, res) => { tray.setContextMenu(buildMenu(contextMenu)); - if (event) { - tray.on('click', (combo, bounds, position) => { - notifyLaravel('events', { - event, - payload: { - combo, - bounds, - position, - }, - }); - }); - } - state.activeMenuBar = menubar({ tray, tooltip, @@ -164,15 +151,41 @@ router.post("/create", (req, res) => { }); }); - state.activeMenuBar.tray.on("right-click", () => { + state.activeMenuBar.tray.on('click', (combo, bounds, position) => { + notifyLaravel('events', { + event: "\\Native\\Laravel\\Events\\MenuBar\\MenuBarClicked", + payload: { + combo, + bounds, + position, + }, + }); + }); + + state.activeMenuBar.tray.on("right-click", (combo, bounds) => { notifyLaravel("events", { - event: "\\Native\\Laravel\\Events\\MenuBar\\MenuBarContextMenuOpened" + event: "\\Native\\Laravel\\Events\\MenuBar\\MenuBarRightClicked", + payload: { + combo, + bounds, + } }); if (! onlyShowContextMenu) { + state.activeMenuBar.hideWindow(); state.activeMenuBar.tray.popUpContextMenu(buildMenu(contextMenu)); } }); + + state.activeMenuBar.tray.on('double-click', (combo, bounds) => { + notifyLaravel('events', { + event: "\\Native\\Laravel\\Events\\MenuBar\\MenuBarDoubleClicked", + payload: { + combo, + bounds, + }, + }); + }); }); });