Skip to content

Commit

Permalink
Share logic for opening external links
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Jun 30, 2020
1 parent dc3dd44 commit ca1eb70
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
25 changes: 25 additions & 0 deletions app/features/utils/openExternalLink.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
27 changes: 2 additions & 25 deletions app/preload/preload.js
Original file line number Diff line number Diff line change
@@ -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' ];

Expand All @@ -34,7 +12,6 @@ window.jitsiNodeAPI = {
osUserInfo: os.userInfo,
openExternalLink,
jitsiMeetElectronUtils,
shellOpenExternal: shell.openExternal,
getLocale: remote.app.getLocale,
ipc: {
on: (channel, listener) => {
Expand Down
6 changes: 3 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const {
BrowserWindow,
Menu,
app,
ipcMain,
shell
ipcMain
} = require('electron');
const contextMenu = require('electron-context-menu');
const debug = require('electron-debug');
Expand All @@ -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);

Expand Down Expand Up @@ -211,7 +211,7 @@ function createJitsiMeetWindow() {

if (!target || target === 'browser') {
event.preventDefault();
shell.openExternal(url);
openExternalLink(url);
}
});
mainWindow.on('closed', () => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ca1eb70

Please sign in to comment.