From 47667fa58e69cddb3b9e4507b1f9939a840e8cf9 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 11 Jan 2017 19:53:42 +0000 Subject: [PATCH] Change storage abstraction to use a new key --- src/app/storage.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/app/storage.js b/src/app/storage.js index 0bcc71c83a..f6dc715bb9 100644 --- a/src/app/storage.js +++ b/src/app/storage.js @@ -6,20 +6,24 @@ function Storage () { } this.get = function (name) { - return window.localStorage.getItem(name) + return window.localStorage.getItem('sol:' + name) } this.set = function (name, content) { - window.localStorage.setItem(name, content) + window.localStorage.setItem('sol:' + name, content) } - this.keys = function () { + function safeKeys () { // NOTE: this is a workaround for some browsers return Object.keys(window.localStorage).filter(function (item) { return item !== null && item !== undefined }) } + this.keys = function () { + return safeKeys().filter(function (item) { return item.replace('sol:', '') }) + } + this.remove = function (name) { - window.localStorage.removeItem(name) + window.localStorage.removeItem('sol:' + name) } this.rename = function (originalName, newName) { @@ -36,6 +40,15 @@ function Storage () { } this.set(filename, content) } + + // on startup, upgrade the old storage layout + safeKeys().forEach(function (name) { + if (name.indexOf('sol-cache-file-', 0) === 0) { + var content = window.localStorage.getItem(name) + window.localStorage.setItem('sol:' + name.replace('sol-cache-file-', ''), content) + window.localStorage.removeItem(name) + } + }) } module.exports = Storage