Developing: Custom backgrounds

This commit is contained in:
SethBurkart123
2023-10-08 07:44:26 +11:00
parent 6cd1e59fa7
commit 44025ecfa0
12 changed files with 465 additions and 638 deletions
+34
View File
@@ -0,0 +1,34 @@
// IndexedDB utility functions
export const openDB = () => {
return new Promise<IDBDatabase>((resolve, reject) => {
const request = indexedDB.open("MyDatabase", 1);
request.onerror = () => reject(request.error);
request.onsuccess = () => resolve(request.result);
request.onupgradeneeded = (event) => {
const db = (event.target).result;
db.createObjectStore("backgrounds", { keyPath: "id" });
};
});
};
export const writeData = async (type, data) => {
return new Promise((resolve, reject) => {
openDB().then(db => {
const tx = db.transaction("backgrounds", "readwrite");
const store = tx.objectStore("backgrounds");
const request = store.put({ id: "customBackground", type, data });
tx.oncomplete = () => resolve(request.result);
tx.onerror = () => reject(tx.error);
}).catch(reject);
});
};
export const readData = async () => {
const db = await openDB();
const tx = db.transaction("backgrounds", "readonly");
const store = tx.objectStore("backgrounds");
return store.get("customBackground");
};
+2 -6
View File
@@ -4,7 +4,7 @@ import {
CreateCustomShortcutDiv,
RemoveCustomShortcutDiv,
} from "../../SEQTA.js";
import { updateDocumentColors } from "../ui/Colors.js";
import { updateAllColors } from "../ui/Colors.js";
export default class StorageListener {
constructor() {
@@ -26,11 +26,7 @@ export default class StorageListener {
handleSelectedColorChange(newColor) {
try {
chrome.storage.local.get(["DarkMode"], (result) => {
if (!result.DarkMode) {
updateDocumentColors(newColor);
}
});
updateAllColors(null, newColor);
} catch (err) {
console.error(err);
}