From bef421ebedead85cd2fbf13c5b8ca06f379c1c87 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Thu, 20 Sep 2018 06:50:08 -0700 Subject: [PATCH] Make state serialization opt-in (for now) --- js/index.js | 4 +++- js/indexdb.js | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/js/index.js b/js/index.js index d6536032..90476cb6 100644 --- a/js/index.js +++ b/js/index.js @@ -87,12 +87,14 @@ const MIN_MILKDROP_WIDTH = 725; let screenshot = false; let clearState = false; +let useState = false; let skinUrl = configSkinUrl; if ("URLSearchParams" in window) { const params = new URLSearchParams(location.search); screenshot = params.get("screenshot"); skinUrl = params.get("skinUrl") || skinUrl; clearState = Boolean(params.get("clearState")); + useState = Boolean(params.get("useState")); } function supressDragAndDrop(e) { @@ -301,7 +303,7 @@ Raven.context(async () => { // Expose webamp instance for debugging and integration tests. window.__webamp = webamp; - await bindToIndexDB(webamp, clearState); + await bindToIndexDB(webamp, clearState, useState); await webamp.renderWhenReady(document.getElementById("app")); }); diff --git a/js/indexdb.js b/js/indexdb.js index 73596012..b7e7c465 100644 --- a/js/indexdb.js +++ b/js/indexdb.js @@ -2,7 +2,7 @@ import IdbKvStore from "idb-kv-store"; import { throttle } from "./utils"; const LOCAL_STORAGE_KEY = "webamp_state"; -export async function bindToIndexDB(webamp, clearState) { +export async function bindToIndexDB(webamp, clearState, useState) { const localStore = new IdbKvStore("webamp_state_database"); if (clearState) { @@ -13,6 +13,10 @@ export async function bindToIndexDB(webamp, clearState) { } } + if (!useState) { + return; + } + let previousSerializedState = null; try { previousSerializedState = await localStore.get(LOCAL_STORAGE_KEY);