From df9207dfcfdb63b0c5736ac17eea05d28c099f62 Mon Sep 17 00:00:00 2001 From: kPherox Date: Mon, 22 Apr 2019 19:08:23 +0900 Subject: [PATCH] Carve out open url action --- src/background.ts | 2 +- src/main/Application.ts | 10 ++++++++++ src/main/ApplicationMenu.ts | 2 ++ src/main/Window.ts | 12 ++++-------- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/background.ts b/src/background.ts index 71b321d3..04ff598f 100644 --- a/src/background.ts +++ b/src/background.ts @@ -1,13 +1,13 @@ 'use strict' import { pick } from 'lodash' + import { app, ipcMain, protocol, Event, } from 'electron' - import ContextMenu from 'electron-context-menu' import Application from './main/Application' diff --git a/src/main/Application.ts b/src/main/Application.ts index a561f4b5..39362707 100644 --- a/src/main/Application.ts +++ b/src/main/Application.ts @@ -1,11 +1,13 @@ import { app, + shell, Menu, } from 'electron' import { createProtocol, installVueDevtools, } from 'vue-cli-plugin-electron-builder/lib' + import Window from './Window' const isDevelopment = process.env.NODE_ENV !== 'production' @@ -52,4 +54,12 @@ export default class Application { Window.Main() } } + + public static openUrl(event: Event, url: string) { + shell.openExternal(url, { + activate: false + }, (err) => { + if (err) console.log(err) + }) + } } \ No newline at end of file diff --git a/src/main/ApplicationMenu.ts b/src/main/ApplicationMenu.ts index ad509543..154ba283 100644 --- a/src/main/ApplicationMenu.ts +++ b/src/main/ApplicationMenu.ts @@ -4,7 +4,9 @@ import { Menu, MenuItemConstructorOptions } from 'electron' + import Window from './Window' + import { bugs } from '../../package.json' import { documentURL } from '../../info.json' diff --git a/src/main/Window.ts b/src/main/Window.ts index 03a1b1ea..8d78fe9e 100644 --- a/src/main/Window.ts +++ b/src/main/Window.ts @@ -1,15 +1,15 @@ import { join } from 'path' import { - shell, BrowserWindow, BrowserWindowConstructorOptions, Event, Input, - app, } from 'electron' import { register as shortcutRegister } from 'electron-localshortcut' +import Application from './Application' + declare const __static: string const isDevelopment = process.env.NODE_ENV !== 'production' @@ -91,15 +91,11 @@ export default class Window { }) let openUrl = (event: Event, url: string) => { - if (url === this.ApplicationURL + options.loadPath) { + if (url.startsWith(this.ApplicationURL)) { return } event.preventDefault() - shell.openExternal(url, { - activate: false - }, (err) => { - if (err) console.log(err) - }) + Application.openUrl(event, url) } win.webContents.on('will-navigate', openUrl) win.webContents.on('new-window', openUrl)