From 854c1e94a42954e2c89584db8d513c773c3f3424 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Fri, 13 Oct 2017 13:39:49 +0300 Subject: [PATCH] make infinite spinner error message go away if ChainPad settles after it has been popped --- www/common/sframe-app-framework.js | 29 ++++++++++++++++----- www/common/sframe-chainpad-netflux-inner.js | 1 - 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 0a22fefc7..a0dbdf3c5 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -10,6 +10,7 @@ define([ '/common/sframe-common.js', '/customize/messages.js', '/common/common-util.js', + '/customize/application_config.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', @@ -25,7 +26,8 @@ define([ nThen, SFCommon, Messages, - Util) + Util, + AppConfig) { var SaveAs = window.saveAs; @@ -40,6 +42,9 @@ define([ READY: 'READY' }); + var badStateTimeout = typeof(AppConfig.badStateTimeout) === 'number' ? + AppConfig.badStateTimeout : 30000; + var onConnectError = function () { Cryptpad.errorLoadingScreen(Messages.websocketError); }; @@ -101,7 +106,7 @@ define([ var stateChange = function (newState) { var wasEditable = (state === STATE.READY); - if (state === STATE.INFINITE_SPINNER) { return; } + if (state === STATE.INFINITE_SPINNER && newState !== STATE.READY) { return; } if (newState === STATE.INFINITE_SPINNER) { state = newState; } else if (state === STATE.DISCONNECTED && newState !== STATE.INITIALIZING) { @@ -365,15 +370,27 @@ define([ textPatcher = TextPatcher.create({ realtime: cpNfInner.chainpad }); - cpNfInner.onInfiniteSpinner(function () { - toolbar.failed(); - cpNfInner.chainpad.abort(); + window.setInterval(function () { + if (state === STATE.DISCONNECTED) { return; } + var l; + try { + l = cpNfInner.chainpad.getLag(); + } catch (e) { + throw new Error("ChainPad.getLag() does not exist, please `bower update`"); + } + if (l.lag < badStateTimeout) { return; } + stateChange(STATE.INFINITE_SPINNER); Cryptpad.confirm(Messages.realtime_unrecoverableError, function (yes) { if (!yes) { return; } common.gotoURL(); }); - }); + cpNfInner.chainpad.onSettle(function () { + Cryptpad.findCancelButton().click(); + stateChange(STATE.READY); + onRemote(); + }); + }, 2000); //Cryptpad.onLogout(function () { ... }); diff --git a/www/common/sframe-chainpad-netflux-inner.js b/www/common/sframe-chainpad-netflux-inner.js index 7e0eb2a57..2c46b2129 100644 --- a/www/common/sframe-chainpad-netflux-inner.js +++ b/www/common/sframe-chainpad-netflux-inner.js @@ -75,7 +75,6 @@ define([ throw new Error("ChainPad.getLag() does not exist, please `bower update`"); } if (l.lag < badStateTimeout) { return; } - chainpad.abort(); evInfiniteSpinner.fire(); }, 2000);