Merge remote-tracking branch 'origin/dont-write-empty-dev-tools-extensions-file'
This commit is contained in:
commit
7ca09de386
3 changed files with 30 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
fs.writeFileSync(loadedExtensionsPath, JSON.stringify(loadedExtensions));
|
||||
} else {
|
||||
fs.unlinkSync(loadedExtensionsPath);
|
||||
}
|
||||
return fs.writeFileSync(loadedExtensionsPath, JSON.stringify(loadedExtensions));
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
}
|
||||
|
@ -70,7 +74,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));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -686,4 +687,20 @@ describe('browser-window module', function() {
|
|||
}, 'Missing required channel argument');
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
3
spec/fixtures/devtools-extensions/foo/manifest.json
vendored
Normal file
3
spec/fixtures/devtools-extensions/foo/manifest.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "foo"
|
||||
}
|
Loading…
Reference in a new issue