feat: add deep link theme import functionality

This commit is contained in:
Hachi-R
2025-02-16 01:27:15 -03:00
parent 39ceb8ee6e
commit d7d88ecb8c
8 changed files with 174 additions and 35 deletions

View File

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

View File

@@ -1,38 +1,38 @@
import { themes } from "@main/level/sublevels/themes";
import { WindowManager } from "@main/services";
import { Theme } from "@types";
// 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(),
};
// 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);
// await themes.put(theme.id, theme);
const allThemes = await themes.values().all();
const activeTheme = allThemes.find((theme: Theme) => theme.isActive);
// const allThemes = await themes.values().all();
// const activeTheme = allThemes.find((theme: Theme) => theme.isActive);
if (activeTheme) {
await themes.put(activeTheme.id, {
...activeTheme,
isActive: false,
});
}
// if (activeTheme) {
// await themes.put(activeTheme.id, {
// ...activeTheme,
// isActive: false,
// });
// }
WindowManager.mainWindow?.webContents.send("css-injected", theme.code);
// WindowManager.mainWindow?.webContents.send("css-injected", theme.code);
await themes.put(theme.id, {
...theme,
isActive: true,
});
};
// await themes.put(theme.id, {
// ...theme,
// isActive: true,
// });
// };

View File

@@ -0,0 +1,12 @@
import { registerEvent } from "../register-event";
import { WindowManager } from "@main/services";
const importTheme = async (
_event: Electron.IpcMainInvokeEvent,
theme: string,
author: string,
) => {
WindowManager.mainWindow?.webContents.send("import-theme", theme, author);
};
registerEvent("importTheme", importTheme);

View File

@@ -10,7 +10,6 @@ import { PythonRPC } from "./services/python-rpc";
import { Aria2 } from "./services/aria2";
import { db, levelKeys } from "./level";
import { loadState } from "./main";
import { handleDeepLinkTheme } from "./events/themes/deeplink";
const { autoUpdater } = updater;
@@ -93,7 +92,7 @@ const handleDeepLinkPath = (uri?: string) => {
const authorCode = url.searchParams.get("author");
if (themeName && authorCode) {
handleDeepLinkTheme(themeName, authorCode);
WindowManager.mainWindow?.webContents.send("import-theme", themeName, authorCode);
}
}
} catch (error) {