diff --git a/main/background.ts b/main/background.ts index 76d433b4..9cfbee6d 100644 --- a/main/background.ts +++ b/main/background.ts @@ -4,6 +4,7 @@ import { BrowserWindow, ipcMain, Menu, + shell, utilityProcess, UtilityProcess, } from "electron"; @@ -28,6 +29,10 @@ if (isProd) { let serverProcess: UtilityProcess | null; let mainWindow: BrowserWindow; +function isExternalUrl(url: string) { + return !url.includes("localhost:") && !url.includes("app://"); +} + function createGraphqlSeverProcess() { const serverPath = process.env.NODE_ENV === "production" @@ -77,6 +82,25 @@ app.on("ready", () => { await mainWindow.loadURL(`http://localhost:${port}`); }, 2500); } + + // hit when middle-clicking buttons or with a target set to _blank + // always deny, optionally redirect to browser + mainWindow.webContents.setWindowOpenHandler(({ url }) => { + if (isExternalUrl(url)) { + shell.openExternal(url); + } + + return { action: "deny" }; + }); + + // hit when clicking with no target + // optionally redirect to browser + mainWindow.webContents.on("will-navigate", (event, url) => { + if (isExternalUrl(url)) { + shell.openExternal(url); + event.preventDefault(); + } + }); }); function updateMenu(databaseName?: string) { diff --git a/main/helpers/menu.ts b/main/helpers/menu.ts index fd1b9650..8bd729e7 100644 --- a/main/helpers/menu.ts +++ b/main/helpers/menu.ts @@ -3,6 +3,7 @@ import { BrowserWindow, Menu, MenuItemConstructorOptions, + app, } from "electron"; export function initMenu( @@ -139,6 +140,15 @@ export function initMenu( ], enabled: hasChosenDatabase, }, + { + type: "separator", + }, + { + label: "Run Query", + accelerator: "CmdOrCtrl+Q", + click: () => win.webContents.send("menu-clicked", "run-query"), + enabled: hasChosenDatabase, + }, ], }, { @@ -161,5 +171,41 @@ export function initMenu( ], }, ]; + + const name = app.getName(); + applicationMenu.unshift({ + label: name, + submenu: [ + { + role: "about", + }, + { + type: "separator", + }, + { + role: "services", + submenu: [], + }, + { + type: "separator", + }, + { + role: "hide", + }, + { + role: "hideOthers", + }, + { + role: "unhide", + }, + { + type: "separator", + }, + { + role: "quit", + }, + ], + }); + return Menu.buildFromTemplate(applicationMenu); } diff --git a/package.json b/package.json index 607f713a..548118ff 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,16 @@ "productName": "dolt-sql-workbench", "version": "1.0.0", "main": "app/background.js", - "workspaces": [ - "graphql-server", - "web" - ], + "workspaces": { + "packages": [ + "graphql-server", + "web" + ], + "nohoist": [ + "graphql-server", + "graphql-server/**" + ] + }, "packageManager": "yarn@4.0.2", "scripts": { "dev": "nextron", @@ -28,7 +34,17 @@ ], "extraFiles": [ "graphql-server/dist/*", - "graphql-server/dist/**/*" + "graphql-server/dist/**/*", + "graphql-server/node_modules", + "!graphql-server/node_modules/@types", + "!graphql-server/node_modules/eslint", + "!graphql-server/node_modules/prettier", + "!graphql-server/node_modules/jest", + "!graphql-server/node_modules/yalc", + "!graphql-server/node_modules/webpack", + "!graphql-server/node_modules/eslint-*", + "!graphql-server/node_modules/ts-*", + "!graphql-server/node_modules/typescript" ], "mac": { "icon": "build/icon.icns", diff --git a/web/hooks/useElectronMenu.ts b/web/hooks/useElectronMenu.ts index 4d30e399..ed384d50 100644 --- a/web/hooks/useElectronMenu.ts +++ b/web/hooks/useElectronMenu.ts @@ -4,6 +4,7 @@ import { createTable, newBranch, newRelease, + query, schemaDiagram, upload, } from "@lib/urls"; @@ -51,6 +52,11 @@ export default function useElectronMenu(params: DatabasePageParams) { router.push(href, as).catch(console.error); break; } + case "run-query": { + const { href, as } = query(paramsWithRef); + router.push(href, as).catch(console.error); + break; + } default: break; }