Carve out open url action

This commit is contained in:
kPherox 2019-04-22 19:08:23 +09:00
parent ee18182915
commit df9207dfcf
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D
4 changed files with 17 additions and 9 deletions

View File

@ -1,13 +1,13 @@
'use strict' 'use strict'
import { pick } from 'lodash' import { pick } from 'lodash'
import { import {
app, app,
ipcMain, ipcMain,
protocol, protocol,
Event, Event,
} from 'electron' } from 'electron'
import ContextMenu from 'electron-context-menu' import ContextMenu from 'electron-context-menu'
import Application from './main/Application' import Application from './main/Application'

View File

@ -1,11 +1,13 @@
import { import {
app, app,
shell,
Menu, Menu,
} from 'electron' } from 'electron'
import { import {
createProtocol, createProtocol,
installVueDevtools, installVueDevtools,
} from 'vue-cli-plugin-electron-builder/lib' } from 'vue-cli-plugin-electron-builder/lib'
import Window from './Window' import Window from './Window'
const isDevelopment = process.env.NODE_ENV !== 'production' const isDevelopment = process.env.NODE_ENV !== 'production'
@ -52,4 +54,12 @@ export default class Application {
Window.Main() Window.Main()
} }
} }
public static openUrl(event: Event, url: string) {
shell.openExternal(url, {
activate: false
}, (err) => {
if (err) console.log(err)
})
}
} }

View File

@ -4,7 +4,9 @@ import {
Menu, Menu,
MenuItemConstructorOptions MenuItemConstructorOptions
} from 'electron' } from 'electron'
import Window from './Window' import Window from './Window'
import { bugs } from '../../package.json' import { bugs } from '../../package.json'
import { documentURL } from '../../info.json' import { documentURL } from '../../info.json'

View File

@ -1,15 +1,15 @@
import { join } from 'path' import { join } from 'path'
import { import {
shell,
BrowserWindow, BrowserWindow,
BrowserWindowConstructorOptions, BrowserWindowConstructorOptions,
Event, Event,
Input, Input,
app,
} from 'electron' } from 'electron'
import { register as shortcutRegister } from 'electron-localshortcut' import { register as shortcutRegister } from 'electron-localshortcut'
import Application from './Application'
declare const __static: string declare const __static: string
const isDevelopment = process.env.NODE_ENV !== 'production' const isDevelopment = process.env.NODE_ENV !== 'production'
@ -91,15 +91,11 @@ export default class Window {
}) })
let openUrl = (event: Event, url: string) => { let openUrl = (event: Event, url: string) => {
if (url === this.ApplicationURL + options.loadPath) { if (url.startsWith(this.ApplicationURL)) {
return return
} }
event.preventDefault() event.preventDefault()
shell.openExternal(url, { Application.openUrl(event, url)
activate: false
}, (err) => {
if (err) console.log(err)
})
} }
win.webContents.on('will-navigate', openUrl) win.webContents.on('will-navigate', openUrl)
win.webContents.on('new-window', openUrl) win.webContents.on('new-window', openUrl)