switch to ‘postMessage’ for webapp communication (#1026)

This commit is contained in:
Dean Whillier 2019-09-09 12:33:14 -04:00 committed by GitHub
parent 2d173e6f70
commit f12f9da798
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 22 deletions

View file

@ -1,17 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import EventEmitter from 'events';
/**
* Provides the bridging infrastructure to connect the desktop and webapp together
*/
export default class WebappConnector extends EventEmitter {
constructor() {
super();
this.active = true;
window.webappConnector = this;
}
}

View file

@ -6,14 +6,11 @@
import {ipcRenderer, webFrame} from 'electron'; import {ipcRenderer, webFrame} from 'electron';
import EnhancedNotification from '../js/notification'; import EnhancedNotification from '../js/notification';
import WebappConnector from '../js/WebappConnector';
const UNREAD_COUNT_INTERVAL = 1000; const UNREAD_COUNT_INTERVAL = 1000;
//eslint-disable-next-line no-magic-numbers //eslint-disable-next-line no-magic-numbers
const CLEAR_CACHE_INTERVAL = 6 * 60 * 60 * 1000; // 6 hours const CLEAR_CACHE_INTERVAL = 6 * 60 * 60 * 1000; // 6 hours
const webappConnector = new WebappConnector();
Notification = EnhancedNotification; // eslint-disable-line no-global-assign, no-native-reassign Notification = EnhancedNotification; // eslint-disable-line no-global-assign, no-native-reassign
Reflect.deleteProperty(global.Buffer); // http://electron.atom.io/docs/tutorial/security/#buffer-global Reflect.deleteProperty(global.Buffer); // http://electron.atom.io/docs/tutorial/security/#buffer-global
@ -201,9 +198,9 @@ function setSpellChecker() {
setSpellChecker(); setSpellChecker();
ipcRenderer.on('set-spellchecker', setSpellChecker); ipcRenderer.on('set-spellchecker', setSpellChecker);
// push user activity updates to the webapp via the communication bridge // push user activity updates to the webapp
ipcRenderer.on('user-activity-update', (event, {userIsActive, isSystemEvent}) => { ipcRenderer.on('user-activity-update', (event, {userIsActive, isSystemEvent}) => {
webappConnector.emit('user-activity-update', {userIsActive, manual: isSystemEvent}); window.postMessage({type: 'user-activity-update', message: {userIsActive, manual: isSystemEvent}}, window.location.origin);
}); });
// mattermost-webapp is SPA. So cache is not cleared due to no navigation. // mattermost-webapp is SPA. So cache is not cleared due to no navigation.