From b468ff9ffb83119509aeddb7a6ba76ea3f2e874e Mon Sep 17 00:00:00 2001 From: Berkay Tumal Date: Fri, 11 Oct 2024 03:05:16 +0300 Subject: [PATCH] 0.3.0 code cleanup --- src/scripts/fontStore.js | 135 ++++++++++++++-------------- src/styles.scss | 2 - src/styles/shared/internal-app.scss | 2 - src/welcome.js | 5 +- 4 files changed, 68 insertions(+), 76 deletions(-) diff --git a/src/scripts/fontStore.js b/src/scripts/fontStore.js index 78b7876..dd11eb5 100644 --- a/src/scripts/fontStore.js +++ b/src/scripts/fontStore.js @@ -2,35 +2,34 @@ const dbName = 'FontDB'; const storeName = 'fonts'; const localStorageKey = 'customFontName'; - async function initDB() { return new Promise((resolve, reject) => { - const request = indexedDB.open(dbName, 1); + const request = indexedDB.open(dbName, 1); - request.onupgradeneeded = (event) => { - const db = event.target.result; - if (!db.objectStoreNames.contains(storeName)) { - db.createObjectStore(storeName); - } - }; + request.onupgradeneeded = (event) => { + const db = event.target.result; + if (!db.objectStoreNames.contains(storeName)) { + db.createObjectStore(storeName); + } + }; - request.onsuccess = (event) => resolve(event.target.result); - request.onerror = (event) => reject(event.target.error); + request.onsuccess = (event) => resolve(event.target.result); + request.onerror = (event) => reject(event.target.error); }); } async function saveFont(fontName, fontData) { const db = await this.initDB(); return new Promise((resolve, reject) => { - const transaction = db.transaction(storeName, 'readwrite'); - const store = transaction.objectStore(storeName); - const request = store.put(fontData, fontName); - - request.onsuccess = () => { - localStorage.setItem(localStorageKey, fontName); - resolve(); - }; - request.onerror = (event) => reject(event.target.error); + const transaction = db.transaction(storeName, 'readwrite'); + const store = transaction.objectStore(storeName); + const request = store.put(fontData, fontName); + + request.onsuccess = () => { + localStorage.setItem(localStorageKey, fontName); + resolve(); + }; + request.onerror = (event) => reject(event.target.error); }); } @@ -40,34 +39,34 @@ async function loadFont() { const db = await this.initDB(); return new Promise((resolve, reject) => { - const transaction = db.transaction(storeName, 'readonly'); - const store = transaction.objectStore(storeName); - const request = store.get(fontName); - - request.onsuccess = (event) => { - const fontData = event.target.result; - if (fontData) { - // Revoke previous font URL if exists - if (window.lastFontURL) { - URL.revokeObjectURL(window.lastFontURL); - } - - const blob = new Blob([fontData], { type: 'font/ttf' }); - const fontUrl = URL.createObjectURL(blob); - - // Save the new font URL to window.lastFontURL - window.lastFontURL = fontUrl; - - // Create and inject @font-face rule - const fontFace = new FontFace('CustomFont', `url(${fontUrl})`); - fontFace.load().then(() => { - document.fonts.add(fontFace); - document.body.style.fontFamily = 'CustomFont'; - }); - } - resolve(event.target.result); - }; - request.onerror = (event) => reject(event.target.error); + const transaction = db.transaction(storeName, 'readonly'); + const store = transaction.objectStore(storeName); + const request = store.get(fontName); + + request.onsuccess = (event) => { + const fontData = event.target.result; + if (fontData) { + // Revoke previous font URL if exists + if (window.lastFontURL) { + URL.revokeObjectURL(window.lastFontURL); + } + + const blob = new Blob([fontData], { type: 'font/ttf' }); + const fontUrl = URL.createObjectURL(blob); + + // Save the new font URL to window.lastFontURL + window.lastFontURL = fontUrl; + + // Create and inject @font-face rule + const fontFace = new FontFace('CustomFont', `url(${fontUrl})`); + fontFace.load().then(() => { + document.fonts.add(fontFace); + document.body.style.fontFamily = 'CustomFont'; + }); + } + resolve(event.target.result); + }; + request.onerror = (event) => reject(event.target.error); }); } @@ -77,22 +76,22 @@ async function clearFont() { localStorage.removeItem("font") const db = await this.initDB(); return new Promise((resolve, reject) => { - const transaction = db.transaction(storeName, 'readwrite'); - const store = transaction.objectStore(storeName); - const request = store.delete(fontName); - - request.onsuccess = () => { - localStorage.removeItem(localStorageKey); - - // Revoke current Blob URL if exists - if (window.lastFontURL) { - URL.revokeObjectURL(window.lastFontURL); - window.lastFontURL = null; - } - - resolve(); - }; - request.onerror = (event) => reject(event.target.error); + const transaction = db.transaction(storeName, 'readwrite'); + const store = transaction.objectStore(storeName); + const request = store.delete(fontName); + + request.onsuccess = () => { + localStorage.removeItem(localStorageKey); + + // Revoke current Blob URL if exists + if (window.lastFontURL) { + URL.revokeObjectURL(window.lastFontURL); + window.lastFontURL = null; + } + + resolve(); + }; + request.onerror = (event) => reject(event.target.error); }); } @@ -102,12 +101,12 @@ async function hasFont() { const db = await this.initDB(); return new Promise((resolve, reject) => { - const transaction = db.transaction(storeName, 'readonly'); - const store = transaction.objectStore(storeName); - const request = store.get(fontName); + const transaction = db.transaction(storeName, 'readonly'); + const store = transaction.objectStore(storeName); + const request = store.get(fontName); - request.onsuccess = (event) => resolve(!!event.target.result); - request.onerror = (event) => reject(event.target.error); + request.onsuccess = (event) => resolve(!!event.target.result); + request.onerror = (event) => reject(event.target.error); }); } diff --git a/src/styles.scss b/src/styles.scss index 8f1e6a0..8fade08 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -40,8 +40,6 @@ img { font-family: SymbolsNerd, CustomFont, OpenSans; } - //word-spacing: -6px; - //letter-spacing: -.5px; touch-action: none; user-select: none; user-drag: none; diff --git a/src/styles/shared/internal-app.scss b/src/styles/shared/internal-app.scss index 9b881d9..0aab36a 100644 --- a/src/styles/shared/internal-app.scss +++ b/src/styles/shared/internal-app.scss @@ -38,8 +38,6 @@ img { font-family: SymbolsNerd, CustomFont, OpenSans; } - //word-spacing: -6px; - //letter-spacing: -.5px; touch-action: none; user-select: none; user-drag: none; diff --git a/src/welcome.js b/src/welcome.js index 332b602..5a50d03 100644 --- a/src/welcome.js +++ b/src/welcome.js @@ -67,7 +67,6 @@ window.goToPage = goToPage [{ title: "Next", style: "default",inline: true, action: () => { } }] );*/ //alert.querySelector("button").style.visibility = "hidden" -console.log(alert) function finishSetup() { @@ -109,7 +108,6 @@ if (updatedApp) { } var history = [] history.push(0) -console.log(setup) document.querySelector("#page-welcome button.right-btn").addEventListener("flowClick", (e) => { if (setup.update_wizard) { goToPage(1) @@ -213,8 +211,7 @@ document.querySelector("#page-readme button.right-btn").addEventListener("flowCl try { const appdetail = GrooveBoard.backendMethods.getAppDetails(defaultApps[element]) const app = searchApps[element] - console.log("app", element, app, appdetail) - if (appdetail.label = "Unknown") throw new Error("App not found for ", element); + if (appdetail.label == "Unknown") throw new Error("App not found for ", element); homeConfiguration.push({ "p": appdetail.packageName,