refactor: prefer using app.whenReady() (#21972)
* docs: add references to app.whenReady() in isReady * refactor: prefer app.whenReady() In the docs, specs, and lib, replace instances of `app.once('ready')` (seen occasionally) and `app.on('ready')` (extremely common) with `app.whenReady()`. It's better to encourage users to use whenReady(): 1. it handles the edge case of registering for 'ready' after it's fired 2. it avoids the minor wart of leaving an active listener alive for an event that wll never fire again
This commit is contained in:
parent
7a3862a1c6
commit
c83f836faf
78 changed files with 111 additions and 109 deletions
|
@ -34,10 +34,11 @@ Returns:
|
|||
|
||||
* `launchInfo` unknown _macOS_
|
||||
|
||||
Emitted when Electron has finished initializing. On macOS, `launchInfo` holds
|
||||
the `userInfo` of the `NSUserNotification` that was used to open the application,
|
||||
if it was launched from Notification Center. You can call `app.isReady()` to
|
||||
check if this event has already fired.
|
||||
Emitted once, when Electron has finished initializing. On macOS, `launchInfo`
|
||||
holds the `userInfo` of the `NSUserNotification` that was used to open the
|
||||
application, if it was launched from Notification Center. You can also call
|
||||
`app.isReady()` to check if this event has already fired and `app.whenReady()`
|
||||
to get a Promise that is fulfilled when Electron is initialized.
|
||||
|
||||
### Event: 'window-all-closed'
|
||||
|
||||
|
@ -545,6 +546,7 @@ app.exit(0)
|
|||
### `app.isReady()`
|
||||
|
||||
Returns `Boolean` - `true` if Electron has finished initializing, `false` otherwise.
|
||||
See also `app.whenReady()`.
|
||||
|
||||
### `app.whenReady()`
|
||||
|
||||
|
@ -935,7 +937,7 @@ if (!gotTheLock) {
|
|||
})
|
||||
|
||||
// Create myWindow, load the rest of the app, etc...
|
||||
app.on('ready', () => {
|
||||
app.whenReady().then(() => {
|
||||
})
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue