From ead767658fc3bc6beca815d58c4c049b69f8096f Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 26 Jan 2021 15:57:25 +0100 Subject: [PATCH] Fix race condition --- www/common/loading.js | 15 +++++++++++++++ www/common/sframe-boot2.js | 10 ---------- www/common/sframe-common-outer.js | 3 +++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/www/common/loading.js b/www/common/loading.js index 9394c6ae3..98003daba 100644 --- a/www/common/loading.js +++ b/www/common/loading.js @@ -1,3 +1,18 @@ +(function () { +try { + var req = JSON.parse(decodeURIComponent(window.location.hash.substring(1))); + var theme = req.theme; + var os = req.themeOS; + window.CryptPad_theme = theme || os; + if ((theme || os) === 'dark') { + var s = document.createElement('style'); + s.innerHTML = 'body { background: black; }'; + document.body.appendChild(s); + } + console.error(theme, os); +} catch (e) { console.error(e); } +})(); + require(['/customize/loading.js'], function (Loading) { Loading(); }); diff --git a/www/common/sframe-boot2.js b/www/common/sframe-boot2.js index 828c244a8..66a93545f 100644 --- a/www/common/sframe-boot2.js +++ b/www/common/sframe-boot2.js @@ -1,13 +1,3 @@ -(function () { -try { - if (!window.cryptpadStore) { return; } - var theme = window.cryptpadStore.store['colortheme']; - var os = window.cryptpadStore.store['colortheme_default']; - window.CryptPad_theme = theme || os; - console.error(theme, os); -} catch (e) { console.error(e); } -})(); - // This is stage 1, it can be changed but you must bump the version of the project. // Note: This must only be loaded from inside of a sandbox-iframe. define([ diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 80bce6cc2..b3540c7e6 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -11,10 +11,13 @@ define([ common.initIframe = function (waitFor, isRt, pathname) { var requireConfig = RequireConfig(); var lang = Messages._languageUsed; + var themeKey = 'CRYPTPAD_STORE|colortheme'; var req = { cfg: requireConfig, req: [ '/common/loading.js' ], pfx: window.location.origin, + theme: localStorage[themeKey], + themeOS: localStorage[themeKey+'_default'], lang: lang }; window.rc = requireConfig;