Unverified Commit 08eb7b4c authored by Tasso Evangelista's avatar Tasso Evangelista Committed by GitHub

[FIX] Updates preloads scripts to be compatible with Rocket.Chat >0.74.0 (#1099)

* Fix gulp tasks

* Fix i18n error string

* Fix webview initialization bug

* Remove idle time detection

* Fix and isolate title change detection

* Update external links handling

* Test window.reloadServer existence before invoking it

* Update Jitsi preload script
parent fb8394b2
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
"e2e": "xvfb-maybe mocha --require source-map-support/register app/e2e.js" "e2e": "xvfb-maybe mocha --require source-map-support/register app/e2e.js"
}, },
"dependencies": { "dependencies": {
"@paulcbetts/system-idle-time": "^1.0.4",
"electron-updater": "^4.0.6", "electron-updater": "^4.0.6",
"freedesktop-notifications": "^1.4.0", "freedesktop-notifications": "^1.4.0",
"fs-jetpack": "^2.2.0", "fs-jetpack": "^2.2.0",
......
import { app, ipcMain } from 'electron'; import { app, ipcMain } from 'electron';
import querystring from 'querystring'; import querystring from 'querystring';
import url from 'url'; import url from 'url';
import idle from '@paulcbetts/system-idle-time';
import './background/aboutDialog'; import './background/aboutDialog';
import appData from './background/appData'; import appData from './background/appData';
import certificate from './background/certificate'; import certificate from './background/certificate';
...@@ -52,10 +50,6 @@ if (process.platform === 'linux') { ...@@ -52,10 +50,6 @@ if (process.platform === 'linux') {
app.disableHardwareAcceleration(); app.disableHardwareAcceleration();
} }
ipcMain.on('getSystemIdleTime', (event) => {
event.returnValue = idle.getIdleTime();
});
process.on('unhandledRejection', console.error.bind(console)); process.on('unhandledRejection', console.error.bind(console));
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
}, },
"loadDictionaryError": { "loadDictionaryError": {
"title": "Error", "title": "Error",
"message": "Error copying dictionary file" "message": "Error copying dictionary file: {{- message}}"
}, },
"resetAppData": { "resetAppData": {
"title": "Reset app data", "title": "Reset app data",
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
}, },
"loadDictionaryError": { "loadDictionaryError": {
"title": "Erro", "title": "Erro",
"message": "Erro ao copiar arquivo de dicionário" "message": "Erro ao copiar arquivo de dicionário: {{- message}}"
}, },
"resetAppData": { "resetAppData": {
"title": "Limpar dados do aplicativo", "title": "Limpar dados do aplicativo",
......
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import i18n from './i18n';
import setupContextMenuPreload from './preload/contextMenu'; import setupContextMenuPreload from './preload/contextMenu';
import setupEventsPreload from './preload/events'; import setupEventsPreload from './preload/events';
import setupJitsiPreload from './preload/jitsi'; import setupJitsiPreload from './preload/jitsi';
...@@ -6,6 +7,7 @@ import setupLinksPreload from './preload/links'; ...@@ -6,6 +7,7 @@ import setupLinksPreload from './preload/links';
import setupNotificationsPreload from './preload/notifications'; import setupNotificationsPreload from './preload/notifications';
import setupSidebarPreload from './preload/sidebar'; import setupSidebarPreload from './preload/sidebar';
import setupSpellcheckingPreload from './preload/spellchecking'; import setupSpellcheckingPreload from './preload/spellchecking';
import setupTitleChangePreload from './preload/titleChange';
setupContextMenuPreload(); setupContextMenuPreload();
...@@ -15,6 +17,7 @@ setupLinksPreload(); ...@@ -15,6 +17,7 @@ setupLinksPreload();
setupNotificationsPreload(); setupNotificationsPreload();
setupSidebarPreload(); setupSidebarPreload();
setupSpellcheckingPreload(); setupSpellcheckingPreload();
setupTitleChangePreload();
window.reloadServer = () => ipcRenderer.sendToHost('reload-server'); window.reloadServer = () => ipcRenderer.sendToHost('reload-server');
window.i18n = require('./i18n'); window.i18n = i18n;
...@@ -19,8 +19,11 @@ const createSpellCheckingMenuTemplate = async({ ...@@ -19,8 +19,11 @@ const createSpellCheckingMenuTemplate = async({
try { try {
await spellchecking.installDictionaries(filePaths); await spellchecking.installDictionaries(filePaths);
} catch (error) { } catch (error) {
dialog.showErrorBox(i18n.__('dialog.loadDictionaryError.title'), `${ i18n.__('dialog.loadDictionaryError.message') }: ${ name }`);
console.error(error); console.error(error);
dialog.showErrorBox(
i18n.__('dialog.loadDictionaryError.title'),
i18n.__('dialog.loadDictionaryError.message', { message: error.message })
);
} }
}; };
......
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
const handleTitleChange = () => {
const { Meteor, RocketChat, Tracker } = window;
if (!Meteor || !RocketChat || !Tracker) {
return;
}
Meteor.startup(() => {
Tracker.autorun(() => {
const siteName = RocketChat.settings.get('Site_Name');
if (siteName) {
ipcRenderer.sendToHost('title-changed', siteName);
}
});
});
};
const handleUserPresenceChange = () => {
const { Meteor, UserPresence } = window;
if (!Meteor || !UserPresence) {
return;
}
const idleDetectionInterval = 10000;
setInterval(() => {
try {
const idleTime = ipcRenderer.sendSync('getSystemIdleTime');
if (idleTime < idleDetectionInterval) {
UserPresence.setOnline();
}
} catch (e) {
console.error(`Error getting system idle time: ${ e }`);
}
}, idleDetectionInterval);
};
export default () => { export default () => {
document.addEventListener('dragover', (event) => event.preventDefault()); document.addEventListener('dragover', (event) => event.preventDefault());
document.addEventListener('drop', (event) => event.preventDefault()); document.addEventListener('drop', (event) => event.preventDefault());
...@@ -49,9 +9,4 @@ export default () => { ...@@ -49,9 +9,4 @@ export default () => {
for (const eventName of eventsListened) { for (const eventName of eventsListened) {
window.addEventListener(eventName, (event) => ipcRenderer.sendToHost(eventName, event.detail)); window.addEventListener(eventName, (event) => ipcRenderer.sendToHost(eventName, event.detail));
} }
window.addEventListener('load', () => {
handleTitleChange();
handleUserPresenceChange();
});
}; };
import { desktopCapturer } from 'electron'; import { desktopCapturer, remote } from 'electron';
import path from 'path';
import url from 'url'; import url from 'url';
import util from 'util';
const { app } = remote;
const getScreenSources = util.promisify(desktopCapturer.getSources.bind(desktopCapturer));
const JitsiMeetElectron = { const JitsiMeetElectron = {
obtainDesktopStreams(callback, errorCallback, options = {}) { async obtainDesktopStreams(callback, errorCallback, options = {}) {
desktopCapturer.getSources(options, (error, sources) => { try {
if (error) { callback(await getScreenSources(options));
errorCallback(error); } catch (error) {
return; errorCallback(error);
} }
callback(sources);
});
}, },
}; };
const getSettings = () => (
(window.RocketChat && window.RocketChat.settings) ||
(window.require && window.require('meteor/rocketchat:settings').settings)
);
const wrapWindowOpen = (defaultWindowOpen) => (href, frameName, features) => { const wrapWindowOpen = (defaultWindowOpen) => (href, frameName, features) => {
const { RocketChat } = window; const settings = getSettings();
if (RocketChat && url.parse(href).host === RocketChat.settings.get('Jitsi_Domain')) { if (settings && url.parse(href).host === settings.get('Jitsi_Domain')) {
features = [ features = [
features, features,
'nodeIntegration=true', 'nodeIntegration=true',
`preload=${ path.join(__dirname, './preload.js') }`, `preload=${ `${ app.getAppPath() }/app/preload.js` }`,
].filter((x) => Boolean(x)).join(','); ].join(',');
} }
return defaultWindowOpen(href, frameName, features); return defaultWindowOpen.call(window, href, frameName, features);
}; };
...@@ -44,7 +48,6 @@ const pollJitsiIframe = () => { ...@@ -44,7 +48,6 @@ const pollJitsiIframe = () => {
export default () => { export default () => {
window.JitsiMeetElectron = JitsiMeetElectron; window.JitsiMeetElectron = JitsiMeetElectron;
window.open = wrapWindowOpen(window.open); window.open = wrapWindowOpen(window.open);
window.addEventListener('load', () => { window.addEventListener('load', () => {
......
import { shell } from 'electron'; import { shell } from 'electron';
const getSettings = () => (
(window.RocketChat && window.RocketChat.settings) ||
(window.require && window.require('meteor/rocketchat:settings').settings)
);
const handleAnchorClick = (event) => { const handleAnchorClick = (event) => {
const a = event.target.closest('a'); const a = event.target.closest('a');
...@@ -28,8 +33,8 @@ const handleAnchorClick = (event) => { ...@@ -28,8 +33,8 @@ const handleAnchorClick = (event) => {
return; return;
} }
const { Meteor } = window; const settings = getSettings();
const isInsideDomain = Meteor && RegExp(`^${ Meteor.absoluteUrl() }`).test(href); const isInsideDomain = settings && RegExp(`^${ settings.get('Site_Url') }`).test(href);
const isRelative = !/^([a-z]+:)?\/\//.test(href); const isRelative = !/^([a-z]+:)?\/\//.test(href);
if (isInsideDomain || isRelative) { if (isInsideDomain || isRelative) {
return; return;
......
import { ipcRenderer } from 'electron';
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('meteor/rocketchat:settings').settings)
);
function handleTitleChange() {
const Meteor = getMeteor();
const Tracker = getTracker();
const settings = getSettings();
if (!Meteor || !Tracker || !settings) {
return;
}
Meteor.startup(() => {
Tracker.autorun(() => {
const siteName = settings.get('Site_Name');
if (siteName) {
ipcRenderer.sendToHost('title-changed', siteName);
}
});
});
}
export default () => {
window.addEventListener('load', handleTitleChange);
};
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
document.querySelector('.reload-button').addEventListener('click', ({ target }) => { document.querySelector('.reload-button').addEventListener('click', ({ target }) => {
document.querySelector('.reload-button').classList.add('hidden'); document.querySelector('.reload-button').classList.add('hidden');
document.querySelector('.reloading-server').classList.remove('hidden'); document.querySelector('.reloading-server').classList.remove('hidden');
window.reloadServer(); window.reloadServer && window.reloadServer();
}, false); }, false);
let counter = 60; let counter = 60;
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
counter = counter - reloadCounterStepSize; counter = counter - reloadCounterStepSize;
document.querySelector('.reload-button').innerHTML = `${textBefore} (${counter})`; document.querySelector('.reload-button').innerHTML = `${textBefore} (${counter})`;
if (counter <= 0) { if (counter <= 0) {
document.querySelector('.reload-button').click(); window.reloadServer && window.reloadServer();
counter = 60;
} }
}, reloadCounterStepSize * 1000); }, reloadCounterStepSize * 1000);
}); });
......
...@@ -39,9 +39,9 @@ class SideBar extends EventEmitter { ...@@ -39,9 +39,9 @@ class SideBar extends EventEmitter {
this.setLabel(hostUrl, title); this.setLabel(hostUrl, title);
}); });
webview.on('dom-ready', (hostUrl) => { webview.on('dom-ready', (webviewObj, hostUrl) => {
this.setActive(localStorage.getItem(servers.activeKey)); this.setActive(localStorage.getItem(servers.activeKey));
webview.getActive().send('request-sidebar-color'); webviewObj.send('request-sidebar-color');
this.setImage(hostUrl); this.setImage(hostUrl);
if (this.isHidden()) { if (this.isHidden()) {
this.hide(); this.hide();
...@@ -272,8 +272,24 @@ class SideBar extends EventEmitter { ...@@ -272,8 +272,24 @@ class SideBar extends EventEmitter {
localStorage.setItem('sidebar-closed', 'true'); localStorage.setItem('sidebar-closed', 'true');
this.emit('hide'); this.emit('hide');
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
document.querySelectorAll('webview').forEach( Array.from(document.querySelectorAll('webview.ready'))
(webviewObj) => { if (webviewObj.insertCSS) { webviewObj.insertCSS('aside.side-nav{margin-top:15px;overflow:hidden; transition: margin .5s ease-in-out; } .sidebar{padding-top:10px;transition: margin .5s ease-in-out;}'); } }); .forEach((webviewObj) => {
if (!webviewObj.insertCSS) {
return;
}
webviewObj.insertCSS(`
aside.side-nav {
margin-top: 15px;
overflow: hidden;
transition: margin .5s ease-in-out;
}
.sidebar {
padding-top: 10px;
transition: margin .5s ease-in-out;
}
`);
});
} }
} }
...@@ -282,8 +298,25 @@ class SideBar extends EventEmitter { ...@@ -282,8 +298,25 @@ class SideBar extends EventEmitter {
localStorage.setItem('sidebar-closed', 'false'); localStorage.setItem('sidebar-closed', 'false');
this.emit('show'); this.emit('show');
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
document.querySelectorAll('webview').forEach( Array.from(document.querySelectorAll('webview.ready'))
(webviewObj) => { if (webviewObj.insertCSS) { webviewObj.insertCSS('aside.side-nav{margin-top:0; overflow:hidden; transition: margin .5s ease-in-out;} .sidebar{padding-top:0;transition: margin .5s ease-in-out;}'); } }); .forEach((webviewObj) => {
if (!webviewObj.insertCSS) {
return;
}
webviewObj.insertCSS(`
aside.side-nav {
margin-top: 0;
overflow: hidden;
transition: margin .5s ease-in-out;
}
.sidebar {
padding-top: 0;
transition: margin .5s ease-in-out;
}
`);
});
} }
} }
......
...@@ -101,7 +101,7 @@ class WebView extends EventEmitter { ...@@ -101,7 +101,7 @@ class WebView extends EventEmitter {
webviewObj.addEventListener('dom-ready', () => { webviewObj.addEventListener('dom-ready', () => {
webviewObj.classList.add('ready'); webviewObj.classList.add('ready');
this.emit('dom-ready', host.url); this.emit('dom-ready', webviewObj, host.url);
}); });
webviewObj.addEventListener('did-fail-load', (e) => { webviewObj.addEventListener('did-fail-load', (e) => {
......
...@@ -31,7 +31,7 @@ gulp.task('less', () => gulp.src('src/stylesheets/main.less') ...@@ -31,7 +31,7 @@ gulp.task('less', () => gulp.src('src/stylesheets/main.less')
gulp.task('build-app', gulp.series('public', 'i18n', 'bundle', 'less')); gulp.task('build-app', gulp.series('public', 'i18n', 'bundle', 'less'));
gulp.task('watch', () => { gulp.task('watch', () => {
const run = (taskName) => batch((event, done) => gulp.start(taskName, done)); const run = (taskName) => batch((event, done) => gulp.task(taskName)(done));
watch('src/public/**/*', run('public')); watch('src/public/**/*', run('public'));
watch('src/i18n/lang/**/*', run('i18n')); watch('src/i18n/lang/**/*', run('i18n'));
......
...@@ -8,4 +8,4 @@ const spawnElectron = () => ( ...@@ -8,4 +8,4 @@ const spawnElectron = () => (
.on('close', spawnElectron) .on('close', spawnElectron)
); );
gulp.task('start', gulp.parallel('watch', gulp.series('build-app', spawnElectron))); gulp.task('start', gulp.series('build-app', gulp.parallel('watch', spawnElectron)));
...@@ -378,14 +378,6 @@ ...@@ -378,14 +378,6 @@
dependencies: dependencies:
core-js "^2.5.7" core-js "^2.5.7"
"@paulcbetts/system-idle-time@^1.0.4":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@paulcbetts/system-idle-time/-/system-idle-time-1.0.5.tgz#e54192e9134144a13699b55b52827274bd2d5b85"
integrity sha512-H0+wDm1yHmVHsmZBSU8AtjYX5nAtivSGlwun3xSLvPI+xu9TU6J6EpgJlA5JtMpc6mRAB1NacGMTeU7cvkdcvA==
dependencies:
bindings "~1.2.1"
nan "^2.0.0"
"@rocket.chat/eslint-config@^0.1.2": "@rocket.chat/eslint-config@^0.1.2":
version "0.1.2" version "0.1.2"
resolved "https://registry.yarnpkg.com/@rocket.chat/eslint-config/-/eslint-config-0.1.2.tgz#f9c5041b8a0e849de9eb4013e4e3efcbe9951d0a" resolved "https://registry.yarnpkg.com/@rocket.chat/eslint-config/-/eslint-config-0.1.2.tgz#f9c5041b8a0e849de9eb4013e4e3efcbe9951d0a"
...@@ -1111,11 +1103,6 @@ bindings@^1.2.1: ...@@ -1111,11 +1103,6 @@ bindings@^1.2.1:
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.1.tgz#21fc7c6d67c18516ec5aaa2815b145ff77b26ea5" resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.1.tgz#21fc7c6d67c18516ec5aaa2815b145ff77b26ea5"
integrity sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew== integrity sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew==
bindings@~1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11"
integrity sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=
bl@^1.0.0: bl@^1.0.0:
version "1.2.2" version "1.2.2"
resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.2.tgz#a160911717103c07410cef63ef51b397c025af9c" resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.2.tgz#a160911717103c07410cef63ef51b397c025af9c"
...@@ -5270,7 +5257,7 @@ mute-stream@0.0.7: ...@@ -5270,7 +5257,7 @@ mute-stream@0.0.7:
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
integrity sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s= integrity sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=
nan@^2.0.0, nan@^2.0.9, nan@^2.10.0, nan@^2.9.2: nan@^2.0.9, nan@^2.10.0, nan@^2.9.2:
version "2.12.1" version "2.12.1"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552" resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552"
integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw== integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment