fixup 3418ac9c: append to updateLog

This commit is contained in:
tophf 2018-05-09 18:33:13 +03:00
parent 3548a6caed
commit d36fea27ad
2 changed files with 16 additions and 6 deletions

View File

@ -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 = [];
}

View File

@ -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<any>}
*/
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]),