diff --git a/src/main/events/themes/import-theme.ts b/src/main/events/themes/import-theme.ts index a5b06287..50ef940f 100644 --- a/src/main/events/themes/import-theme.ts +++ b/src/main/events/themes/import-theme.ts @@ -4,7 +4,7 @@ import { WindowManager } from "@main/services"; const importTheme = async ( _event: Electron.IpcMainInvokeEvent, theme: string, - author: string, + author: string ) => { WindowManager.mainWindow?.webContents.send("import-theme", theme, author); }; diff --git a/src/main/index.ts b/src/main/index.ts index b289a442..919e48c6 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -92,7 +92,11 @@ const handleDeepLinkPath = (uri?: string) => { const authorCode = url.searchParams.get("author"); if (themeName && authorCode) { - WindowManager.mainWindow?.webContents.send("import-theme", themeName, authorCode); + WindowManager.mainWindow?.webContents.send( + "import-theme", + themeName, + authorCode + ); } } } catch (error) { diff --git a/src/preload/index.ts b/src/preload/index.ts index a247bd17..16415b89 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -361,8 +361,11 @@ contextBridge.exposeInMainWorld("electron", { ipcRenderer.invoke("getCustomThemeById", themeId), getActiveCustomTheme: () => ipcRenderer.invoke("getActiveCustomTheme"), onImportTheme: (cb: (theme: string, author: string) => void) => { - const listener = (_event: Electron.IpcRendererEvent, theme: string, author: string) => - cb(theme, author); + const listener = ( + _event: Electron.IpcRendererEvent, + theme: string, + author: string + ) => cb(theme, author); ipcRenderer.on("import-theme", listener); return () => ipcRenderer.removeListener("import-theme", listener); }, diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index 0fd6370c..55a94e21 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -39,13 +39,13 @@ export interface AppProps { export function App() { const contentRef = useRef(null); const { updateLibrary, library } = useLibrary(); - const [isImportThemeModalVisible, setIsImportThemeModalVisible] = useState(false); + const [isImportThemeModalVisible, setIsImportThemeModalVisible] = + useState(false); const [importTheme, setImportTheme] = useState<{ theme: string; author: string; } | null>(null); - const { t } = useTranslation("app"); const { updateRepacks } = useRepacks(); diff --git a/src/renderer/src/pages/settings/aparence/modals/import-theme-modal.tsx b/src/renderer/src/pages/settings/aparence/modals/import-theme-modal.tsx index 8431a647..65eea7c3 100644 --- a/src/renderer/src/pages/settings/aparence/modals/import-theme-modal.tsx +++ b/src/renderer/src/pages/settings/aparence/modals/import-theme-modal.tsx @@ -7,86 +7,86 @@ import { injectCustomCss, removeCustomCss } from "@renderer/helpers"; import { useToast } from "@renderer/hooks"; interface ImportThemeModalProps { - visible: boolean; - onClose: () => void; - onThemeImported: () => void; - themeName: string; - authorCode: string; + visible: boolean; + onClose: () => void; + onThemeImported: () => void; + themeName: string; + authorCode: string; } export const ImportThemeModal = ({ - visible, - onClose, - onThemeImported, - themeName, - authorCode, + visible, + onClose, + onThemeImported, + themeName, + authorCode, }: ImportThemeModalProps) => { - const { t } = useTranslation("settings"); - const { showSuccessToast, showErrorToast } = useToast(); + const { t } = useTranslation("settings"); + const { showSuccessToast, showErrorToast } = useToast(); - const handleImportTheme = async () => { - 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(), - }; - - try { - await window.electron.addCustomTheme(theme); - - const currentTheme = await window.electron.getCustomThemeById(theme.id); - - if (!currentTheme) return; - - const activeTheme = await window.electron.getActiveCustomTheme(); - - if (activeTheme) { - removeCustomCss(); - await window.electron.updateCustomTheme(activeTheme.id, { - ...activeTheme, - isActive: false, - }); - } - - if (currentTheme.code) { - injectCustomCss(currentTheme.code); - } - - await window.electron.updateCustomTheme(currentTheme.id, { - ...currentTheme, - isActive: true, - }); - onThemeImported(); - showSuccessToast(t("theme_imported")); - onClose(); - } catch (error) { - console.error(error); - showErrorToast(t("error_importing_theme")); - onClose(); - } + const handleImportTheme = async () => { + 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(), }; - return ( - -
- + try { + await window.electron.addCustomTheme(theme); - -
-
- ); + const currentTheme = await window.electron.getCustomThemeById(theme.id); + + if (!currentTheme) return; + + const activeTheme = await window.electron.getActiveCustomTheme(); + + if (activeTheme) { + removeCustomCss(); + await window.electron.updateCustomTheme(activeTheme.id, { + ...activeTheme, + isActive: false, + }); + } + + if (currentTheme.code) { + injectCustomCss(currentTheme.code); + } + + await window.electron.updateCustomTheme(currentTheme.id, { + ...currentTheme, + isActive: true, + }); + onThemeImported(); + showSuccessToast(t("theme_imported")); + onClose(); + } catch (error) { + console.error(error); + showErrorToast(t("error_importing_theme")); + onClose(); + } + }; + + return ( + +
+ + + +
+
+ ); };