diff --git a/sw_scripts/safari-notifications.js b/sw_scripts/safari-notifications.js index 8f420e7..b653c59 100644 --- a/sw_scripts/safari-notifications.js +++ b/sw_scripts/safari-notifications.js @@ -12,11 +12,39 @@ function decodeBase64(s) { return b; }; +async function getSettingById(id) { + return new Promise((resolve, reject) => { + let openRequest = indexedDB.open('TimeSafari'); + + openRequest.onupgradeneeded = (event) => { + // Handle database setup if necessary + let db = event.target.result; + if (!db.objectStoreNames.contains('settings')) { + db.createObjectStore('settings', { keyPath: 'id' }); + } + }; + + openRequest.onsuccess = (event) => { + let db = event.target.result; + let transaction = db.transaction('settings', 'readonly'); + let objectStore = transaction.objectStore('settings'); + let getRequest = objectStore.get(id); + + getRequest.onsuccess = () => resolve(getRequest.result); + getRequest.onerror = () => reject(getRequest.error); + }; + + openRequest.onerror = () => reject(openRequest.error); + }); +} + async function getNotificationCount() { let secret = null; if ('secret' in self) { secret = self.secret; const secretUint8Array = decodeBase64(secret); + const settings = await getSettingById(1); + const activeDid = settings['activeDid']; } return secret; }