mirror of
https://github.com/electron/electron.git
synced 2026-02-13 00:25:15 -05:00
* 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
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
// Verifies that Electron cannot play a video that uses proprietary codecs
|
|
//
|
|
// This application should be run with the ffmpeg that does not include
|
|
// proprietary codecs to ensure Electron uses it instead of the version
|
|
// that does include proprietary codecs.
|
|
|
|
const { app, BrowserWindow, ipcMain } = require('electron')
|
|
const path = require('path')
|
|
|
|
const MEDIA_ERR_SRC_NOT_SUPPORTED = 4
|
|
const FIVE_MINUTES = 5 * 60 * 1000
|
|
|
|
let window
|
|
|
|
app.whenReady().then(() => {
|
|
window = new BrowserWindow({
|
|
show: false,
|
|
webPreferences: {
|
|
nodeIntegration: true
|
|
}
|
|
})
|
|
|
|
window.webContents.on('crashed', (event, killed) => {
|
|
console.log(`WebContents crashed (killed=${killed})`)
|
|
app.exit(1)
|
|
})
|
|
|
|
window.loadFile(path.resolve(__dirname, 'test.asar', 'video.asar', 'index.html'))
|
|
|
|
ipcMain.on('asar-video', (event, message, error) => {
|
|
if (message === 'ended') {
|
|
console.log('Video played, proprietary codecs are included')
|
|
app.exit(1)
|
|
return
|
|
}
|
|
|
|
if (message === 'error' && error === MEDIA_ERR_SRC_NOT_SUPPORTED) {
|
|
app.exit(0)
|
|
return
|
|
}
|
|
|
|
console.log(`Unexpected response from page: ${message} ${error}`)
|
|
app.exit(1)
|
|
})
|
|
|
|
setTimeout(() => {
|
|
console.log('No IPC message after 5 minutes')
|
|
app.exit(1)
|
|
}, FIVE_MINUTES)
|
|
})
|