From 4250dcf3f0e940d17bff208683bc498c2f3ce1e5 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 1 Mar 2022 15:49:35 +0100 Subject: [PATCH] Cleanup theme switcher --- dev/Common/Utils.js | 50 ++++++++------------- dev/boot.js | 3 -- snappymail/v/0.0.0/app/templates/Index.html | 2 +- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index fef3b523d..b9062dae8 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -55,41 +55,29 @@ export const __themeJson = null; }; - let url = themeStyle.dataset.href; + let url = themeStyle.dataset.href.replace(/(Admin|User)\/-\/[^/]+\//, '$1/-/' + value + '/') + + 'Json/'; - if (url) { - url = url.toString() - .replace(/\/-\/[^/]+\/-\//, '/-/' + value + '/-/') - .replace(/\/Css\/[^/]+\/User\//, '/Css/0/User/') - .replace(/\/Hash\/[^/]+\//, '/Hash/-/'); + clearTimeout(__themeTimer); - if ('Json/' !== url.substr(-5)) { - url += 'Json/'; - } + themeTrigger(SaveSettingsStep.Animate); - clearTimeout(__themeTimer); - - themeTrigger(SaveSettingsStep.Animate); - - if (__themeJson) { - __themeJson.abort(); - } - let init = {}; - if (window.AbortController) { - __themeJson = new AbortController(); - init.signal = __themeJson.signal; - } - rl.fetchJSON(url, init) - .then(data => { - if (2 === arrayLength(data)) { - themeStyle.textContent = data[1]; - themeStyle.dataset.href = url; - themeStyle.dataset.theme = data[0]; - themeTrigger(SaveSettingsStep.TrueResult); - } - }) - .then(clearTimer, clearTimer); + if (__themeJson) { + __themeJson.abort(); } + let init = {}; + if (window.AbortController) { + __themeJson = new AbortController(); + init.signal = __themeJson.signal; + } + rl.fetchJSON(url, init) + .then(data => { + if (2 === arrayLength(data)) { + themeStyle.textContent = data[1]; + themeTrigger(SaveSettingsStep.TrueResult); + } + }) + .then(clearTimer, clearTimer); }, getKeyByValue = (o, v) => Object.keys(o).find(key => o[key] === v); diff --git a/dev/boot.js b/dev/boot.js index 36525c3d0..07a1d6503 100644 --- a/dev/boot.js +++ b/dev/boot.js @@ -6,7 +6,6 @@ const doc = document, eId = id => doc.getElementById('rl-'+id), app = eId('app'), - css = eId('css'), admin = app && '1' == app.dataset.admin, cb = () => rl.app.bootstart(), @@ -70,8 +69,6 @@ win.rl = { } }; -css.href = css.dataset.href; - loadScript(`./?/${admin ? 'Admin' : ''}AppData/0/${Math.random().toString().slice(2)}/`) .then(() => 0); diff --git a/snappymail/v/0.0.0/app/templates/Index.html b/snappymail/v/0.0.0/app/templates/Index.html index 5cab773ad..eac9e333e 100644 --- a/snappymail/v/0.0.0/app/templates/Index.html +++ b/snappymail/v/0.0.0/app/templates/Index.html @@ -12,7 +12,7 @@