From 50a4074c39700f8a3d38bdd4b83ee14925787f71 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 28 Jun 2024 16:24:40 -0700 Subject: [PATCH] Fix new window from menu bar (#91) Fixes the New Window menu item so that it shows the new window after it loads and captures any errors that occur. Also adds a keyboard shortcut for new window and uses the native shortcut for close window. --- emain/emain.ts | 11 +++++++---- frontend/util/util.ts | 12 +++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/emain/emain.ts b/emain/emain.ts index f9011e362..e92d2eccc 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -11,6 +11,7 @@ import { debounce } from "throttle-debounce"; import { getBackendHostPort } from "../frontend/app/store/global"; import * as services from "../frontend/app/store/services"; import * as keyutil from "../frontend/util/keyutil"; +import { fireAndForget } from "../frontend/util/util"; const electronApp = electron.app; const isDev = process.env.WAVETERM_DEV; @@ -460,10 +461,11 @@ electron.ipcMain.on("getCursorPoint", (event) => { async function createNewWaveWindow() { let clientData = await services.ClientService.GetClientData(); const newWindow = await services.ClientService.MakeWindow(); - createBrowserWindow(clientData.oid, newWindow); + const newBrowserWindow = createBrowserWindow(clientData.oid, newWindow); + newBrowserWindow.show(); } -electron.ipcMain.on("openNewWindow", createNewWaveWindow); +electron.ipcMain.on("openNewWindow", () => fireAndForget(createNewWaveWindow)); electron.ipcMain.on("contextmenu-show", (event, menuDefArr: ElectronContextMenuItem[], { x, y }) => { if (menuDefArr == null || menuDefArr.length == 0) { @@ -498,10 +500,11 @@ function makeAppMenu() { let fileMenu: Electron.MenuItemConstructorOptions[] = []; fileMenu.push({ label: "New Window", - click: createNewWaveWindow, + accelerator: "CommandOrControl+N", + click: () => fireAndForget(createNewWaveWindow), }); fileMenu.push({ - label: "Close Window", + role: "close", click: () => { electron.BrowserWindow.getFocusedWindow()?.close(); }, diff --git a/frontend/util/util.ts b/frontend/util/util.ts index cd5dbc460..723f77e0a 100644 --- a/frontend/util/util.ts +++ b/frontend/util/util.ts @@ -89,4 +89,14 @@ function makeIconClass(icon: string, fw: boolean): string { return null; } -export { base64ToArray, base64ToString, isBlank, jsonDeepEqual, makeIconClass, stringToBase64 }; +/** + * A wrapper function for running a promise and catching any errors + * @param f The promise to run + */ +function fireAndForget(f: () => Promise) { + f().catch((e) => { + console.log("fireAndForget error", e); + }); +} + +export { base64ToArray, base64ToString, fireAndForget, isBlank, jsonDeepEqual, makeIconClass, stringToBase64 };