Monday, 15 May 2017

Electron right click depending on what's underneath?

I'm trying to build a desktop file explorer using Electron. enter image description here

I have a list of files, and now I want to add a right click (preferable native to the OS) with context specific info, such as:

  • Remove
  • Add to favorites
  • Open with
    • Atom
    • Code
    • Sublime
  • ...

A bit like this: enter image description here

I've managed to add the usual "Inspect Element" from some other questions. But I can't figure out how to customize the menu depending on where the right click was done and get information from that place (like which file in this example).

 mainWindow.webContents.on('context-menu', (e, props) => {
            const {x, y} = props;

            Menu.buildFromTemplate([
                {
                    label: 'Inspect element',
                    click() {
                        mainWindow.inspectElement(x, y);
                    }
                },
                {
                    label: 'Hello :P',
                    click() {
                        console.log("What did I click on?");
                    }
                }
            ]).popup(mainWindow);
        });

Thanks in advance for your help.



via denislexic

No comments:

Post a Comment