Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug where 'Inspect element' would always inspect the same element. Fixed some typos. #10

Merged
merged 3 commits into from
Jul 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
const electron = require('electron');

let menu = null;
let posX = 0;
let posY = 0;
let elm = null;

function inpectMenuTemplate(pos, elm) {
function inspectMenuTemplate() {
return {
label: 'Inspect element',
click: () => (elm || electron.remote.getCurrentWindow()).inspectElement(pos.x, pos.y)
click: () => (elm || electron.remote.getCurrentWindow()).inspectElement(posX, posY)
};
}

function inpectElementMenu(pos, elm) {
function inspectElementMenu() {
const Menu = process.type === 'renderer' ?
electron.remote.Menu :
electron.Menu;
Expand All @@ -23,7 +26,7 @@ function inpectElementMenu(pos, elm) {
const mnu = new Menu();

mnu.append(new MenuItem(
inpectMenuTemplate(pos, elm)
inspectMenuTemplate()
));

return mnu;
Expand All @@ -37,14 +40,23 @@ function ifInspectable(elm) {

function onContextMenu(e) {
if (menu === null) {
menu = inpectElementMenu({x: e.x, y: e.y}, ifInspectable(e.target));
menu = inspectElementMenu();
}

posX = e.x;
posY = e.y;
elm = ifInspectable(e.target);

e.preventDefault();
menu.popup(electron.remote.getCurrentWindow());
}

exports.middleware = (ctx, next) => {
ctx.menu.push(inpectMenuTemplate(ctx.click, ifInspectable(ctx.elm)));
posX = ctx.click.x;
posY = ctx.click.y;
elm = ifInspectable(ctx.elm);

ctx.menu.push(inspectMenuTemplate());
next();
};

Expand Down