c83f836faf
* 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
37 lines
1.7 KiB
JavaScript
37 lines
1.7 KiB
JavaScript
'use strict'
|
|
|
|
// This is a temporary shim to aid in transition from the old
|
|
// BrowserWindow-based extensions stuff to the new native-backed extensions
|
|
// API.
|
|
|
|
if (!process.electronBinding('features').isExtensionsEnabled()) {
|
|
throw new Error('Attempted to load JS chrome-extension shim without //extensions support enabled')
|
|
}
|
|
|
|
const { app, session, BrowserWindow, deprecate } = require('electron')
|
|
|
|
app.whenReady().then(function () {
|
|
const addExtension = function (srcDirectory) {
|
|
return session.defaultSession.loadExtension(srcDirectory)
|
|
}
|
|
|
|
const removeExtension = function (name) {
|
|
const extension = session.defaultSession.getAllExtensions().find(e => e.name === name)
|
|
if (extension) { session.defaultSession.removeExtension(extension.id) }
|
|
}
|
|
|
|
const getExtensions = function () {
|
|
const extensions = {}
|
|
session.defaultSession.getAllExtensions().forEach(e => {
|
|
extensions[e.name] = e
|
|
})
|
|
return extensions
|
|
}
|
|
|
|
BrowserWindow.addExtension = deprecate.moveAPI(addExtension, 'BrowserWindow.addExtension', 'session.loadExtension')
|
|
BrowserWindow.removeExtension = deprecate.moveAPI(removeExtension, 'BrowserWindow.removeExtension', 'session.removeExtension')
|
|
BrowserWindow.getExtensions = deprecate.moveAPI(getExtensions, 'BrowserWindow.getExtensions', 'session.getAllExtensions')
|
|
BrowserWindow.addDevToolsExtension = deprecate.moveAPI(addExtension, 'BrowserWindow.addDevToolsExtension', 'session.loadExtension')
|
|
BrowserWindow.removeDevToolsExtension = deprecate.moveAPI(removeExtension, 'BrowserWindow.removeDevToolsExtension', 'session.removeExtension')
|
|
BrowserWindow.getDevToolsExtensions = deprecate.moveAPI(getExtensions, 'BrowserWindow.getDevToolsExtensions', 'session.getAllExtensions')
|
|
})
|