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'
import { pick } from 'lodash'
import {
app,
ipcMain,
protocol,
Event,
} from 'electron'
import ContextMenu from 'electron-context-menu'
import Application from './main/Application'

View File

@ -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)
})
}
}

View File

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

View File

@ -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)