feat: split openExternal into sync and async (#16176)
* feat: split openExternal into sync and async * v8::Locker => mate::Locker * fix: enter js env when resolving promise
This commit is contained in:
parent
52e257668d
commit
0881fd6397
11 changed files with 135 additions and 55 deletions
|
@ -245,7 +245,7 @@ const template = [
|
|||
submenu: [
|
||||
{
|
||||
label: 'Learn More',
|
||||
click () { require('electron').shell.openExternal('https://electronjs.org') }
|
||||
click () { require('electron').shell.openExternalSync('https://electronjs.org') }
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ When a majority of affected functions are migrated, this flag will be enabled by
|
|||
|
||||
### Candidate Functions
|
||||
|
||||
- [ ] [app.getFileIcon(path[, options], callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#getFileIcon)
|
||||
- [ ] [app.importCertificate(options, callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#importCertificate)
|
||||
- [ ] [request.write(chunk[, encoding][, callback])](https://github.com/electron/electron/blob/master/docs/api/client-request.md#write)
|
||||
- [ ] [request.end([chunk][, encoding][, callback])](https://github.com/electron/electron/blob/master/docs/api/client-request.md#end)
|
||||
|
@ -41,7 +40,6 @@ When a majority of affected functions are migrated, this flag will be enabled by
|
|||
- [ ] [ses.clearHostResolverCache([callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearHostResolverCache)
|
||||
- [ ] [ses.getBlobData(identifier, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#getBlobData)
|
||||
- [ ] [ses.clearAuthCache(options[, callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearAuthCache)
|
||||
- [ ] [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal)
|
||||
- [ ] [contents.executeJavaScript(code[, userGesture, callback])](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#executeJavaScript)
|
||||
- [ ] [contents.getZoomFactor(callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#getZoomFactor)
|
||||
- [ ] [contents.getZoomLevel(callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#getZoomLevel)
|
||||
|
@ -61,4 +59,6 @@ When a majority of affected functions are migrated, this flag will be enabled by
|
|||
|
||||
- [ ] [win.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/browser-window.md#capturePage)
|
||||
- [ ] [webviewTag.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#capturePage)
|
||||
- [ ] [contents.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#capturePage)
|
||||
- [ ] [contents.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#capturePage)
|
||||
- [ ] [app.getFileIcon(path[, options], callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#getFileIcon)
|
||||
- [ ] [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal)
|
|
@ -34,21 +34,29 @@ Returns `Boolean` - Whether the item was successfully opened.
|
|||
|
||||
Open the given file in the desktop's default manner.
|
||||
|
||||
### `shell.openExternal(url[, options, callback])`
|
||||
### `shell.openExternalSync(url[, options])`
|
||||
|
||||
* `url` String - Max 2081 characters on windows, or the function returns false.
|
||||
* `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_
|
||||
* `callback` Function (optional) _macOS_ - If specified will perform the open asynchronously.
|
||||
* `error` Error
|
||||
|
||||
Returns `Boolean` - Whether an application was available to open the URL.
|
||||
If callback is specified, always returns true.
|
||||
|
||||
Open the given external protocol URL in the desktop's default manner. (For
|
||||
example, mailto: URLs in the user's default mail agent).
|
||||
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.
|
||||
* `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 `Promise<void>`
|
||||
|
||||
Open the given external protocol URL in the desktop's default manner. (For example, mailto: URLs in the user's default mail agent).
|
||||
|
||||
### `shell.moveItemToTrash(fullPath)`
|
||||
|
||||
|
|
|
@ -782,7 +782,7 @@ const webview = document.querySelector('webview')
|
|||
webview.addEventListener('new-window', (e) => {
|
||||
const protocol = require('url').parse(e.url).protocol
|
||||
if (protocol === 'http:' || protocol === 'https:') {
|
||||
shell.openExternal(e.url)
|
||||
shell.openExternalSync(e.url)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue