From 0a26075699121f4df874b67230119d8b3f748270 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 9 Jun 2016 10:04:02 -0700 Subject: [PATCH 1/5] Add BrowserWindow.isDevToolsExtensionInstalled API --- lib/browser/chrome-extension.js | 4 ++++ spec/api-browser-window-spec.js | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index ea9dc15f2c71..d3f8aab694e8 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -339,4 +339,8 @@ app.once('ready', function () { delete manifestMap[manifest.extensionId] delete manifestNameMap[name] } + + BrowserWindow.isDevToolsExtensionInstalled = function (name) { + return manifestNameMap.hasOwnProperty(name) + } }) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index a5a1478d6908..d9f50b6195a3 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -838,9 +838,11 @@ describe('browser-window module', function () { beforeEach(function () { BrowserWindow.removeDevToolsExtension('foo') + assert.equal(BrowserWindow.isDevToolsExtensionInstalled('foo'), false) var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo') BrowserWindow.addDevToolsExtension(extensionPath) + assert.equal(BrowserWindow.isDevToolsExtensionInstalled('foo'), true) w.webContents.on('devtools-opened', function () { var showPanelIntevalId = setInterval(function () { From 091682a039724f5e79b7db0d67112b81943e4dc3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 9 Jun 2016 10:05:09 -0700 Subject: [PATCH 2/5] Doc BrowserWindow.isDevToolsExtensionInstalled --- docs/api/browser-window.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 8b850b5c4388..5fb1fbff7ec3 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -396,6 +396,12 @@ Method will also not return if the extension's manifest is missing or incomplete Remove the DevTools extension whose name is `name`. +### `BrowserWindow.isDevToolsExtensionInstalled(name)` + +* `name` String + +Returns `true` if the named DevTools extension is installed, `false` otherwise. + ## Instance Properties Objects created with `new BrowserWindow` have the following properties: From 1f245d5ff6b7c4170696182aa110bf1279ea9169 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 10 Jun 2016 09:24:00 -0700 Subject: [PATCH 3/5] Add getDevToolsExtensions API --- lib/browser/chrome-extension.js | 9 +++++++-- spec/api-browser-window-spec.js | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index d3f8aab694e8..8739c7a0aba3 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -340,7 +340,12 @@ app.once('ready', function () { delete manifestNameMap[name] } - BrowserWindow.isDevToolsExtensionInstalled = function (name) { - return manifestNameMap.hasOwnProperty(name) + BrowserWindow.getDevToolsExtensions = function () { + const extensions = {} + Object.keys(manifestNameMap).forEach(function (name) { + const manifest = manifestNameMap[name] + extensions[name] = {name: manifest.name, version: manifest.version} + }) + return extensions } }) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index d9f50b6195a3..42a9b0887a99 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -838,11 +838,11 @@ describe('browser-window module', function () { beforeEach(function () { BrowserWindow.removeDevToolsExtension('foo') - assert.equal(BrowserWindow.isDevToolsExtensionInstalled('foo'), false) + assert.equal(BrowserWindow.getDevToolsExtensions().hasOwnProperty('foo'), false) var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo') BrowserWindow.addDevToolsExtension(extensionPath) - assert.equal(BrowserWindow.isDevToolsExtensionInstalled('foo'), true) + assert.equal(BrowserWindow.getDevToolsExtensions().hasOwnProperty('foo'), true) w.webContents.on('devtools-opened', function () { var showPanelIntevalId = setInterval(function () { From 2804272c7da987eaf1a8c724c952132d0c2bd002 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 10 Jun 2016 09:29:26 -0700 Subject: [PATCH 4/5] Doc getDevToolsExtensions --- docs/api/browser-window.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 5fb1fbff7ec3..2259d765fa37 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -396,11 +396,16 @@ Method will also not return if the extension's manifest is missing or incomplete Remove the DevTools extension whose name is `name`. -### `BrowserWindow.isDevToolsExtensionInstalled(name)` +### `BrowserWindow.getDevToolsExtensions()` -* `name` String +Returns an Object where the keys are the extension names and each value is +an Object containing `name` and `version` properties. -Returns `true` if the named DevTools extension is installed, `false` otherwise. +To check if a DevTools extension is installed you can run the following: + +```javascript +let installed = BrowserWindow.getDevToolsExtesion().hasOwnProperty('devtron') +``` ## Instance Properties From f9b7033f43bd4346a24373284d58b4e22c2ab379 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 10 Jun 2016 09:34:34 -0700 Subject: [PATCH 5/5] Fix typo in example --- docs/api/browser-window.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 2259d765fa37..e73ef6cfa188 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -404,7 +404,7 @@ an Object containing `name` and `version` properties. To check if a DevTools extension is installed you can run the following: ```javascript -let installed = BrowserWindow.getDevToolsExtesion().hasOwnProperty('devtron') +let installed = BrowserWindow.getDevToolsExtensions().hasOwnProperty('devtron') ``` ## Instance Properties