From 089e0361b6ea82d94d8a84663e79b2e3f42a710a Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 11 Jun 2018 16:52:26 +0200 Subject: [PATCH] Detect new version --- www/common/cryptpad-common.js | 20 +++++++++++++++++--- www/common/sframe-common-outer.js | 4 ++++ www/common/sframe-common.js | 6 ++++++ www/common/sframe-protocol.js | 3 +++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 9131b34c6..9c29fbe4d 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -525,6 +525,7 @@ define([ // Network common.onNetworkDisconnect = Util.mkEvent(); common.onNetworkReconnect = Util.mkEvent(); + common.onNewVersionReconnect = Util.mkEvent(); // Messaging var messaging = common.messaging = {}; @@ -622,9 +623,10 @@ define([ }; var CRYPTPAD_VERSION = 'cryptpad-version'; - var updateLocalVersion = function () { + var currentVersion = localStorage[CRYPTPAD_VERSION]; + var updateLocalVersion = function (newUrlArgs) { // Check for CryptPad updates - var urlArgs = Config.requireConf ? Config.requireConf.urlArgs : null; + var urlArgs = newUrlArgs || (Config.requireConf ? Config.requireConf.urlArgs : null); if (!urlArgs) { return; } var arr = /ver=([0-9.]+)(-[0-9]*)?/.exec(urlArgs); var ver = arr[1]; @@ -632,14 +634,20 @@ define([ var verArr = ver.split('.'); verArr[2] = 0; if (verArr.length !== 3) { return; } - var stored = localStorage[CRYPTPAD_VERSION] || '0.0.0'; + var stored = currentVersion || '0.0.0'; var storedArr = stored.split('.'); storedArr[2] = 0; var shouldUpdate = parseInt(verArr[0]) > parseInt(storedArr[0]) || (parseInt(verArr[0]) === parseInt(storedArr[0]) && parseInt(verArr[1]) > parseInt(storedArr[1])); if (!shouldUpdate) { return; } + currentVersion = ver; localStorage[CRYPTPAD_VERSION] = ver; + if (newUrlArgs) { + // It's a reconnect + common.onNewVersionReconnect.fire(); + } + return true; }; var _onMetadataChanged = []; @@ -696,6 +704,12 @@ define([ common.onNetworkDisconnect.fire(); break; } case 'NETWORK_RECONNECT': { + require(['/api/config?' + (+new Date())], function (NewConfig) { + var update = updateLocalVersion(NewConfig.requireConf && NewConfig.requireConf.urlArgs); + if (update) { + postMessage('DISCONNECT'); + } + }); common.onNetworkReconnect.fire(data); break; } // Messenger diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 5f0bac953..45738265d 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -267,6 +267,10 @@ define([ Test.registerOuter(sframeChan); + Cryptpad.onNewVersionReconnect.reg(function () { + sframeChan.event("EV_NEW_VERSION"); + }); + // Put in the following function the RPC queries that should also work in filepicker var addCommonRpc = function (sframeChan) { sframeChan.on('Q_ANON_RPC_MESSAGE', function (data, cb) { diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 89cc16554..6687baee0 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -438,6 +438,12 @@ define([ UI.updateLoadingProgress(data, true); }); + ctx.sframeChan.on('EV_NEW_VERSION', function () { + // TODO display new verison stuff + // XXX + UI.errorLoadingScreen("New version detected", true, true); + }); + ctx.metadataMgr.onReady(waitFor()); }).nThen(function () { try { diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index fef8b1027..e50740c04 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -236,4 +236,7 @@ define({ // Get all existing tags 'Q_GET_ALL_TAGS': true, + + // Reload on new version + 'EV_NEW_VERSION': true, });