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:
Charles Kerr 2020-02-03 16:43:22 -06:00 committed by GitHub
parent 7a3862a1c6
commit c83f836faf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 111 additions and 109 deletions

View file

@ -1,6 +1,6 @@
const { app } = require('electron')
app.on('ready', () => {
app.whenReady().then(() => {
const payload = {
hasSwitch: app.commandLine.hasSwitch('foobar'),
getSwitchValue: app.commandLine.getSwitchValue('foobar')

View file

@ -1,6 +1,6 @@
const { app, session } = require('electron')
app.on('ready', async function () {
app.whenReady().then(async function () {
const url = 'http://foo.bar'
const persistentSession = session.fromPartition('persist:ence-test')
const name = 'test'

View file

@ -18,7 +18,7 @@ try {
Menu.setApplicationMenu(null)
}
app.on('ready', () => {
app.whenReady().then(() => {
setImmediate(() => {
try {
output(Menu.getApplicationMenu() === expectedMenu)

View file

@ -8,7 +8,7 @@ function createWindow (id) {
windows.push(window)
}
app.once('ready', () => {
app.whenReady().then(() => {
for (let i = 1; i <= 5; i++) {
createWindow(i)
}

View file

@ -2,7 +2,7 @@ const { app } = require('electron')
app.commandLine.appendSwitch('--disable-software-rasterizer')
app.on('ready', () => {
app.whenReady().then(() => {
const infoType = process.argv.pop()
app.getGPUInfo(infoType).then(
(gpuInfo) => {

View file

@ -1,5 +1,5 @@
const { app, webContents } = require('electron')
app.on('ready', function () {
app.whenReady().then(function () {
webContents.create({})
app.quit()

View file

@ -1,6 +1,6 @@
const { app } = require('electron')
app.on('ready', () => {
app.whenReady().then(() => {
process.stdout.write(app.getLocale())
process.stdout.end()

View file

@ -12,7 +12,7 @@ if (process.argv.includes('--app-enable-sandbox')) {
let currentWindowSandboxed = false
app.once('ready', () => {
app.whenReady().then(() => {
function testWindow (isSandboxed, callback) {
currentWindowSandboxed = isSandboxed
const currentWindow = new BrowserWindow({

View file

@ -1,6 +1,6 @@
const { app } = require('electron')
app.on('ready', function () {
app.whenReady().then(function () {
// This setImmediate call gets the spec passing on Linux
setImmediate(function () {
app.exit(123)

View file

@ -7,7 +7,7 @@ process.on('uncaughtException', () => {
app.exit(1)
})
app.once('ready', () => {
app.whenReady().then(() => {
const lastArg = process.argv[process.argv.length - 1]
const client = net.connect(socketPath)
client.once('connect', () => {

View file

@ -1,6 +1,6 @@
const { app } = require('electron')
app.once('ready', () => {
app.whenReady().then(() => {
console.log('started') // ping parent
})

View file

@ -14,7 +14,7 @@ app.on('quit', () => {
process.stdout.end()
})
app.on('ready', () => {
app.whenReady().then(() => {
const win = new BrowserWindow()
win.close()
})