mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
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.
This commit is contained in:
parent
4c45bca56b
commit
50a4074c39
@ -11,6 +11,7 @@ import { debounce } from "throttle-debounce";
|
|||||||
import { getBackendHostPort } from "../frontend/app/store/global";
|
import { getBackendHostPort } from "../frontend/app/store/global";
|
||||||
import * as services from "../frontend/app/store/services";
|
import * as services from "../frontend/app/store/services";
|
||||||
import * as keyutil from "../frontend/util/keyutil";
|
import * as keyutil from "../frontend/util/keyutil";
|
||||||
|
import { fireAndForget } from "../frontend/util/util";
|
||||||
|
|
||||||
const electronApp = electron.app;
|
const electronApp = electron.app;
|
||||||
const isDev = process.env.WAVETERM_DEV;
|
const isDev = process.env.WAVETERM_DEV;
|
||||||
@ -460,10 +461,11 @@ electron.ipcMain.on("getCursorPoint", (event) => {
|
|||||||
async function createNewWaveWindow() {
|
async function createNewWaveWindow() {
|
||||||
let clientData = await services.ClientService.GetClientData();
|
let clientData = await services.ClientService.GetClientData();
|
||||||
const newWindow = await services.ClientService.MakeWindow();
|
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 }) => {
|
electron.ipcMain.on("contextmenu-show", (event, menuDefArr: ElectronContextMenuItem[], { x, y }) => {
|
||||||
if (menuDefArr == null || menuDefArr.length == 0) {
|
if (menuDefArr == null || menuDefArr.length == 0) {
|
||||||
@ -498,10 +500,11 @@ function makeAppMenu() {
|
|||||||
let fileMenu: Electron.MenuItemConstructorOptions[] = [];
|
let fileMenu: Electron.MenuItemConstructorOptions[] = [];
|
||||||
fileMenu.push({
|
fileMenu.push({
|
||||||
label: "New Window",
|
label: "New Window",
|
||||||
click: createNewWaveWindow,
|
accelerator: "CommandOrControl+N",
|
||||||
|
click: () => fireAndForget(createNewWaveWindow),
|
||||||
});
|
});
|
||||||
fileMenu.push({
|
fileMenu.push({
|
||||||
label: "Close Window",
|
role: "close",
|
||||||
click: () => {
|
click: () => {
|
||||||
electron.BrowserWindow.getFocusedWindow()?.close();
|
electron.BrowserWindow.getFocusedWindow()?.close();
|
||||||
},
|
},
|
||||||
|
@ -89,4 +89,14 @@ function makeIconClass(icon: string, fw: boolean): string {
|
|||||||
return null;
|
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<any>) {
|
||||||
|
f().catch((e) => {
|
||||||
|
console.log("fireAndForget error", e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export { base64ToArray, base64ToString, fireAndForget, isBlank, jsonDeepEqual, makeIconClass, stringToBase64 };
|
||||||
|
Loading…
Reference in New Issue
Block a user