Detect new version

pull/1/head
yflory 7 years ago
parent 0d4fbec4bc
commit 089e0361b6

@ -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

@ -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) {

@ -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 {

@ -236,4 +236,7 @@ define({
// Get all existing tags
'Q_GET_ALL_TAGS': true,
// Reload on new version
'EV_NEW_VERSION': true,
});

Loading…
Cancel
Save