From 8678d935830b5db3389af624e242bbc03d824b2c Mon Sep 17 00:00:00 2001 From: rhysd Date: Sun, 16 Apr 2017 02:57:54 +0900 Subject: [PATCH] open external URLs in external browser --- main/app.ts | 12 +++++++++++- renderer/index.ts | 2 +- renderer/ipc.ts | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main/app.ts b/main/app.ts index 44d7ffb..b481dc7 100644 --- a/main/app.ts +++ b/main/app.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import {app, BrowserWindow, globalShortcut, Tray} from 'electron'; +import {app, BrowserWindow, globalShortcut, Tray, shell} from 'electron'; import windowState = require('electron-window-state'); import * as menubar from 'menubar'; import log from './log'; @@ -23,6 +23,16 @@ export class App { } open() { + this.win.webContents.on('will-navigate', (e, url) => { + if (!url.startsWith(`https://${this.account.host}`)) { + e.preventDefault(); + shell.openExternal(url); + } + }); + this.win.webContents.on('new-window', (e, url) => { + e.preventDefault(); + shell.openExternal(url); + }); this.win.loadURL(`https://${this.account.host}${this.account.default_page}`); this.win.show(); } diff --git a/renderer/index.ts b/renderer/index.ts index b5b4b9a..3fe4e8f 100644 --- a/renderer/index.ts +++ b/renderer/index.ts @@ -1,4 +1,4 @@ -// import * as Mousetrap from 'mousetrap'; +import * as Mousetrap from 'mousetrap'; import {Config} from '../main/config'; import * as Ipc from './ipc'; import log from './log'; diff --git a/renderer/ipc.ts b/renderer/ipc.ts index 54b5029..35f6827 100644 --- a/renderer/ipc.ts +++ b/renderer/ipc.ts @@ -5,7 +5,7 @@ const ipc = electron.ipcRenderer; export function on(channel: IpcChannel, callback: Function) { ipc.on(channel, (...args: any[]) => { - log.info('IPC: Received from:', channel, args); + log.debug('IPC: Received from:', channel, args); callback(...args); }); }