From edfe81e06a65a41465395afb0766a16f14fd2281 Mon Sep 17 00:00:00 2001 From: rhysd Date: Wed, 19 Apr 2017 20:56:54 +0900 Subject: [PATCH] do not crash on external link on Windows --- main/common.ts | 1 + main/config.ts | 6 +++--- main/window.ts | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/main/common.ts b/main/common.ts index 54176a9..a5966ef 100644 --- a/main/common.ts +++ b/main/common.ts @@ -3,6 +3,7 @@ import {app} from 'electron'; export const IS_DEBUG = process.env.NODE_ENV === 'development'; export const IS_DARWIN = process.platform === 'darwin'; +export const IS_WINDOWS = process.platform === 'win32'; export const APP_ICON = path.join(__dirname, '..', 'resources', 'icon', 'icon.png'); export const PRELOAD_JS = path.join(__dirname, '..', 'renderer', 'preload.js'); export const DATA_DIR = app.getPath('userData'); diff --git a/main/config.ts b/main/config.ts index f50c3b0..1ffcdd3 100644 --- a/main/config.ts +++ b/main/config.ts @@ -1,7 +1,7 @@ import {app, systemPreferences, dialog, shell} from 'electron'; import * as fs from 'fs'; import log from './log'; -import {CONFIG_FILE} from './common'; +import {CONFIG_FILE, IS_DARWIN, IS_WINDOWS} from './common'; export interface Account { host: string; @@ -20,8 +20,8 @@ export interface Config { } function makeDefaultConfig(): Config { - const IsDarkMode = (process.platform === 'darwin') && systemPreferences.isDarkMode(); - const menubarBroken = process.platform === 'win32'; + const IsDarkMode = IS_DARWIN && systemPreferences.isDarkMode(); + const menubarBroken = IS_WINDOWS; return { hot_key: 'CmdOrCtrl+Shift+S', diff --git a/main/window.ts b/main/window.ts index 7088eef..6e7d924 100644 --- a/main/window.ts +++ b/main/window.ts @@ -4,7 +4,7 @@ import * as menubar from 'menubar'; import {Config, Account} from './config'; import {partitionForAccount} from './account_switcher'; import log from './log'; -import {IS_DEBUG, IS_DARWIN, APP_ICON, PRELOAD_JS, trayIcon} from './common'; +import {IS_DEBUG, IS_DARWIN, IS_WINDOWS, APP_ICON, PRELOAD_JS, trayIcon} from './common'; export default class Window { static create(account: Account, config: Config, mb: Menubar.MenubarApp | null = null) { @@ -34,6 +34,11 @@ export default class Window { log.debug('Opened URL with external browser (will-navigate)', url); }); browser.webContents.on('new-window', (e, url) => { + if (IS_WINDOWS) { + // XXX: + // On Windows, rel="noopener" lets app crash on preventing the event. + return; + } e.preventDefault(); shell.openExternal(url); log.debug('Opened URL with external browser (new-window)', url);