mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-19 01:03:57 +00:00
feat: add deep link theme import functionality
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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,
|
||||
// });
|
||||
// };
|
||||
|
||||
12
src/main/events/themes/import-theme.ts
Normal file
12
src/main/events/themes/import-theme.ts
Normal 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);
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user