fix: fixing stale state

This commit is contained in:
Chubby Granny Chaser
2025-02-16 05:18:08 +00:00
parent 9449d7cdcd
commit 484fa863dc
17 changed files with 50 additions and 90 deletions

View File

@@ -88,6 +88,7 @@ import "./themes/get-active-custom-theme";
import "./themes/css-injector";
import "./themes/close-editor-window";
import "./themes/import-theme";
import "./themes/toggle-custom-theme";
import { isPortableVersion } from "@main/helpers";
ipcMain.handle("ping", () => "pong");

View File

@@ -1,12 +1,12 @@
import { Theme } from "@types";
import { themes } from "@main/level/sublevels/themes";
import { registerEvent } from "../register-event";
import { themesSublevel } from "@main/level";
const addCustomTheme = async (
_event: Electron.IpcMainInvokeEvent,
theme: Theme
) => {
await themes.put(theme.id, theme);
await themesSublevel.put(theme.id, theme);
};
registerEvent("addCustomTheme", addCustomTheme);

View File

@@ -1,38 +0,0 @@
// import { themes } from "@main/level/sublevels/themes";
// import { WindowManager } from "@main/services";
// import { Theme } from "@types";
// export const handleDeepLinkTheme = async (
// themeName: string,
// authorCode: string
// ) => {
// const theme: Theme = {
// id: crypto.randomUUID(),
// name: themeName,
// isActive: false,
// author: authorCode,
// authorName: "spectre",
// code: `https://hydrathemes.shop/themes/${themeName}.css`,
// createdAt: new Date(),
// updatedAt: new Date(),
// };
// await themes.put(theme.id, theme);
// const allThemes = await themes.values().all();
// const activeTheme = allThemes.find((theme: Theme) => theme.isActive);
// if (activeTheme) {
// await themes.put(activeTheme.id, {
// ...activeTheme,
// isActive: false,
// });
// }
// WindowManager.mainWindow?.webContents.send("css-injected", theme.code);
// await themes.put(theme.id, {
// ...theme,
// isActive: true,
// });
// };

View File

@@ -1,9 +1,8 @@
import { themes } from "@main/level/sublevels/themes";
import { themesSublevel } from "@main/level";
import { registerEvent } from "../register-event";
const deleteAllCustomThemes = async (_event: Electron.IpcMainInvokeEvent) => {
console.log("sexo2");
await themes.clear();
await themesSublevel.clear();
};
registerEvent("deleteAllCustomThemes", deleteAllCustomThemes);

View File

@@ -1,11 +1,11 @@
import { themes } from "@main/level/sublevels/themes";
import { themesSublevel } from "@main/level";
import { registerEvent } from "../register-event";
const deleteCustomTheme = async (
_event: Electron.IpcMainInvokeEvent,
themeId: string
) => {
await themes.del(themeId);
await themesSublevel.del(themeId);
};
registerEvent("deleteCustomTheme", deleteCustomTheme);

View File

@@ -1,10 +1,9 @@
import { themesSublevel } from "@main/level";
import { registerEvent } from "../register-event";
import { themes } from "@main/level/sublevels/themes";
import { Theme } from "@types";
const getActiveCustomTheme = async () => {
const allThemes = await themes.values().all();
return allThemes.find((theme: Theme) => theme.isActive);
const allThemes = await themesSublevel.values().all();
return allThemes.find((theme) => theme.isActive);
};
registerEvent("getActiveCustomTheme", getActiveCustomTheme);

View File

@@ -1,8 +1,8 @@
import { themes } from "@main/level/sublevels/themes";
import { themesSublevel } from "@main/level";
import { registerEvent } from "../register-event";
const getAllCustomThemes = async (_event: Electron.IpcMainInvokeEvent) => {
return await themes.values().all();
return themesSublevel.values().all();
};
registerEvent("getAllCustomThemes", getAllCustomThemes);

View File

@@ -1,11 +1,11 @@
import { themes } from "@main/level/sublevels/themes";
import { themesSublevel } from "@main/level";
import { registerEvent } from "../register-event";
const getCustomThemeById = async (
_event: Electron.IpcMainInvokeEvent,
themeId: string
) => {
return await themes.get(themeId);
return themesSublevel.get(themeId);
};
registerEvent("getCustomThemeById", getCustomThemeById);

View File

@@ -1,13 +1,22 @@
import { themes } from "@main/level/sublevels/themes";
import { themesSublevel } from "@main/level";
import { registerEvent } from "../register-event";
import { Theme } from "@types";
const updateCustomTheme = async (
_event: Electron.IpcMainInvokeEvent,
themeId: string,
theme: Theme
code: string
) => {
await themes.put(themeId, theme);
const theme = await themesSublevel.get(themeId);
if (!theme) {
throw new Error("Theme not found");
}
await themesSublevel.put(themeId, {
...theme,
code,
updatedAt: new Date(),
});
};
registerEvent("updateCustomTheme", updateCustomTheme);

View File

@@ -3,3 +3,4 @@ export * from "./games";
export * from "./game-shop-cache";
export * from "./game-achievements";
export * from "./keys";
export * from "./themes";

View File

@@ -2,6 +2,6 @@ import type { Theme } from "@types";
import { db } from "../level";
import { levelKeys } from "./keys";
export const themes = db.sublevel<string, Theme>(levelKeys.themes, {
export const themesSublevel = db.sublevel<string, Theme>(levelKeys.themes, {
valueEncoding: "json",
});