From 212552f525877e2f6dd70b37927e28aa08ac8fbc Mon Sep 17 00:00:00 2001 From: Erik Bender Date: Fri, 22 May 2020 10:36:15 +0200 Subject: [PATCH] Add support for new session extension handling in Electron 9 (#80) Co-authored-by: Sindre Sorhus --- index.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d4f457c..1864c1a 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -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 (_) {} };