From cca80cd99259517a56206cccb76e4f6a712c38e8 Mon Sep 17 00:00:00 2001 From: Mukunda Modell Date: Sun, 5 Feb 2017 00:53:57 -0600 Subject: [PATCH] dev toools: separate shortcut for electron and for web content --- electron-main.js | 26 +++++++++++++++++++------- electron-start.html | 4 ++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/electron-main.js b/electron-main.js index 92b2dd6..36ef9dc 100755 --- a/electron-main.js +++ b/electron-main.js @@ -9,7 +9,6 @@ const Menu = require('electron').Menu; // Node fs module const fs = require("fs"); - var template; template = [ @@ -76,7 +75,20 @@ } }, { - label: 'Toggle Developer Tools', + label: 'Electron Developer Tools', + accelerator: (function() { + if (process.platform == 'darwin') + return 'Alt+Command+E'; + else + return 'Ctrl+Shift+E'; + })(), + click: function(item, focusedWindow) { + if (focusedWindow) + focusedWindow.toggleDevTools(); + } + }, + { + label: 'Web Developer Tools', accelerator: (function() { if (process.platform == 'darwin') return 'Alt+Command+I'; @@ -84,10 +96,11 @@ return 'Ctrl+Shift+I'; })(), click: function(item, focusedWindow) { - if (focusedWindow) - focusedWindow.toggleDevTools(); + if ( focusedWindow ) { + focusedWindow.webContents.send( 'openDevTools' ); + } } - }, + } ] }, { @@ -183,7 +196,6 @@ }); app.on('ready', function() { - var menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); const initPath = __dirname + "/init.json"; @@ -197,7 +209,7 @@ console.log('Unable to read init.json: ', e); } const bounds = (data && data.bounds) ? data.bounds : {width: 1280, height:800 }; - var bwdata = {width: bounds.width, height: bounds.height, 'min-width': 1024, 'min-height': 600, 'autoHideMenuBar': true, 'web-security': true, 'java': false, 'accept-first-mouse': true, defaultEncoding: 'UTF-8', 'icon':'file://'+__dirname + '/assets/img/favicon.png'} + var bwdata = {width: bounds.width, height: bounds.height, 'min-width': 1024, 'min-height': 600, 'autoHideMenuBar': true, 'web-security': true, 'java': false, 'accept-first-mouse': true, defaultEncoding: 'UTF-8', 'icon':'file://'+__dirname + '/assets/img/favicon.png'}; // Remembe window position if (data && data.bounds.x && data.bounds.y) { bwdata.x = data.bounds.x; diff --git a/electron-start.html b/electron-start.html index 028a7a9..2844bfa 100644 --- a/electron-start.html +++ b/electron-start.html @@ -24,6 +24,10 @@ onload = function() { webview.addEventListener("new-window", handlenewwindow); webview.addEventListener("page-title-set", handletitleset); + ipc.on('openDevTools', function() { + setTimeout(function() { webview.openDevTools(); }, 0 ); + }); + ipc.on('browser-window-focus', function() { setTimeout(function() { webview.focus(); }, 0); setTimeout(function() { webview.executeJavaScript("document.getElementById(\"sendMessage\").focus();") }, 0);