From d601896f799d970c3fc31c9abb11c9b8a76fd95c Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 11 Apr 2021 22:32:36 +0200 Subject: [PATCH] Fix loading of themes in the custom generator: use compression --- InitUiElements.ts | 10 ++++------ customGenerator.ts | 8 +++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/InitUiElements.ts b/InitUiElements.ts index 5503057..d999f97 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -39,6 +39,8 @@ import SelectedFeatureHandler from "./Logic/Actors/SelectedFeatureHandler"; import LZString from "lz-string"; import {LayoutConfigJson} from "./Customizations/JSON/LayoutConfigJson"; import AttributionPanel from "./UI/BigComponents/AttributionPanel"; +import AllKnownLayers from "./Customizations/AllKnownLayers"; +import LayerConfig from "./Customizations/JSON/LayerConfig"; export class InitUiElements { @@ -83,13 +85,9 @@ export class InitUiElements { // This is purely for the personal theme to load the layers there const favs = State.state.favouriteLayers.data ?? []; + layoutToUse.layers.splice(0, layoutToUse.layers.length); for (const fav of favs) { - const layer = AllKnownLayouts.allLayers[fav]; - if (!!layer) { - layoutToUse.layers.push(layer); - } - for (const layouts of State.state.installedThemes.data) { for (const layer of layouts.layout.layers) { if (typeof layer === "string") { @@ -218,7 +216,7 @@ export class InitUiElements { json = JSON.parse(atob(hash)); } catch (e) { // We try to decode with lz-string - json = JSON.parse( Utils.UnMinify(LZString.decompressFromBase64(hash))) + json = JSON.parse(atob(window.location.hash.substr(1))) as LayoutConfigJson; } // @ts-ignore diff --git a/customGenerator.ts b/customGenerator.ts index ba8c564..84b0ff0 100644 --- a/customGenerator.ts +++ b/customGenerator.ts @@ -7,7 +7,13 @@ import {LocalStorageSource} from "./Logic/Web/LocalStorageSource"; let layout = GenerateEmpty.createEmptyLayout(); if (window.location.hash.length > 10) { - layout = JSON.parse(atob(window.location.hash.substr(1))) as LayoutConfigJson; + try{ + layout = JSON.parse(atob(window.location.hash.substr(1))) as LayoutConfigJson; + }catch(e){ + console.log("Initial load of theme failed, attempt nr 2 with decompression", e) + layout = JSON.parse(atob(window.location.hash.substr(1))) as LayoutConfigJson; + } + } else { const hash = LocalStorageSource.Get("last-custom-theme").data if (hash !== undefined) {