Share logic for opening external links
This commit is contained in:
parent
dc3dd4459a
commit
ca1eb70250
|
@ -0,0 +1,25 @@
|
|||
const { shell } = require('electron');
|
||||
const url = require('url');
|
||||
|
||||
|
||||
const protocolRegex = /^https?:/i;
|
||||
|
||||
/**
|
||||
* Opens the given link in an external browser.
|
||||
*
|
||||
* @param {string} link - The link (URL) that should be opened in the external browser.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function openExternalLink(link) {
|
||||
let u;
|
||||
|
||||
try {
|
||||
u = url.parse(link);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (protocolRegex.test(u.protocol)) {
|
||||
shell.openExternal(link);
|
||||
}
|
||||
}
|
|
@ -1,31 +1,9 @@
|
|||
const createElectronStorage = require('redux-persist-electron-storage');
|
||||
const { ipcRenderer, shell, remote } = require('electron');
|
||||
const { ipcRenderer, remote } = require('electron');
|
||||
const os = require('os');
|
||||
const url = require('url');
|
||||
|
||||
const jitsiMeetElectronUtils = require('jitsi-meet-electron-utils');
|
||||
const { openExternalLink } = require('../features/utils/openExternalLink');
|
||||
|
||||
const protocolRegex = /^https?:/i;
|
||||
|
||||
/**
|
||||
* Opens the given link in an external browser.
|
||||
*
|
||||
* @param {string} link - The link (URL) that should be opened in the external browser.
|
||||
* @returns {void}
|
||||
*/
|
||||
function openExternalLink(link) {
|
||||
let u;
|
||||
|
||||
try {
|
||||
u = url.parse(link);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (protocolRegex.test(u.protocol)) {
|
||||
shell.openExternal(link);
|
||||
}
|
||||
}
|
||||
|
||||
const whitelistedIpcChannels = [ 'protocol-data-msg', 'renderer-ready' ];
|
||||
|
||||
|
@ -34,7 +12,6 @@ window.jitsiNodeAPI = {
|
|||
osUserInfo: os.userInfo,
|
||||
openExternalLink,
|
||||
jitsiMeetElectronUtils,
|
||||
shellOpenExternal: shell.openExternal,
|
||||
getLocale: remote.app.getLocale,
|
||||
ipc: {
|
||||
on: (channel, listener) => {
|
||||
|
|
6
main.js
6
main.js
|
@ -4,8 +4,7 @@ const {
|
|||
BrowserWindow,
|
||||
Menu,
|
||||
app,
|
||||
ipcMain,
|
||||
shell
|
||||
ipcMain
|
||||
} = require('electron');
|
||||
const contextMenu = require('electron-context-menu');
|
||||
const debug = require('electron-debug');
|
||||
|
@ -22,6 +21,7 @@ const {
|
|||
const path = require('path');
|
||||
const URL = require('url');
|
||||
const config = require('./app/features/config');
|
||||
const { openExternalLink } = require('./app/features/utils/openExternalLink');
|
||||
|
||||
const showDevTools = Boolean(process.env.SHOW_DEV_TOOLS) || (process.argv.indexOf('--show-dev-tools') > -1);
|
||||
|
||||
|
@ -211,7 +211,7 @@ function createJitsiMeetWindow() {
|
|||
|
||||
if (!target || target === 'browser') {
|
||||
event.preventDefault();
|
||||
shell.openExternal(url);
|
||||
openExternalLink(url);
|
||||
}
|
||||
});
|
||||
mainWindow.on('closed', () => {
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
"validate": "npm ls",
|
||||
"watch": "webpack --config ./webpack.renderer.js --mode development --watch --watch-poll"
|
||||
},
|
||||
"engines" : {
|
||||
"node" : ">=12.0.0"
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"build": {
|
||||
"appId": "org.jitsi.jitsi-meet",
|
||||
|
|
Loading…
Reference in New Issue