mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-23 10:38:55 +00:00
Implement support for clicking buttons so that users can control where links open as referenced in #73
This commit is contained in:
parent
949fce5e3c
commit
d8fb87ccb5
@ -10,19 +10,23 @@ function initContextMenu(mainWindow, sendMessage) {
|
|||||||
{
|
{
|
||||||
label: 'Open in default browser',
|
label: 'Open in default browser',
|
||||||
click: function() {
|
click: function() {
|
||||||
if (!targetHref) {
|
if (targetHref) {
|
||||||
|
shell.openExternal(targetHref);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
shell.openExternal(targetHref);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Open in new window',
|
label: 'Open in new window',
|
||||||
click: function() {
|
click: function() {
|
||||||
if (!targetHref) {
|
if (targetHref) {
|
||||||
|
new BrowserWindow().loadURL(targetHref);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new BrowserWindow().loadURL(targetHref);
|
|
||||||
|
mainWindow.useDefaultWindowBehaviour = true;
|
||||||
|
mainWindow.webContents.send('contextMenuClosed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -5,6 +5,7 @@ var helpers = require('./../../helpers/helpers');
|
|||||||
var createMenu = require('./../menu/menu');
|
var createMenu = require('./../menu/menu');
|
||||||
var BrowserWindow = electron.BrowserWindow;
|
var BrowserWindow = electron.BrowserWindow;
|
||||||
var shell = electron.shell;
|
var shell = electron.shell;
|
||||||
|
const ipcMain = electron.ipcMain;
|
||||||
var isOSX = helpers.isOSX;
|
var isOSX = helpers.isOSX;
|
||||||
var linkIsInternal = helpers.linkIsInternal;
|
var linkIsInternal = helpers.linkIsInternal;
|
||||||
|
|
||||||
@ -86,6 +87,11 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.webContents.on('new-window', function(event, urlToGo) {
|
mainWindow.webContents.on('new-window', function(event, urlToGo) {
|
||||||
|
if (mainWindow.useDefaultWindowBehaviour) {
|
||||||
|
mainWindow.useDefaultWindowBehaviour = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (linkIsInternal(options.targetUrl, urlToGo)) {
|
if (linkIsInternal(options.targetUrl, urlToGo)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -111,6 +117,13 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
|
|||||||
return mainWindow;
|
return mainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipcMain.on('cancelNewWindowOverride', () => {
|
||||||
|
const allWindows = BrowserWindow.getAllWindows();
|
||||||
|
allWindows.forEach(window => {
|
||||||
|
window.useDefaultWindowBehaviour = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function maybeHideWindow(window, event) {
|
function maybeHideWindow(window, event) {
|
||||||
if (isOSX()) {
|
if (isOSX()) {
|
||||||
// this is called when exiting from clicking the cross button on the window
|
// this is called when exiting from clicking the cross button on the window
|
||||||
|
@ -17,6 +17,13 @@ document.addEventListener('DOMContentLoaded', function(event) {
|
|||||||
const targetElement = event.srcElement;
|
const targetElement = event.srcElement;
|
||||||
const targetHref = targetElement.href;
|
const targetHref = targetElement.href;
|
||||||
|
|
||||||
|
if (!targetHref) {
|
||||||
|
ipc.once('contextMenuClosed', () => {
|
||||||
|
clickSelector(event.target);
|
||||||
|
ipc.send('cancelNewWindowOverride');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ipc.send('contextMenuOpened', targetHref);
|
ipc.send('contextMenuOpened', targetHref);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user