diff --git a/background/update.js b/background/update.js index 34b238c6..29b8359f 100644 --- a/background/update.js +++ b/background/update.js @@ -225,12 +225,11 @@ global API_METHODS debounce(flushQueue, text && checkingAll ? 1000 : 0); } - function flushQueue(stored) { - if (!stored) { - chrome.storage.local.get('updateLog', flushQueue); + function flushQueue(lines) { + if (!lines) { + chromeLocal.getValue('updateLog', []).then(flushQueue); return; } - const lines = stored.lines || []; const time = Date.now() - logLastWriteTime > 11e3 ? logQueue[0].time + ' ' : ''; @@ -242,7 +241,7 @@ global API_METHODS lines.push(time + (logQueue[0] && logQueue[0].text || '')); lines.push(...logQueue.slice(1).map(item => item.text)); - chrome.storage.local.set({updateLog: lines}); + chromeLocal.setValue('updateLog', lines); logLastWriteTime = Date.now(); logQueue = []; } diff --git a/js/storage-util.js b/js/storage-util.js index 209e211c..8cf894d9 100644 --- a/js/storage-util.js +++ b/js/storage-util.js @@ -21,7 +21,18 @@ var [chromeLocal, chromeSync] = (() => { set: data => new Promise(resolve => storage.set(data, () => resolve(data))), remove: data => new Promise(resolve => storage.remove(data, resolve)), - getValue: key => wrapper.get(key).then(data => data[key]), + /** + * @param {String} key + * @param {Any} [defaultValue] + * @returns {Promise} + */ + getValue: (key, defaultValue) => + wrapper.get( + defaultValue !== undefined ? + {[key]: defaultValue} : + key + ).then(data => data[key]), + setValue: (key, value) => wrapper.set({[key]: value}), getLZValue: key => wrapper.getLZValues([key]).then(data => data[key]),