on master help sign in
Don't let bw use localstorage
50a3a0biko
bw/src/BW.js+8−14
@@ -99,7 +99,7 @@ class MainBackground {
99 constructor() {
99 constructor() {
100
100
101 this.messagingService = new BrowserMessagingService();
101 this.messagingService = new BrowserMessagingService();
102− this.storageService = new BrowserStorageService();
102+ this.storageService = new MemoryStorageService();
103 this.logService = new ConsoleLogService(false);
103 this.logService = new ConsoleLogService(false);
104 this.stateMigrationService = new StateMigrationService(
104 this.stateMigrationService = new StateMigrationService(
105 this.storageService,
105 this.storageService,
@@ -172,34 +172,28 @@ class MainBackground {
172 }
172 }
173}
173}
174
174
175−
175+class MemoryStorageService {
176−class BrowserStorageService {
176+ storage = {};
177− storage;
178−
179− constructor() {
180− this.storage = window.localStorage;
181− }
182
177
183 async get(key) {
178 async get(key) {
184− return JSON.parse(this.storage.getItem(key))
179+ return this.storage[key]
185 }
180 }
186
181
187 async has(key) {
182 async has(key) {
188− return this.storage.getItem(key) != null;
183+ return key in this.storage;
189 }
184 }
190
185
191 async save(key, obj) {
186 async save(key, obj) {
192 if (obj == null) {
187 if (obj == null) {
193− // Fix safari not liking null in set
188+ this.remove(key)
194− this.storage.removeItem(key)
195 return
189 return
196 }
190 }
197
191
198− this.storage.setItem(key, JSON.stringify(obj));
192+ this.storage[key] = obj
199 }
193 }
200
194
201 async remove(key) {
195 async remove(key) {
202− this.storage.removeItem(key)
196+ delete this.storage[key]
203 }
197 }
204}
198}
205
199