Add a flag to clear IndexDB state

This commit is contained in:
Jordan Eldredge 2018-09-19 21:43:55 -07:00
parent d1b43d55ca
commit 4f57d26b9c
2 changed files with 12 additions and 2 deletions

View file

@ -84,11 +84,13 @@ const NOISY_ACTION_TYPES = new Set([
const MIN_MILKDROP_WIDTH = 725;
let screenshot = false;
let clearState = 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"));
}
function supressDragAndDrop(e) {
@ -296,7 +298,7 @@ Raven.context(async () => {
// Expose webamp instance for debugging and integration tests.
window.__webamp = webamp;
await bindToIndexDB(webamp);
await bindToIndexDB(webamp, clearState);
await webamp.renderWhenReady(document.getElementById("app"));
});

View file

@ -2,9 +2,17 @@ import IdbKvStore from "idb-kv-store";
import { throttle } from "./utils";
const LOCAL_STORAGE_KEY = "webamp_state";
export async function bindToIndexDB(webamp) {
export async function bindToIndexDB(webamp, clearState) {
const localStore = new IdbKvStore("webamp_state_database");
if (clearState) {
try {
await localStore.clear();
} catch (e) {
console.log("Failed to clear our IndexdB state", e);
}
}
let previousSerializedState = null;
try {
previousSerializedState = await localStore.get(LOCAL_STORAGE_KEY);