From d36fea27ad5a733fc644372c6ca11f5dc33c9a47 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 9 May 2018 18:33:13 +0300 Subject: [PATCH] fixup 3418ac9c: append to updateLog --- background/update.js | 9 ++++----- js/storage-util.js | 13 ++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) 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]),