From d3a11b0e4cf1a38ae23c6d21918cb731c4d8f023 Mon Sep 17 00:00:00 2001 From: kPherox Date: Mon, 8 Apr 2019 04:28:54 +0900 Subject: [PATCH] Change to open links in default browser --- src/background.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index 8ba4fc3d..778d948f 100644 --- a/src/background.js +++ b/src/background.js @@ -40,7 +40,6 @@ protocol.registerStandardSchemes(['app'], { secure: true }) async function createWindow(windowName, loadPath, windowOptions, singleton, lastAction, openDevTools) { if (typeof windows[windowName] !== 'undefined') { windows[windowName].show() - windows[windowName].focus() return } @@ -60,10 +59,23 @@ async function createWindow(windowName, loadPath, windowOptions, singleton, last windows[windowName] = undefined }) + let openUrl = (event, url) => { + if (url === process.env.WEBPACK_DEV_SERVER_URL + loadPath) { + return + } + event.preventDefault() + shell.openExternal(url, { + activate: false + }, (err) => { + if (err) console.log(err) + }) + } + win.webContents.on('will-navigate', openUrl) + win.webContents.on('new-window', openUrl) + if (process.env.WEBPACK_DEV_SERVER_URL) { // `electron:serve`で起動した時の読み込み win.loadURL(process.env.WEBPACK_DEV_SERVER_URL + loadPath) - if (openDevTools) win.webContents.openDevTools() } else { // ビルドしたアプリでの読み込み if (!createdAppProtocol) { @@ -73,6 +85,8 @@ async function createWindow(windowName, loadPath, windowOptions, singleton, last win.loadURL(`app://./${loadPath}`) } + if (isDevelopment && openDevTools) win.webContents.openDevTools() + lastAction(win) windows[windowName] = win