From ee56f5608fa26293c2cb6626099a1a511ade00f4 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 8 Dec 2016 18:52:36 +0100 Subject: [PATCH] Fix the infinite spinner bug with the file manager store --- customize.dist/fsStore.js | 9 ++++++++- customize.dist/translations/messages.js | 1 + www/code/main.js | 15 +++++++++++---- www/common/cryptpad-common.js | 17 +++++++++++++++-- www/pad/main.js | 15 +++++++++++---- www/poll/test/main.js | 4 ++++ www/slide/main.js | 15 +++++++++++---- 7 files changed, 61 insertions(+), 15 deletions(-) diff --git a/customize.dist/fsStore.js b/customize.dist/fsStore.js index e953f8354..215c515ab 100644 --- a/customize.dist/fsStore.js +++ b/customize.dist/fsStore.js @@ -153,8 +153,15 @@ define([ } onReady(f, rt.proxy, Cryptpad.storageKey); }) - .on('disconnect', function () { + .on('disconnect', function (info) { //setEditable(false); + if (info.error) { + //Cryptpad.alert(Messages.websocketError); + if (typeof Cryptpad.storeError === "function") { + Cryptpad.storeError(); + } + return; + } Cryptpad.alert(Messages.common_connectionLost); }); diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index d97a11fcf..6560767f8 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -21,6 +21,7 @@ define(function () { ].join(''); out.common_connectionLost = 'Server Connection Lost'; + out.websocketError = 'Unable to connect to the websocket server...'; out.disconnected = 'Disconnected'; out.synchronizing = 'Synchronizing'; diff --git a/www/code/main.js b/www/code/main.js index df068beef..761577034 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -42,6 +42,11 @@ define([ secret.keys = secret.key; } + var onConnectError = function (info) { + module.spinner.hide(); + Cryptpad.alert(Messages.websocketError); + }; + var andThen = function (CMeditor) { var CodeMirror = module.CodeMirror = CMeditor; CodeMirror.modeURL = "/bower_components/codemirror/mode/%N/%N.js"; @@ -687,10 +692,7 @@ define([ } }; - var onError = config.onError = function (info) { - module.spinner.hide(); - Cryptpad.alert(Messages.websocketError); - }; + var onError = config.onError = onConnectError(); var realtime = module.realtime = Realtime.start(config); @@ -704,6 +706,11 @@ define([ // TODO handle error andThen(CM); }); + Cryptpad.onError(function (info) { + if (info && info.type === "store") { + onConnectError(); + } + }); }; var first = function () { diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 698430acf..fdc212cec 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -649,6 +649,19 @@ define([ }, common); }; + var errorHandlers = []; + common.onError = function (h) { + if (typeof h !== "function") { return; } + errorHandlers.push(h); + }; + common.storeError = function () { + errorHandlers.forEach(function (h) { + if (typeof h === "function") { + h({type: "store"}); + } + }); + }; + /* * Saving files */ @@ -877,9 +890,9 @@ define([ var $link = $('link[href="/customize/alertify.css"]'); if ($link.length) { return; - $link.attr('href', ''); + /*$link.attr('href', ''); $link.attr('href', '/customize/alertify.css'); - return; + return;*/ } href = href || '/customize/alertify.css'; diff --git a/www/pad/main.js b/www/pad/main.js index bed565952..4acc3469a 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -77,6 +77,11 @@ define([ return hj; }; + var onConnectError = function (info) { + module.spinner.hide(); + Cryptpad.alert(Messages.websocketError); + }; + var andThen = function (Ckeditor) { var secret = Cryptpad.getSecrets(); var readOnly = secret.keys && !secret.keys.editKeyStr; @@ -691,10 +696,7 @@ define([ } }; - var onError = realtimeOptions.onError = function (info) { - module.spinner.hide(); - Cryptpad.alert(Messages.websocketError); - }; + var onError = realtimeOptions.onError = onConnectError; var onLocal = realtimeOptions.onLocal = function () { if (initializing) { return; } @@ -741,6 +743,11 @@ define([ // TODO handle error andThen(Ckeditor); }); + Cryptpad.onError(function (info) { + if (info && info.type === "store") { + onConnectError(); + } + }); }; var first = function () { diff --git a/www/poll/test/main.js b/www/poll/test/main.js index d2abae97c..069406ee7 100644 --- a/www/poll/test/main.js +++ b/www/poll/test/main.js @@ -662,6 +662,10 @@ define([ var disconnect = function () { //setEditable(false); // TODO + if (info.error) { + Cryptpad.alert(Messages.websocketError); + return; + } //Cryptpad.alert(Messages.common_connectionLost); // TODO }; diff --git a/www/slide/main.js b/www/slide/main.js index b43da457a..d1dfe212e 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -59,6 +59,11 @@ define([ var presentMode = Slide.isPresentURL(); + var onConnectError = function (info) { + module.spinner.hide(); + Cryptpad.alert(Messages.websocketError); + }; + var andThen = function (CMeditor) { var CodeMirror = module.CodeMirror = CMeditor; CodeMirror.modeURL = "/bower_components/codemirror/mode/%N/%N.js"; @@ -786,10 +791,7 @@ define([ } }; - var onError = config.onError = function (info) { - module.spinner.hide(); - Cryptpad.alert(Messages.websocketError); - }; + var onError = config.onError = onConnectError; var realtime = module.realtime = Realtime.start(config); @@ -803,6 +805,11 @@ define([ // TODO handle error andThen(CM); }); + Cryptpad.onError(function (info) { + if (info && info.type === "store") { + onConnectError(); + } + }); }; var first = function () {