From 0b87af884eddf3124506631a90e1ed0ad2bf6a19 Mon Sep 17 00:00:00 2001 From: wearrrrr Date: Wed, 17 Apr 2024 09:24:12 -0500 Subject: [PATCH] Fix bug with adding extensions to indexedDB --- src/layouts/Layout.astro | 4 ++ src/pages/[lang]/marketplace.astro | 73 +++++++++++++++--------------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 3708834..d35a620 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -160,6 +160,10 @@ const { title, optionalPreloads } = Astro.props; font-weight: 400; font-size: 40px; } + .title-desc { + color: var(--text-color); + text-align: center; + } ::-webkit-scrollbar { display: none; } diff --git a/src/pages/[lang]/marketplace.astro b/src/pages/[lang]/marketplace.astro index bdb6933..afc06d7 100644 --- a/src/pages/[lang]/marketplace.astro +++ b/src/pages/[lang]/marketplace.astro @@ -18,6 +18,7 @@ type MarketplaceItem = {

Marketplace

+

Install custom userscripts and themes for Alu.

{ Object.keys(marketplace).map((mp_item) => { @@ -117,44 +118,44 @@ type MarketplaceItem = { async function installExtension(ext: ExtensionMetadata, slug: string) { return new Promise((resolve, reject) => { const request = window.indexedDB.open("AluDB", 1); - request.onupgradeneeded = (event) => { - const db = (event.target as IDBOpenDBRequest).result; - if (!db.objectStoreNames.contains("InstalledExtensions")) { - db.createObjectStore("InstalledExtensions", { keyPath: "slug" }); - } - }; - request.onsuccess = async (event) => { - const db = (event.target as IDBOpenDBRequest).result; - const transaction = db.transaction("InstalledExtensions", "readwrite"); - const store = transaction.objectStore("InstalledExtensions"); - const extensionObject = { - slug: slug, - title: ext.title, - version: ext.version, - script: ext.script, - }; - // Check if the key already exists in the IDB - let slugCheck = store.get(slug); - slugCheck.onsuccess = (event) => { - if (slugCheck.result) { - resolve(EXT_RETURN.ALREADY_INSTALLED); - } else { - if (store.get(slug)) resolve(EXT_RETURN.ALREADY_INSTALLED); - const addRequest = store.add(extensionObject); - addRequest.onerror = (event) => { - console.error(`Error installing ${slug}!`) + request.onupgradeneeded = (event) => { + const db = (event.target as IDBOpenDBRequest).result; + if (!db.objectStoreNames.contains("InstalledExtensions")) { + db.createObjectStore("InstalledExtensions", { keyPath: "slug" }); + } + }; + request.onsuccess = async (event) => { + const db = (event.target as IDBOpenDBRequest).result; + const transaction = db.transaction("InstalledExtensions", "readwrite"); + const store = transaction.objectStore("InstalledExtensions"); + const extensionObject = { + slug: slug, + title: ext.title, + version: ext.version, + script: ext.script, + }; + // Check if the key already exists in the IDB + let slugCheck = store.get(slug); + slugCheck.onsuccess = () => { + console.log(slugCheck.result) + if (slugCheck.result != undefined) { + resolve(EXT_RETURN.ALREADY_INSTALLED); + } else { + const addRequest = store.add(extensionObject); + addRequest.onerror = () => { + console.error(`Error installing ${slug}!`) + reject(EXT_RETURN.INSTALL_FAILED); + }; + addRequest.onsuccess = () => { + resolve(EXT_RETURN.INSTALL_SUCCESS); + }; + } + }; + slugCheck.onerror = () => { + console.error("Error checking install status!"); reject(EXT_RETURN.INSTALL_FAILED); }; - addRequest.onsuccess = (event) => { - resolve(EXT_RETURN.INSTALL_SUCCESS); - }; - } - }; - slugCheck.onerror = (event) => { - console.error("Error checking install status!"); - reject(EXT_RETURN.INSTALL_FAILED); - }; - }; + }; }) }