Skip to content
This repository has been archived by the owner on Mar 27, 2018. It is now read-only.

Commit

Permalink
Merge pull request #19 from sportradar/right-click
Browse files Browse the repository at this point in the history
#6: add right click menu items
  • Loading branch information
kennethaasan authored Mar 10, 2017
2 parents 07868d1 + efd4211 commit b18c4b0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DevelopmentMenuTemplateMenu from './menu/DevelopmentMenuTemplateMenu';
import FileMenu from './menu/FileMenu';
import HelpMenu from './menu/HelpMenu';
import TrayMenu from './menu/TrayMenu';
import HandleRightClick from './menu/RightClick';
import createWindow from './helpers/window';

// Special module holding environment variables which you declared
Expand Down Expand Up @@ -104,6 +105,8 @@ app.on('ready', () => {

mainWindow.webContents.on('will-navigate', handleRedirect);
mainWindow.webContents.on('new-window', handleRedirect);
mainWindow.webContents.on('context-menu', (event, props) =>
HandleRightClick(event, props, mainWindow));
});

app.on('window-all-closed', () => {
Expand Down
35 changes: 35 additions & 0 deletions src/menu/RightClick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { clipboard, Menu } from 'electron';

const HandleRightClick = (event, props, windowContext) => {
const { selectionText, linkURL, linkText } = props;
const menuItems = [];

if (selectionText && selectionText.length > 0) {
menuItems.push({
role: 'copy',
label: 'Copy',
});
}

if (linkURL && linkURL.length > 0) {
menuItems.push({
label: 'Copy link address',
click: () => {
clipboard.writeText(linkURL);
},
});
menuItems.push({
label: 'Copy link text',
click: () => {
clipboard.writeText(linkText);
},
});
}

if (menuItems.length > 0) {
const rightClickMenu = Menu.buildFromTemplate(menuItems);
rightClickMenu.popup(windowContext);
}
};

export default HandleRightClick;

0 comments on commit b18c4b0

Please sign in to comment.