Implement openNew for electron

This commit is contained in:
Junyoung Choi 2019-12-19 11:17:19 +09:00
parent 0cfd800ddf
commit 799eab51b4
2 changed files with 16 additions and 2 deletions

View File

@ -33,5 +33,15 @@
</head>
<body>
<div id="root"></div>
<script>
;(function() {
const electron = require('electron')
function $openExternal(url) {
console.log('opening ...', url)
electron.shell.openExternal(url)
}
window.$openExternal = $openExterna
})()
</script>
</body>
</html>

View File

@ -1,8 +1,12 @@
export const isElectron = () => navigator.userAgent.indexOf('Electron') >= 0
import isElectron from 'is-electron'
declare function $openExternal(url: string): void
export const openNew = (url: string) => {
if (isElectron()) {
// electron implementation
if (url.length > 0) {
$openExternal(url)
}
} else {
window.open(url, '_blank')
}