From 0e6012ad4561102c72bbdcb2c29c300a57927f4e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 3 Jun 2017 12:50:47 +0100 Subject: [PATCH] absorb updater.js into the Platforms, gets rid of pointless setInterval in Electron Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> (cherry picked from commit 24e8a30) Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/index.js | 7 +++--- src/vector/platform/VectorBasePlatform.js | 6 +++++ src/vector/platform/WebPlatform.js | 7 ++++++ src/vector/updater.js | 30 ----------------------- 4 files changed, 17 insertions(+), 33 deletions(-) delete mode 100644 src/vector/updater.js diff --git a/src/vector/index.js b/src/vector/index.js index 9f16205164..d26e480e30 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -59,7 +59,6 @@ var sdk = require("matrix-react-sdk"); const PlatformPeg = require("matrix-react-sdk/lib/PlatformPeg"); sdk.loadSkin(require('../component-index')); var VectorConferenceHandler = require('../VectorConferenceHandler'); -var UpdateChecker = require("./updater"); var q = require('q'); var request = require('browser-request'); import * as UserSettingsStore from 'matrix-react-sdk/lib/UserSettingsStore'; @@ -277,7 +276,9 @@ async function loadApp() { Unable to load config file: please refresh the page to try again. , document.getElementById('matrixchat')); } else if (validBrowser) { - UpdateChecker.start(); + const platform = PlatformPeg.get(); + platform.startUpdater(); + const MatrixChat = sdk.getComponent('structures.MatrixChat'); window.matrixChat = ReactDOM.render( , document.getElementById('matrixchat') ); diff --git a/src/vector/platform/VectorBasePlatform.js b/src/vector/platform/VectorBasePlatform.js index 76707d1d58..8e998402c4 100644 --- a/src/vector/platform/VectorBasePlatform.js +++ b/src/vector/platform/VectorBasePlatform.js @@ -74,6 +74,12 @@ export default class VectorBasePlatform extends BasePlatform { this._updateFavicon(); } + /** + * Begin update polling, if applicable + */ + startUpdater() { + } + /** * Check for the availability of an update to the version of the * app that's currently running. diff --git a/src/vector/platform/WebPlatform.js b/src/vector/platform/WebPlatform.js index 8397a7f703..c589af38b8 100644 --- a/src/vector/platform/WebPlatform.js +++ b/src/vector/platform/WebPlatform.js @@ -26,6 +26,8 @@ import q from 'q'; import url from 'url'; import UAParser from 'ua-parser-js'; +var POKE_RATE_MS = 10 * 60 * 1000; // 10 min + export default class WebPlatform extends VectorBasePlatform { constructor() { super(); @@ -132,6 +134,11 @@ export default class WebPlatform extends VectorBasePlatform { return this._getVersion(); } + startUpdater() { + this.pollForUpdate(); + setInterval(this.pollForUpdate, POKE_RATE_MS); + } + pollForUpdate() { this._getVersion().done((ver) => { if (this.runningVersion === null) { diff --git a/src/vector/updater.js b/src/vector/updater.js deleted file mode 100644 index 19d40b4f38..0000000000 --- a/src/vector/updater.js +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2016 OpenMarket Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg'; - -var POKE_RATE_MS = 10 * 60 * 1000; // 10 min - -module.exports = { - start: function() { - module.exports.poll(); - setInterval(module.exports.poll, POKE_RATE_MS); - }, - - poll: function() { - PlatformPeg.get().pollForUpdate(); - } -};