Skip to content

Commit

Permalink
Add support for new session extension handling in Electron 9 (#80)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
Erik Bender and sindresorhus authored May 22, 2020
1 parent 29b58de commit 212552f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const {app, BrowserWindow} = require('electron');
const {app, BrowserWindow, session} = require('electron');
const localShortcut = require('electron-localshortcut');
const isDev = require('electron-is-dev');

Expand Down Expand Up @@ -54,13 +54,25 @@ function inspectElements() {

const addExtensionIfInstalled = (name, getPath) => {
const isExtensionInstalled = name => {
// For Electron >=9.
if (session.defaultSession.getAllExtensions) {
return {}.hasOwnProperty.call(session.defaultSession.getAllExtensions(), name);
}

// TODO: Remove this when targeting Electron >=9.
return BrowserWindow.getDevToolsExtensions &&
{}.hasOwnProperty.call(BrowserWindow.getDevToolsExtensions(), name);
};

try {
if (!isExtensionInstalled(name)) {
BrowserWindow.addDevToolsExtension(getPath(name));
// For Electron >=9.
if (session.defaultSession.loadExtension) {
session.defaultSession.loadExtension(getPath(name));
} else {
// TODO: Remove this when targeting Electron >=9.
BrowserWindow.addDevToolsExtension(getPath(name));
}
}
} catch (_) {}
};
Expand Down

0 comments on commit 212552f

Please sign in to comment.