refactor: make shell.OpenExternal async (#17135)

This commit is contained in:
Shelley Vohr 2019-05-03 13:53:45 -07:00 committed by GitHub
parent 0755857a0c
commit 6d96f30ed3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 70 additions and 140 deletions

View file

@ -240,7 +240,10 @@ const template = [
submenu: [
{
label: 'Learn More',
click () { require('electron').shell.openExternalSync('https://electronjs.org') }
click: async () => {
const { shell } = require('electron')
await shell.openExternal('https://electronjs.org')
}
}
]
}

View file

@ -32,18 +32,6 @@ Returns `Boolean` - Whether the item was successfully opened.
Open the given file in the desktop's default manner.
### `shell.openExternalSync(url[, options])`
* `url` String - Max 2081 characters on Windows, or the function returns false.
* `options` Object (optional)
* `activate` Boolean (optional) - `true` to bring the opened application to the
foreground. The default is `true`. _macOS_
* `workingDirectory` String (optional) - The working directory. _Windows_
Returns `Boolean` - Whether an application was available to open the URL.
Open the given external protocol URL in the desktop's default manner. (For example, mailto: URLs in the user's default mail agent).
### `shell.openExternal(url[, options])`
* `url` String - Max 2081 characters on windows.

View file

@ -774,10 +774,10 @@ The following example code opens the new url in system's default browser.
const { shell } = require('electron')
const webview = document.querySelector('webview')
webview.addEventListener('new-window', (e) => {
webview.addEventListener('new-window', async (e) => {
const protocol = require('url').parse(e.url).protocol
if (protocol === 'http:' || protocol === 'https:') {
shell.openExternalSync(e.url)
await shell.openExternal(e.url)
}
})
```