From 8bd07af5e579da36140191fbea59f561964fbda3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 16:22:16 -0800 Subject: [PATCH 1/5] Correct typo in comment --- atom/browser/lib/chrome-extension.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/lib/chrome-extension.js b/atom/browser/lib/chrome-extension.js index fbb537d052c1..eaed9b655a6e 100644 --- a/atom/browser/lib/chrome-extension.js +++ b/atom/browser/lib/chrome-extension.js @@ -70,7 +70,7 @@ app.once('ready', function() { var BrowserWindow, chromeExtensionHandler, i, init, len, protocol, srcDirectory; protocol = electron.protocol, BrowserWindow = electron.BrowserWindow; - // Load persistented extensions. + // Load persisted extensions. loadedExtensionsPath = path.join(app.getPath('userData'), 'DevTools Extensions'); try { loadedExtensions = JSON.parse(fs.readFileSync(loadedExtensionsPath)); From 5714ae0b73c722d2a57bbac182d671384b705314 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 17:08:46 -0800 Subject: [PATCH 2/5] Add failing spec for dev tools extensions file --- spec/api-browser-window-spec.js | 17 +++++++++++++++++ .../devtools-extensions/foo/manifest.json | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 spec/fixtures/devtools-extensions/foo/manifest.json diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index fc8d3523c8fb..328325a376a1 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -8,6 +8,7 @@ const os = require('os'); const remote = require('electron').remote; const screen = require('electron').screen; +const app = remote.require('electron').app; const ipcMain = remote.require('electron').ipcMain; const BrowserWindow = remote.require('electron').BrowserWindow; @@ -618,4 +619,20 @@ describe('browser-window module', function() { }); }); }); + + describe('dev tool extensions', function () { + it('serializes the registered extensions on quit', function () { + var extensionName = 'foo' + var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName); + var serializedPath = path.join(app.getPath('userData'), 'DevTools Extensions'); + + BrowserWindow.addDevToolsExtension(extensionPath); + app.emit('will-quit'); + assert.deepEqual(JSON.parse(fs.readFileSync(serializedPath)), [extensionPath]); + + BrowserWindow.removeDevToolsExtension(extensionName); + app.emit('will-quit'); + assert.equal(fs.existsSync(serializedPath), false); + }) + }) }); diff --git a/spec/fixtures/devtools-extensions/foo/manifest.json b/spec/fixtures/devtools-extensions/foo/manifest.json new file mode 100644 index 000000000000..bde99de9287a --- /dev/null +++ b/spec/fixtures/devtools-extensions/foo/manifest.json @@ -0,0 +1,3 @@ +{ + "name": "foo" +} From 6252511b7fa5505ba4f47dfad9ff16f26fe0c5e0 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 17:12:09 -0800 Subject: [PATCH 3/5] Delete extensions file when there are no loaded extensions --- atom/browser/lib/chrome-extension.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/atom/browser/lib/chrome-extension.js b/atom/browser/lib/chrome-extension.js index eaed9b655a6e..e396989bcf38 100644 --- a/atom/browser/lib/chrome-extension.js +++ b/atom/browser/lib/chrome-extension.js @@ -54,12 +54,16 @@ app.on('will-quit', function() { loadedExtensions = Object.keys(extensionInfoMap).map(function(key) { return extensionInfoMap[key].srcDirectory; }); - try { - fs.mkdirSync(path.dirname(loadedExtensionsPath)); - } catch (error) { - // Ignore error + if (loadedExtensions.length > 0) { + try { + fs.mkdirSync(path.dirname(loadedExtensionsPath)); + } catch (error) { + // Ignore error + } + return fs.writeFileSync(loadedExtensionsPath, JSON.stringify(loadedExtensions)); + } else { + fs.unlinkSync(loadedExtensionsPath); } - return fs.writeFileSync(loadedExtensionsPath, JSON.stringify(loadedExtensions)); } catch (error) { // Ignore error } From adfa4844d1b1849b1b6ea7f2839fc037a5aba020 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 17:15:28 -0800 Subject: [PATCH 4/5] Don't return anything from will-quit handler --- atom/browser/lib/chrome-extension.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/lib/chrome-extension.js b/atom/browser/lib/chrome-extension.js index e396989bcf38..fcbb8c7f15fd 100644 --- a/atom/browser/lib/chrome-extension.js +++ b/atom/browser/lib/chrome-extension.js @@ -60,7 +60,7 @@ app.on('will-quit', function() { } catch (error) { // Ignore error } - return fs.writeFileSync(loadedExtensionsPath, JSON.stringify(loadedExtensions)); + fs.writeFileSync(loadedExtensionsPath, JSON.stringify(loadedExtensions)); } else { fs.unlinkSync(loadedExtensionsPath); } From 00261a5571d71d77850cd268e8ae8890716924bd Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 17:17:11 -0800 Subject: [PATCH 5/5] Remove lint warnings --- spec/api-browser-window-spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 328325a376a1..a7d58d7feb87 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -622,7 +622,7 @@ describe('browser-window module', function() { describe('dev tool extensions', function () { it('serializes the registered extensions on quit', function () { - var extensionName = 'foo' + var extensionName = 'foo'; var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName); var serializedPath = path.join(app.getPath('userData'), 'DevTools Extensions'); @@ -633,6 +633,6 @@ describe('browser-window module', function() { BrowserWindow.removeDevToolsExtension(extensionName); app.emit('will-quit'); assert.equal(fs.existsSync(serializedPath), false); - }) - }) + }); + }); });