@@ -48,6 +48,19 @@ function inspectElements() {
4848 }
4949}
5050
51+ const addExtensionIfInstalled = ( name , getPath ) => {
52+ const isExtensionInstalled = name => {
53+ return BrowserWindow . getDevToolsExtensions &&
54+ { } . hasOwnProperty . call ( BrowserWindow . getDevToolsExtensions ( ) , name ) ;
55+ } ;
56+
57+ try {
58+ if ( ! isExtensionInstalled ( name ) ) {
59+ BrowserWindow . addDevToolsExtension ( getPath ( name ) ) ;
60+ }
61+ } catch ( err ) { }
62+ } ;
63+
5164module . exports = opts => {
5265 opts = Object . assign ( {
5366 enabled : null ,
@@ -65,15 +78,10 @@ module.exports = opts => {
6578 } ) ;
6679
6780 app . on ( 'ready' , ( ) => {
68- // Activate devtron for the user if they have it installed and it's not already added
69- try {
70- const devtronAlreadyAdded = BrowserWindow . getDevToolsExtensions &&
71- { } . hasOwnProperty . call ( BrowserWindow . getDevToolsExtensions ( ) , 'devtron' ) ;
72-
73- if ( ! devtronAlreadyAdded ) {
74- BrowserWindow . addDevToolsExtension ( require ( 'devtron' ) . path ) ;
75- }
76- } catch ( err ) { }
81+ addExtensionIfInstalled ( 'devtron' , name => require ( name ) . path ) ;
82+ // TODO: Use this when https://github.com/firejune/electron-react-devtools/pull/6 is out
83+ // addExtensionIfInstalled('electron-react-devtools', name => require(name).path);
84+ addExtensionIfInstalled ( 'electron-react-devtools' , name => require ( 'path' ) . dirname ( require . resolve ( name ) ) ) ;
7785
7886 localShortcut . register ( 'CmdOrCtrl+Shift+C' , inspectElements ) ;
7987 localShortcut . register ( isMacOS ? 'Cmd+Alt+I' : 'Ctrl+Shift+I' , devTools ) ;
0 commit comments