From 90c3aaac7240a1d96f4f48e3f297b2acd65c0437 Mon Sep 17 00:00:00 2001 From: Kyle Kemp Date: Thu, 6 May 2021 09:39:41 -0500 Subject: [PATCH] open external urls in browser --- src/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 13057be..1de157c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -const { app, BrowserWindow } = require('electron'); +const { app, BrowserWindow, shell } = require('electron'); const DiscordRPC = require('discord-rpc'); const startCase = require('lodash.startcase'); const path = require('path'); @@ -30,7 +30,8 @@ const createWindow = () => { ...opts, webPreferences: { webviewTag: true, - nodeIntegration: true + nodeIntegration: true, + nativeWindowOpen: true } }); @@ -70,6 +71,16 @@ app.on('activate', () => { } }); +app.on('web-contents-created', (e, contents) => { + if(contents.getType() === 'webview') { + + contents.addListener('will-navigate', (e, url) => { + e.preventDefault(); + shell.openExternal(url); + }); + } +}) + // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and import them here.