mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2025-01-03 06:10:20 +00:00
parent
74bc2d4188
commit
10fb19b377
@ -1,9 +1,13 @@
|
|||||||
import { BrowserWindow, ContextMenuParams } from 'electron';
|
import {
|
||||||
|
BrowserWindow,
|
||||||
|
ContextMenuParams,
|
||||||
|
NewWindowWebContentsEvent,
|
||||||
|
} from 'electron';
|
||||||
import contextMenu from 'electron-context-menu';
|
import contextMenu from 'electron-context-menu';
|
||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
import { nativeTabsSupported, openExternal } from '../helpers/helpers';
|
import { nativeTabsSupported, openExternal } from '../helpers/helpers';
|
||||||
import { setupNativefierWindow } from '../helpers/windowEvents';
|
import { setupNativefierWindow } from '../helpers/windowEvents';
|
||||||
import { createNewTab, createNewWindow } from '../helpers/windowHelpers';
|
import { createNewWindow } from '../helpers/windowHelpers';
|
||||||
import {
|
import {
|
||||||
OutputOptions,
|
OutputOptions,
|
||||||
outputOptionsToWindowOptions,
|
outputOptionsToWindowOptions,
|
||||||
@ -43,12 +47,25 @@ export function initContextMenu(
|
|||||||
items.push({
|
items.push({
|
||||||
label: 'Open Link in New Tab',
|
label: 'Open Link in New Tab',
|
||||||
click: () =>
|
click: () =>
|
||||||
createNewTab(
|
// Fire a new window event for a foreground tab
|
||||||
outputOptionsToWindowOptions(options),
|
// Previously we called createNewTab directly, but it had incosistent and buggy behavior
|
||||||
setupNativefierWindow,
|
// as it was mostly designed for running off of events. So this will create a new event
|
||||||
|
// for a foreground-tab for the event handler to grab and take care of instead.
|
||||||
|
(window as BrowserWindow).webContents.emit(
|
||||||
|
// event name
|
||||||
|
'new-window',
|
||||||
|
// event object
|
||||||
|
{
|
||||||
|
// Leave to the default for a NewWindowWebContentsEvent
|
||||||
|
newGuest: undefined,
|
||||||
|
...new Event('new-window'),
|
||||||
|
} as NewWindowWebContentsEvent,
|
||||||
|
// url
|
||||||
params.linkURL,
|
params.linkURL,
|
||||||
true,
|
// frameName
|
||||||
window,
|
window?.webContents.mainFrame.name ?? '',
|
||||||
|
// disposition
|
||||||
|
'foreground-tab',
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,9 @@ export function onNewWindow(
|
|||||||
});
|
});
|
||||||
const preventDefault = (newGuest?: BrowserWindow): void => {
|
const preventDefault = (newGuest?: BrowserWindow): void => {
|
||||||
log.debug('onNewWindow.preventDefault', { newGuest, event });
|
log.debug('onNewWindow.preventDefault', { newGuest, event });
|
||||||
event.preventDefault();
|
if (event.preventDefault) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
if (newGuest) {
|
if (newGuest) {
|
||||||
event.newGuest = newGuest;
|
event.newGuest = newGuest;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user