Background pages and content script should be loaded on startup
This commit is contained in:
parent
e76c36a9a8
commit
599d3c147b
1 changed files with 18 additions and 19 deletions
|
@ -149,10 +149,6 @@ const manifestToExtensionInfo = function (manifest) {
|
||||||
const loadDevToolsExtensions = function (win, manifests) {
|
const loadDevToolsExtensions = function (win, manifests) {
|
||||||
if (!win.devToolsWebContents) return
|
if (!win.devToolsWebContents) return
|
||||||
|
|
||||||
for (const manifest of manifests) {
|
|
||||||
startBackgroundPages(manifest)
|
|
||||||
injectContentScripts(manifest)
|
|
||||||
}
|
|
||||||
const extensionInfoArray = manifests.map(manifestToExtensionInfo)
|
const extensionInfoArray = manifests.map(manifestToExtensionInfo)
|
||||||
win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`)
|
win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`)
|
||||||
}
|
}
|
||||||
|
@ -182,20 +178,6 @@ app.on('will-quit', function () {
|
||||||
|
|
||||||
// We can not use protocol or BrowserWindow until app is ready.
|
// We can not use protocol or BrowserWindow until app is ready.
|
||||||
app.once('ready', function () {
|
app.once('ready', function () {
|
||||||
// Load persisted extensions.
|
|
||||||
loadedExtensionsPath = path.join(app.getPath('userData'), 'DevTools Extensions')
|
|
||||||
try {
|
|
||||||
const loadedExtensions = JSON.parse(fs.readFileSync(loadedExtensionsPath))
|
|
||||||
if (Array.isArray(loadedExtensions)) {
|
|
||||||
// Preheat the manifest cache.
|
|
||||||
for (const srcDirectory of loadedExtensions) {
|
|
||||||
getManifestFromPath(srcDirectory)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
// Ignore error
|
|
||||||
}
|
|
||||||
|
|
||||||
// The chrome-extension: can map a extension URL request to real file path.
|
// The chrome-extension: can map a extension URL request to real file path.
|
||||||
const chromeExtensionHandler = function (request, callback) {
|
const chromeExtensionHandler = function (request, callback) {
|
||||||
const parsed = url.parse(request.url)
|
const parsed = url.parse(request.url)
|
||||||
|
@ -227,6 +209,23 @@ app.once('ready', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Load persisted extensions.
|
||||||
|
loadedExtensionsPath = path.join(app.getPath('userData'), 'DevTools Extensions')
|
||||||
|
try {
|
||||||
|
const loadedExtensions = JSON.parse(fs.readFileSync(loadedExtensionsPath))
|
||||||
|
if (Array.isArray(loadedExtensions)) {
|
||||||
|
for (const srcDirectory of loadedExtensions) {
|
||||||
|
// Start background pages and set content scripts.
|
||||||
|
const manifest = getManifestFromPath(srcDirectory)
|
||||||
|
startBackgroundPages(manifest)
|
||||||
|
injectContentScripts(manifest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Ignore error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The public API to add/remove extensions.
|
||||||
BrowserWindow.addDevToolsExtension = function (srcDirectory) {
|
BrowserWindow.addDevToolsExtension = function (srcDirectory) {
|
||||||
const manifest = getManifestFromPath(srcDirectory)
|
const manifest = getManifestFromPath(srcDirectory)
|
||||||
if (manifest) {
|
if (manifest) {
|
||||||
|
@ -245,7 +244,7 @@ app.once('ready', function () {
|
||||||
delete manifestMap[name]
|
delete manifestMap[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load persisted extensions when devtools is opened.
|
// Load extensions automatically when devtools is opened.
|
||||||
const init = BrowserWindow.prototype._init
|
const init = BrowserWindow.prototype._init
|
||||||
BrowserWindow.prototype._init = function () {
|
BrowserWindow.prototype._init = function () {
|
||||||
init.call(this)
|
init.call(this)
|
||||||
|
|
Loading…
Reference in a new issue