2016-08-06 20:03:53 +02:00
|
|
|
import {Menu, ipcMain, shell, clipboard, BrowserWindow} from 'electron';
|
2016-01-25 08:56:33 +01:00
|
|
|
|
2016-01-28 04:47:40 +01:00
|
|
|
function initContextMenu(mainWindow) {
|
2016-01-29 15:04:41 +01:00
|
|
|
ipcMain.on('contextMenuOpened', (event, targetHref) => {
|
2016-01-25 08:56:33 +01:00
|
|
|
const contextMenuTemplate = [
|
|
|
|
{
|
2017-04-08 04:28:35 +02:00
|
|
|
label: 'Open with default browser',
|
2016-01-29 15:04:41 +01:00
|
|
|
click: () => {
|
2016-01-25 09:49:11 +01:00
|
|
|
if (targetHref) {
|
|
|
|
shell.openExternal(targetHref);
|
2016-01-25 08:56:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Open in new window',
|
2016-01-29 15:04:41 +01:00
|
|
|
click: () => {
|
2016-01-25 09:49:11 +01:00
|
|
|
if (targetHref) {
|
|
|
|
new BrowserWindow().loadURL(targetHref);
|
2016-01-25 08:56:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-01-25 09:49:11 +01:00
|
|
|
|
2016-08-06 20:03:53 +02:00
|
|
|
mainWindow.useDefaultWindowBehaviour = true;
|
|
|
|
mainWindow.webContents.send('contextMenuClosed');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Copy link location',
|
|
|
|
click: () => {
|
|
|
|
if (targetHref) {
|
|
|
|
clipboard.writeText(targetHref);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-25 09:49:11 +01:00
|
|
|
mainWindow.useDefaultWindowBehaviour = true;
|
|
|
|
mainWindow.webContents.send('contextMenuClosed');
|
2016-01-25 08:56:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const contextMenu = Menu.buildFromTemplate(contextMenuTemplate);
|
|
|
|
contextMenu.popup(mainWindow);
|
|
|
|
mainWindow.contextMenuOpen = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initContextMenu;
|