Skip to content

Commit

Permalink
chore: Validate deeplinks protocol set in electron-builder.json (#2654)
Browse files Browse the repository at this point in the history
* use electron-builder information to validate deeplinks

* use product name as video call window name
  • Loading branch information
jeanfbrito authored Apr 26, 2023
1 parent 07cefde commit 1ec9125
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"copyright": "© 2016-2021, Rocket.Chat",
"homepage": "https://rocket.chat",
"license": "MIT",
"goUrlShortener": "go.rocket.chat",
"keywords": [
"rocketchat",
"desktop",
Expand Down
1 change: 1 addition & 0 deletions src/app/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { APP_PATH_SET, APP_VERSION_SET } from '../actions';

export const packageJsonInformation = {
productName: packageJson.productName,
goUrlShortener: packageJson.goUrlShortener,
};

export const electronBuilderJsonInformation = {
Expand Down
17 changes: 11 additions & 6 deletions src/deepLinks/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { URL } from 'url';

import { app, WebContents } from 'electron';

import {
electronBuilderJsonInformation,
packageJsonInformation,
} from '../app/main/app';
import { ServerUrlResolutionStatus } from '../servers/common';
import { resolveServerUrl } from '../servers/main';
import { select, dispatch } from '../store';
Expand All @@ -13,11 +17,12 @@ import { getRootWindow } from '../ui/main/rootWindow';
import { getWebContentsByServerUrl } from '../ui/main/serverView';
import { DEEP_LINKS_SERVER_FOCUSED, DEEP_LINKS_SERVER_ADDED } from './actions';

const isRocketChatUrl = (parsedUrl: URL): boolean =>
parsedUrl.protocol === 'rocketchat:';
const isDefinedProtocol = (parsedUrl: URL): boolean =>
parsedUrl.protocol === `${electronBuilderJsonInformation.protocol}:`;

const isGoRocketChatUrl = (parsedUrl: URL): boolean =>
parsedUrl.protocol === 'https:' && parsedUrl.hostname === 'go.rocket.chat';
const isGoUrlShortener = (parsedUrl: URL): boolean =>
parsedUrl.protocol === 'https:' &&
parsedUrl.hostname === packageJsonInformation.goUrlShortener;

const parseDeepLink = (
input: string
Expand All @@ -35,13 +40,13 @@ const parseDeepLink = (
return null;
}

if (isRocketChatUrl(url)) {
if (isDefinedProtocol(url)) {
const action = url.hostname;
const args = url.searchParams;
return { action, args };
}

if (isGoRocketChatUrl(url)) {
if (isGoUrlShortener(url)) {
const action = url.pathname;
const args = url.searchParams;
return { action, args };
Expand Down
5 changes: 3 additions & 2 deletions src/videoCallWindow/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
systemPreferences,
} from 'electron';

import { packageJsonInformation } from '../app/main/app';
import { handle } from '../ipc/main';
import { getRootWindow } from '../ui/main/rootWindow';

Expand All @@ -29,7 +30,6 @@ export const startVideoCallWindowHandler = (): void => {
);

handle('video-call-window/open-window', async (_event, url) => {
console.log('[Rocket.Chat Desktop] open-internal-video-chat-window', url);
const validUrl = new URL(url);
const allowedProtocols = ['http:', 'https:'];
if (allowedProtocols.includes(validUrl.protocol)) {
Expand Down Expand Up @@ -83,8 +83,9 @@ export const startVideoCallWindowHandler = (): void => {
videoCallWindow.loadFile(
path.join(app.getAppPath(), 'app/video-call-window.html')
);

videoCallWindow.once('ready-to-show', () => {
console.log('[Rocket.Chat Desktop] ready-to-show', url);
videoCallWindow.setTitle(packageJsonInformation.productName);
videoCallWindow.webContents.send('video-call-window/open-url', url);
videoCallWindow.show();
});
Expand Down

0 comments on commit 1ec9125

Please sign in to comment.