Fix loading of compressed themes in the custom generator too

This commit is contained in:
pietervdvn 2021-04-11 23:43:23 +02:00
parent d601896f79
commit 9874b7d8c8
3 changed files with 16 additions and 6 deletions

View file

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

View file

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

View file

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