From 4dd5664462992731f52ff1c3f8c9ea687247eec2 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Fri, 1 Dec 2023 07:12:13 -0500 Subject: [PATCH] Fix exit from loops --- sw_scripts/additional-scripts.js | 2 ++ sw_scripts/safari-notifications.js | 10 ++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/sw_scripts/additional-scripts.js b/sw_scripts/additional-scripts.js index f7416169..e39c527a 100644 --- a/sw_scripts/additional-scripts.js +++ b/sw_scripts/additional-scripts.js @@ -5,6 +5,7 @@ importScripts( ); self.addEventListener("install", (event) => { + console.error(event); importScripts( "safari-notifications.js", "nacl.js", @@ -22,6 +23,7 @@ self.addEventListener("push", function (event) { payload = JSON.parse(event.data.text()); } const message = await self.getNotificationCount(); + console.error(message); const title = payload ? payload.title : "Custom Title"; const options = { body: message, diff --git a/sw_scripts/safari-notifications.js b/sw_scripts/safari-notifications.js index 158372c1..f0baf832 100644 --- a/sw_scripts/safari-notifications.js +++ b/sw_scripts/safari-notifications.js @@ -389,8 +389,8 @@ async function setMostRecentNotified(id) { const db = await openIndexedDB("TimeSafari"); const transaction = db.transaction("settings", "readwrite"); const store = transaction.objectStore("settings"); - const data = await getRecord(store, 1); + if (data) { data["lastNotifiedClaimId"] = id; await updateRecord(store, data); @@ -409,12 +409,6 @@ function openIndexedDB(dbName) { const request = indexedDB.open(dbName); request.onerror = () => reject(request.error); request.onsuccess = () => resolve(request.result); - request.onupgradeneeded = (event) => { - const db = event.target.result; - if (!db.objectStoreNames.contains("settings")) { - db.createObjectStore("settings"); - } - }; }); } @@ -526,10 +520,10 @@ async function getNotificationCount() { } const most_recent_notified = claims[0]["id"]; await setMostRecentNotified(most_recent_notified); - return "TEST"; } else { console.error(response.status); } + break; } } }