Skip to content

Commit

Permalink
improve middle click handling logic, closes #285
Browse files Browse the repository at this point in the history
* so middle click on https/http links will lead to opening the url in a default browser (same behavior as primary button clicking)
  • Loading branch information
vladimiry committed Apr 26, 2020
1 parent 22b1c3d commit 70d8666
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/electron-main/web-contents.ts
Expand Up @@ -2,6 +2,7 @@ import _logger from "electron-log";
import {BrowserWindow, Menu, MenuItemConstructorOptions, WebPreferences, app, clipboard, screen} from "electron";
import {equals, pick} from "remeda";
import {inspect} from "util";
import {isWebUri} from "valid-url";
import {take} from "rxjs/operators";

import {Context} from "./model";
Expand Down Expand Up @@ -67,9 +68,13 @@ export async function initWebContentsCreatingHandlers(ctx: Context): Promise<voi
const webViewEntryUrlsWhitelist: readonly string[] = ctx.locations.webClients.map(({entryUrl}) => `${entryUrl}/`);

app.on("web-contents-created", async (...[, webContents]) => {
webContents.on("new-window", (event, url) => {
webContents.on("new-window", async (event, url) => {
event.preventDefault();
notifyLogAndThrow(`Opening a new window is forbidden, url: "${url}"`);
if (isWebUri(url)) {
await endpoints.openExternal({url});
return;
}
logger.warn(`Opening a new window is forbidden, url: "${url}"`);
});

webContents.on("context-menu", async (...[, {editFlags, linkURL, linkText, isEditable, selectionText}]) => {
Expand Down

0 comments on commit 70d8666

Please sign in to comment.