Open external URLs in OS default browser

This commit is contained in:
Alice Gaudon 2020-01-03 22:47:10 +01:00
parent 3abd3dfd5e
commit 96191e5857

View File

@ -1,6 +1,6 @@
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import {app, BrowserWindow, ipcMain, Menu, Tray} from "electron"; import {app, BrowserWindow, ipcMain, Menu, shell, Tray} from "electron";
import Config from "./Config"; import Config from "./Config";
@ -60,6 +60,15 @@ function createWindow() {
}); });
} }
// Open external links in default OS browser
app.on('web-contents-created', (e, contents) => {
if (contents.getType() === 'webview') {
contents.on('new-window', (e, url) => {
e.preventDefault();
shell.openExternal(url);
});
}
});
// Sync services with navigation // Sync services with navigation
window.webContents.on('dom-ready', sendServices); window.webContents.on('dom-ready', sendServices);