Skip to content

Commit

Permalink
[FIX] Preload scripts compatibility (#1140)
Browse files Browse the repository at this point in the history
* Update copyright string

* Make preload scripts support all Rocket.Chat versions up to 1.0.x
  • Loading branch information
tassoevan authored Mar 13, 2019
1 parent f422780 commit cf524f0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Rocket.Chat Native Cross-Platform Desktop Application via Electron.",
"version": "2.16.0-develop",
"author": "Rocket.Chat Support <[email protected]>",
"copyright": "© 2018, Rocket.Chat",
"copyright": "© 2019, Rocket.Chat",
"homepage": "https://rocket.chat",
"license": "MIT",
"main": "app/background.js",
Expand Down
7 changes: 1 addition & 6 deletions src/preload/jitsi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { desktopCapturer, remote } from 'electron';
import url from 'url';
import util from 'util';
import { getSettings } from './rocketChat';
const { app } = remote;


Expand All @@ -15,12 +16,6 @@ const JitsiMeetElectron = {
},
};


const getSettings = () => (
(window.RocketChat && window.RocketChat.settings) ||
(window.require && window.require('/app/settings').settings)
);

const wrapWindowOpen = (defaultWindowOpen) => (href, frameName, features) => {
const settings = getSettings();

Expand Down
6 changes: 1 addition & 5 deletions src/preload/links.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { shell, remote } from 'electron';
import { getSettings } from './rocketChat';


const getSettings = () => (
(window.RocketChat && window.RocketChat.settings) ||
(window.require && window.require('/app/settings').settings)
);

const handleAnchorClick = (event) => {
const a = event.target.closest('a');

Expand Down
72 changes: 72 additions & 0 deletions src/preload/rocketChat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
export function getMeteor() {
if (!window.require) {
return window.Meteor;
}

try {
return window.require('meteor/meteor').Meteor;
} catch (error) {
console.error(error);
return null;
}
}

export function getTracker() {
if (!window.require) {
return window.Tracker;
}

try {
return window.require('meteor/tracker').Tracker;
} catch (error) {
console.error(error);
return null;
}
}

export function getUserPresence() {
if (!window.require) {
return window.UserPresence;
}

try {
return window.require('meteor/konecty:user-presence').UserPresence;
} catch (error) {
console.error(error);
return null;
}
}

export function getSettings() {
if (!window.require) {
return window.RocketChat && window.RocketChat.settings;
}

try {
return window.require('/app/settings').settings;
} catch (_) {
try {
return window.require('meteor/rocketchat:settings').settings;
} catch (error) {
console.error(error);
return null;
}
}
}

export function getGetUserPreference() {
if (!window.require) {
return window.RocketChat && window.RocketChat.getUserPreference;
}

try {
return window.require('/app/utils').getUserPreference;
} catch (_) {
try {
return window.require('meteor/rocketchat:utils').getUserPreference;
} catch (error) {
console.error(error);
return null;
}
}
}
8 changes: 1 addition & 7 deletions src/preload/titleChange.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { ipcRenderer } from 'electron';
import { getMeteor, getTracker, getSettings } from './rocketChat';


const getMeteor = () => window.Meteor || (window.require && window.require('meteor/meteor').Meteor);
const getTracker = () => window.Tracker || (window.require && window.require('meteor/tracker').Tracker);
const getSettings = () => (
(window.RocketChat && window.RocketChat.settings) ||
(window.require && window.require('/app/settings').settings)
);

function handleTitleChange() {
const Meteor = getMeteor();
const Tracker = getTracker();
Expand Down
12 changes: 1 addition & 11 deletions src/preload/userPresence.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { ipcRenderer } from 'electron';
import { getMeteor, getTracker, getGetUserPreference, getUserPresence } from './rocketChat';


let maximumIdleTime = 10 * 1000;
const idleDetectionInterval = 1 * 1000;

const getMeteor = () => window.Meteor || (window.require && window.require('meteor/meteor').Meteor);
const getTracker = () => window.Tracker || (window.require && window.require('meteor/tracker').Tracker);
const getGetUserPreference = () => (
(window.RocketChat && window.RocketChat.getUserPreference) ||
(window.require && window.require('/app/utils').getUserPreference)
);
const getUserPresence = () => (
window.UserPresence ||
(window.require && window.require('meteor/konecty:user-presence').UserPresence)
);

function onChangeUserPresence(isUserPresent) {
const UserPresence = getUserPresence();

Expand Down

0 comments on commit cf524f0

Please sign in to comment.