mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-29 22:01:03 +00:00
feat: use shadow dom on theme editor for achievement notifications
This commit is contained in:
@@ -395,7 +395,16 @@ export class WindowManager {
|
|||||||
this.notificationWindow?.webContents.send(
|
this.notificationWindow?.webContents.send(
|
||||||
"on-achievement-unlocked",
|
"on-achievement-unlocked",
|
||||||
userPreferences.achievementCustomNotificationPosition ?? "top-left",
|
userPreferences.achievementCustomNotificationPosition ?? "top-left",
|
||||||
[generateAchievementCustomNotificationTest(t, language)]
|
[
|
||||||
|
generateAchievementCustomNotificationTest(t, language),
|
||||||
|
generateAchievementCustomNotificationTest(t, language, {
|
||||||
|
isRare: true,
|
||||||
|
isHidden: true,
|
||||||
|
}),
|
||||||
|
generateAchievementCustomNotificationTest(t, language, {
|
||||||
|
isPlatinum: true,
|
||||||
|
}),
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import { injectCustomCss } from "@renderer/helpers";
|
|||||||
import { AchievementNotificationItem } from "@renderer/components/achievements/notification/achievement-notification";
|
import { AchievementNotificationItem } from "@renderer/components/achievements/notification/achievement-notification";
|
||||||
import { generateAchievementCustomNotificationTest } from "@shared";
|
import { generateAchievementCustomNotificationTest } from "@shared";
|
||||||
import { CollapsedMenu } from "@renderer/components/collapsed-menu/collapsed-menu";
|
import { CollapsedMenu } from "@renderer/components/collapsed-menu/collapsed-menu";
|
||||||
|
import app from "../../app.scss?inline";
|
||||||
|
import styles from "../../components/achievements/notification/achievement-notification.scss?inline";
|
||||||
|
import root from "react-shadow";
|
||||||
|
|
||||||
const notificationVariations = {
|
const notificationVariations = {
|
||||||
default: "default",
|
default: "default",
|
||||||
@@ -36,14 +39,15 @@ export default function ThemeEditor() {
|
|||||||
const [notificationAlignment, setNotificationAlignment] =
|
const [notificationAlignment, setNotificationAlignment] =
|
||||||
useState<AchievementCustomNotificationPosition>("top-left");
|
useState<AchievementCustomNotificationPosition>("top-left");
|
||||||
|
|
||||||
|
const [shadowRootRef, setShadowRootRef] = useState<HTMLElement | null>(null);
|
||||||
|
|
||||||
const achievementPreview = useMemo(() => {
|
const achievementPreview = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
achievement: {
|
achievement: generateAchievementCustomNotificationTest(t, i18n.language, {
|
||||||
...generateAchievementCustomNotificationTest(t, i18n.language),
|
|
||||||
isRare: notificationVariation === "rare",
|
isRare: notificationVariation === "rare",
|
||||||
isHidden: notificationVariation === "hidden",
|
isHidden: notificationVariation === "hidden",
|
||||||
isPlatinum: notificationVariation === "platinum",
|
isPlatinum: notificationVariation === "platinum",
|
||||||
},
|
}),
|
||||||
position: notificationAlignment,
|
position: notificationAlignment,
|
||||||
};
|
};
|
||||||
}, [t, i18n.language, notificationVariation, notificationAlignment]);
|
}, [t, i18n.language, notificationVariation, notificationAlignment]);
|
||||||
@@ -58,10 +62,13 @@ export default function ThemeEditor() {
|
|||||||
if (loadedTheme) {
|
if (loadedTheme) {
|
||||||
setTheme(loadedTheme);
|
setTheme(loadedTheme);
|
||||||
setCode(loadedTheme.code);
|
setCode(loadedTheme.code);
|
||||||
|
if (shadowRootRef) {
|
||||||
|
injectCustomCss(loadedTheme.code, shadowRootRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [themeId]);
|
}, [themeId, shadowRootRef]);
|
||||||
|
|
||||||
const handleSave = useCallback(async () => {
|
const handleSave = useCallback(async () => {
|
||||||
if (theme) {
|
if (theme) {
|
||||||
@@ -69,11 +76,14 @@ export default function ThemeEditor() {
|
|||||||
setHasUnsavedChanges(false);
|
setHasUnsavedChanges(false);
|
||||||
setIsClosingNotifications(true);
|
setIsClosingNotifications(true);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
injectCustomCss(code);
|
if (shadowRootRef) {
|
||||||
|
injectCustomCss(code, shadowRootRef);
|
||||||
|
}
|
||||||
|
|
||||||
setIsClosingNotifications(false);
|
setIsClosingNotifications(false);
|
||||||
}, 450);
|
}, 450);
|
||||||
}
|
}
|
||||||
}, [code, theme]);
|
}, [code, theme, shadowRootRef]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
@@ -185,11 +195,18 @@ export default function ThemeEditor() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="theme-editor__notification-preview-wrapper">
|
<div className="theme-editor__notification-preview-wrapper">
|
||||||
<AchievementNotificationItem
|
<root.div>
|
||||||
position={achievementPreview.position}
|
<style type="text/css">
|
||||||
achievement={achievementPreview.achievement}
|
{app} {styles}
|
||||||
isClosing={isClosingNotifications}
|
</style>
|
||||||
/>
|
<section ref={(ref) => setShadowRootRef(ref)}>
|
||||||
|
<AchievementNotificationItem
|
||||||
|
position={achievementPreview.position}
|
||||||
|
achievement={achievementPreview.achievement}
|
||||||
|
isClosing={isClosingNotifications}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</root.div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CollapsedMenu>
|
</CollapsedMenu>
|
||||||
|
|||||||
@@ -179,7 +179,8 @@ export const formatDate = (
|
|||||||
|
|
||||||
export const generateAchievementCustomNotificationTest = (
|
export const generateAchievementCustomNotificationTest = (
|
||||||
t: any,
|
t: any,
|
||||||
language?: string
|
language?: string,
|
||||||
|
options: { isHidden?: boolean; isRare?: boolean; isPlatinum?: boolean } = {}
|
||||||
): AchievementNotificationInfo => {
|
): AchievementNotificationInfo => {
|
||||||
return {
|
return {
|
||||||
title: t("test_achievement_notification_title", {
|
title: t("test_achievement_notification_title", {
|
||||||
@@ -192,8 +193,8 @@ export const generateAchievementCustomNotificationTest = (
|
|||||||
}),
|
}),
|
||||||
iconUrl: "https://cdn.losbroxas.org/favicon.svg",
|
iconUrl: "https://cdn.losbroxas.org/favicon.svg",
|
||||||
points: 2440,
|
points: 2440,
|
||||||
isHidden: false,
|
isHidden: options.isHidden ?? false,
|
||||||
isRare: false,
|
isRare: options.isRare ?? false,
|
||||||
isPlatinum: false,
|
isPlatinum: options.isPlatinum ?? false,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user