From e8cdbf663018a5122edf67dbbfe0e07491eae442 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 8 Dec 2020 11:19:38 +0100 Subject: [PATCH] Fix race condition in framework --- www/common/sframe-app-framework.js | 9 ++++++--- www/common/toolbar.js | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 8776573d7..5c0f9b511 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -221,6 +221,10 @@ define([ evStart.reg(function () { toolbar.deleted(); }); break; } + case STATE.READY: { + evStart.reg(function () { toolbar.ready(); }); + break; + } default: } var isEditable = (state === STATE.READY && !unsyncMode); @@ -479,7 +483,7 @@ define([ sframeChan.event("EV_CORRUPTED_CACHE"); }; var onCacheReady = function () { - stateChange(STATE.DISCONNECTED); + stateChange(STATE.INITIALIZING); toolbar.offline(true); var newContentStr = cpNfInner.chainpad.getUserDoc(); if (toolbar) { @@ -526,7 +530,6 @@ define([ var privateDat = cpNfInner.metadataMgr.getPrivateData(); var type = privateDat.app; - // contentUpdate may be async so we need an nthen here nThen(function (waitFor) { if (!newPad) { @@ -783,7 +786,7 @@ define([ onRemote: onRemote, onLocal: onLocal, onInit: onInit, - onCacheReady: onCacheReady, + onCacheReady: function () { evStart.reg(onCacheReady); }, onReady: function () { evStart.reg(onReady); }, onConnectionChange: onConnectionChange, onError: onError, diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 20cac8337..e2c5af1dd 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -1318,6 +1318,10 @@ MessengerUI, Messages) { toolbar.spinner.text(Messages.reconnecting); } }; + toolbar.ready = function () { + toolbar.connected = true; + kickSpinner(toolbar, config); + }; toolbar.errorState = function (state, error) { toolbar.isErrorState = state;