Skip to content

Commit

Permalink
0.3.0 code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaytumal committed Oct 11, 2024
1 parent 44a3379 commit b468ff9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 76 deletions.
135 changes: 67 additions & 68 deletions src/scripts/fontStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand All @@ -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);
});
}

Expand All @@ -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);
});
}

Expand All @@ -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);
});
}

Expand Down
2 changes: 0 additions & 2 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/styles/shared/internal-app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b468ff9

Please sign in to comment.