2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-23 02:28:55 +00:00

add "copy link location" and "--internal-urls <regex>" features (#230)

* add arg to specify pattern for urls to be considered internal

* add 'copy link location' to context menu

* fix lint
This commit is contained in:
Lex Neva 2016-08-06 14:03:53 -04:00 committed by Jia Hao
parent 48f0872ee5
commit 9243f6689f
6 changed files with 25 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import {Menu, ipcMain, shell, BrowserWindow} from 'electron';
import {Menu, ipcMain, shell, clipboard, BrowserWindow} from 'electron';
function initContextMenu(mainWindow) {
ipcMain.on('contextMenuOpened', (event, targetHref) => {
@ -20,6 +20,18 @@ function initContextMenu(mainWindow) {
return;
}
mainWindow.useDefaultWindowBehaviour = true;
mainWindow.webContents.send('contextMenuClosed');
}
},
{
label: 'Copy link location',
click: () => {
if (targetHref) {
clipboard.writeText(targetHref);
return;
}
mainWindow.useDefaultWindowBehaviour = true;
mainWindow.webContents.send('contextMenuClosed');
}

View File

@ -159,7 +159,7 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
return;
}
if (linkIsInternal(options.targetUrl, urlToGo)) {
if (linkIsInternal(options.targetUrl, urlToGo, options.internalUrls)) {
return;
}
event.preventDefault();

View File

@ -17,7 +17,12 @@ function isWindows() {
return os.platform() === 'win32';
}
function linkIsInternal(currentUrl, newUrl) {
function linkIsInternal(currentUrl, newUrl, internalUrlRegex) {
if (internalUrlRegex) {
var regex = RegExp(internalUrlRegex);
return regex.test(newUrl);
}
var currentDomain = wurl('domain', currentUrl);
var newDomain = wurl('domain', newUrl);
return currentDomain === newDomain;

View File

@ -115,7 +115,8 @@ function selectAppArgs(options) {
maximize: options.maximize,
disableContextMenu: options.disableContextMenu,
disableDevTools: options.disableDevTools,
zoom: options.zoom
zoom: options.zoom,
internalUrls: options.internalUrls
};
}

View File

@ -51,6 +51,7 @@ if (require.main === module) {
.option('--disable-context-menu', 'disable the context menu')
.option('--disable-dev-tools', 'disable developer tools')
.option('--zoom <value>', 'default zoom factor to use when the app is opened, defaults to 1.0', parseFloat)
.option('--internal-urls <value>', 'regular expression of URLs to consider "internal"; all other URLs will be opened in an external browser. (default: URLs on same second-level domain as app)')
.parse(process.argv);
if (!process.argv.slice(2).length) {

View File

@ -66,7 +66,8 @@ function optionsFactory(inpOptions, callback) {
disableDevTools: inpOptions.disableDevTools,
// workaround for electron-packager#375
tmpdir: false,
zoom: inpOptions.zoom || 1.0
zoom: inpOptions.zoom || 1.0,
internalUrls: inpOptions.internalUrls || null
};
if (options.verbose) {