-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/custom-themes' of github.com:hydralauncher/hydr…
…a into feature/custom-themes
- Loading branch information
Showing
8 changed files
with
181 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
// }); | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/renderer/src/pages/settings/aparence/modals/import-theme-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Button } from "@renderer/components/button/button"; | ||
import { Modal } from "@renderer/components/modal/modal"; | ||
import { useTranslation } from "react-i18next"; | ||
import "./modals.scss"; | ||
import { Theme } from "@types"; | ||
import { injectCustomCss, removeCustomCss } from "@renderer/helpers"; | ||
import { useToast } from "@renderer/hooks"; | ||
|
||
interface ImportThemeModalProps { | ||
visible: boolean; | ||
onClose: () => void; | ||
onThemeImported: () => void; | ||
themeName: string; | ||
authorCode: string; | ||
} | ||
|
||
export const ImportThemeModal = ({ | ||
visible, | ||
onClose, | ||
onThemeImported, | ||
themeName, | ||
authorCode, | ||
}: ImportThemeModalProps) => { | ||
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(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal | ||
visible={visible} | ||
title={t("import_theme")} | ||
description={t("import_theme_description")} | ||
onClose={onClose} | ||
> | ||
<div className="delete-all-themes-modal__container"> | ||
<Button theme="outline" onClick={handleImportTheme}> | ||
{t("import_theme")} | ||
</Button> | ||
|
||
<Button theme="primary" onClick={onClose}> | ||
{t("cancel")} | ||
</Button> | ||
</div> | ||
</Modal> | ||
); | ||
}; |