From 9874b7d8c86751b9491618acd9f342de0ebdbca2 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 11 Apr 2021 23:43:23 +0200 Subject: [PATCH] Fix loading of compressed themes in the custom generator too --- InitUiElements.ts | 3 ++- Logic/Actors/InstalledThemes.ts | 12 +++++++++--- customGenerator.ts | 7 +++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/InitUiElements.ts b/InitUiElements.ts index d999f97..8593398 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -216,7 +216,8 @@ export class InitUiElements { json = JSON.parse(atob(hash)); } catch (e) { // We try to decode with lz-string - json = JSON.parse(atob(window.location.hash.substr(1))) as LayoutConfigJson; + json = JSON.parse( Utils.UnMinify(LZString.decompressFromBase64(hash))) as LayoutConfigJson; + } // @ts-ignore diff --git a/Logic/Actors/InstalledThemes.ts b/Logic/Actors/InstalledThemes.ts index 9d83e46..b395fbe 100644 --- a/Logic/Actors/InstalledThemes.ts +++ b/Logic/Actors/InstalledThemes.ts @@ -1,6 +1,8 @@ import {UIEventSource} from "../UIEventSource"; import LayoutConfig from "../../Customizations/JSON/LayoutConfig"; import {OsmConnection} from "../Osm/OsmConnection"; +import {Utils} from "../../Utils"; +import LZString from "lz-string"; export default class InstalledThemes { public installedThemes: UIEventSource<{ layout: LayoutConfig; definition: string }[]>; @@ -22,9 +24,13 @@ export default class InstalledThemes { continue; } try { - const json = atob(customLayout.data); - const layout = new LayoutConfig( - JSON.parse(json), false); + let layoutJson; + try{ + layoutJson = JSON.parse(atob(customLayout.data)) + }catch(e){ + layoutJson = JSON.parse( Utils.UnMinify(LZString.decompressFromBase64(customLayout.data))) + } + const layout = new LayoutConfig(layoutJson, false); installedThemes.push({ layout: layout, definition: customLayout.data diff --git a/customGenerator.ts b/customGenerator.ts index 84b0ff0..c0179c8 100644 --- a/customGenerator.ts +++ b/customGenerator.ts @@ -4,14 +4,17 @@ import {LayoutConfigJson} from "./Customizations/JSON/LayoutConfigJson"; import {OsmConnection} from "./Logic/Osm/OsmConnection"; import CustomGeneratorPanel from "./UI/CustomGenerator/CustomGeneratorPanel"; import {LocalStorageSource} from "./Logic/Web/LocalStorageSource"; +import {Utils} from "./Utils"; +import LZString from "lz-string"; let layout = GenerateEmpty.createEmptyLayout(); if (window.location.hash.length > 10) { + const hash = window.location.hash.substr(1) try{ - layout = JSON.parse(atob(window.location.hash.substr(1))) as LayoutConfigJson; + layout = JSON.parse(atob(hash)) 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; + layout = JSON.parse( Utils.UnMinify(LZString.decompressFromBase64(hash))) } } else {