Fix loading of themes in the custom generator: use compression

This commit is contained in:
pietervdvn 2021-04-11 22:32:36 +02:00
parent 63187aab04
commit d601896f79
2 changed files with 11 additions and 7 deletions

View file

@ -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

View file

@ -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) {