mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
fix: fixing stale state
This commit is contained in:
parent
9449d7cdcd
commit
484fa863dc
17 changed files with 50 additions and 90 deletions
3
src/renderer/src/declaration.d.ts
vendored
3
src/renderer/src/declaration.d.ts
vendored
|
@ -286,9 +286,10 @@ declare global {
|
|||
getAllCustomThemes: () => Promise<Theme[]>;
|
||||
deleteAllCustomThemes: () => Promise<void>;
|
||||
deleteCustomTheme: (themeId: string) => Promise<void>;
|
||||
updateCustomTheme: (themeId: string, theme: Theme) => Promise<void>;
|
||||
updateCustomTheme: (themeId: string, code: string) => Promise<void>;
|
||||
getCustomThemeById: (themeId: string) => Promise<Theme | null>;
|
||||
getActiveCustomTheme: () => Promise<Theme | null>;
|
||||
toggleCustomTheme: (themeId: string, isActive: boolean) => Promise<void>;
|
||||
onImportTheme: (
|
||||
cb: (theme: string, author: string) => void
|
||||
) => () => Electron.IpcRenderer;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
enum Feature {
|
||||
CheckDownloadWritePermission = "CHECK_DOWNLOAD_WRITE_PERMISSION",
|
||||
|
@ -6,14 +6,21 @@ enum Feature {
|
|||
}
|
||||
|
||||
export function useFeature() {
|
||||
const [features, setFeatures] = useState<string[] | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
window.electron.getFeatures().then((features) => {
|
||||
localStorage.setItem("features", JSON.stringify(features || []));
|
||||
setFeatures(features || []);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const isFeatureEnabled = (feature: Feature) => {
|
||||
const features = JSON.parse(localStorage.getItem("features") ?? "[]");
|
||||
if (!features) {
|
||||
const features = JSON.parse(localStorage.getItem("features") ?? "[]");
|
||||
return features.includes(feature);
|
||||
}
|
||||
|
||||
return features.includes(feature);
|
||||
};
|
||||
|
||||
|
|
|
@ -29,20 +29,14 @@ export const ThemeCard = ({ theme, onListUpdated }: ThemeCardProps) => {
|
|||
|
||||
if (activeTheme) {
|
||||
removeCustomCss();
|
||||
await window.electron.updateCustomTheme(activeTheme.id, {
|
||||
...activeTheme,
|
||||
isActive: false,
|
||||
});
|
||||
await window.electron.toggleCustomTheme(activeTheme.id, false);
|
||||
}
|
||||
|
||||
if (currentTheme.code) {
|
||||
injectCustomCss(currentTheme.code);
|
||||
}
|
||||
|
||||
await window.electron.updateCustomTheme(currentTheme.id, {
|
||||
...currentTheme,
|
||||
isActive: true,
|
||||
});
|
||||
await window.electron.toggleCustomTheme(currentTheme.id, true);
|
||||
|
||||
onListUpdated();
|
||||
} catch (error) {
|
||||
|
@ -53,10 +47,7 @@ export const ThemeCard = ({ theme, onListUpdated }: ThemeCardProps) => {
|
|||
const handleUnsetTheme = async () => {
|
||||
try {
|
||||
removeCustomCss();
|
||||
await window.electron.updateCustomTheme(theme.id, {
|
||||
...theme,
|
||||
isActive: false,
|
||||
});
|
||||
await window.electron.toggleCustomTheme(theme.id, false);
|
||||
|
||||
onListUpdated();
|
||||
} catch (error) {
|
||||
|
|
|
@ -47,20 +47,14 @@ export const ImportThemeModal = ({
|
|||
|
||||
if (activeTheme) {
|
||||
removeCustomCss();
|
||||
await window.electron.updateCustomTheme(activeTheme.id, {
|
||||
...activeTheme,
|
||||
isActive: false,
|
||||
});
|
||||
await window.electron.toggleCustomTheme(activeTheme.id, false);
|
||||
}
|
||||
|
||||
if (currentTheme.code) {
|
||||
injectCustomCss(currentTheme.code);
|
||||
}
|
||||
|
||||
await window.electron.updateCustomTheme(currentTheme.id, {
|
||||
...currentTheme,
|
||||
isActive: true,
|
||||
});
|
||||
await window.electron.toggleCustomTheme(currentTheme.id, true);
|
||||
onThemeImported();
|
||||
showSuccessToast(t("theme_imported"));
|
||||
onClose();
|
||||
|
|
|
@ -31,13 +31,7 @@ export default function ThemeEditor() {
|
|||
|
||||
const handleSave = useCallback(async () => {
|
||||
if (theme) {
|
||||
const updatedTheme = {
|
||||
...theme,
|
||||
code: code,
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
await window.electron.updateCustomTheme(theme.id, updatedTheme);
|
||||
await window.electron.updateCustomTheme(theme.id, code);
|
||||
setHasUnsavedChanges(false);
|
||||
|
||||
if (theme.isActive) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue