Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
Allow external links.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Sep 24, 2017
1 parent 8b5ba2d commit f0a6cad
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enableLiveReload();
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
const shell = electron.shell;

const path = require('path');
const url = require('url');
Expand Down Expand Up @@ -36,6 +37,18 @@ function createWindow() {
// when you should delete the corresponding element.
mainWindow = null;
});

// TODO: I'd feel better about transforming the links on render.
// Support external links.
const handleRedirect = (e, newUrl) => {
if (newUrl !== mainWindow.getURL()) {
e.preventDefault();
shell.openExternal(newUrl);
}
};

mainWindow.webContents.on('will-navigate', handleRedirect);
mainWindow.webContents.on('new-window', handleRedirect);
}

// This method will be called when Electron has finished
Expand Down

0 comments on commit f0a6cad

Please sign in to comment.