forked from trent_larson/crowd-funder-for-time-pwa
make more adjustments to try and get logging to work
This commit is contained in:
@@ -407,16 +407,17 @@ async function setMostRecentNotified(id) {
|
||||
async function logMessage(message) {
|
||||
try {
|
||||
const db = await openIndexedDB("TimeSafari");
|
||||
const transaction = db.transaction("worker_log", "readwrite");
|
||||
const store = transaction.objectStore("worker_log");
|
||||
const transaction = db.transaction("logs", "readwrite");
|
||||
const store = transaction.objectStore("logs");
|
||||
// will only keep one day's worth of logs
|
||||
let data = await getRecord(store, new Date().toDateString());
|
||||
const todayKey = new Date().toDateString();
|
||||
let data = await getRecord(store, todayKey);
|
||||
if (!data) {
|
||||
await store.clear(); // clear out anything older than today
|
||||
}
|
||||
data = data || "";
|
||||
data += `\n${message}`;
|
||||
await updateRecord(store, data);
|
||||
await updateRecord(store, { message: data }, todayKey);
|
||||
transaction.oncomplete = () => db.close();
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -442,9 +443,9 @@ function getRecord(store, key) {
|
||||
}
|
||||
|
||||
// Note that this assumes there is only one record in the store.
|
||||
function updateRecord(store, data) {
|
||||
function updateRecord(store, data, key) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = store.put(data);
|
||||
const request = key ? store.put(data, key) : store.put(data);
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = () => reject(request.error);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user