@@ -11,6 +11,9 @@ import { injectCustomCss } from "@renderer/helpers";
1111import { AchievementNotificationItem } from "@renderer/components/achievements/notification/achievement-notification" ;
1212import { generateAchievementCustomNotificationTest } from "@shared" ;
1313import { CollapsedMenu } from "@renderer/components/collapsed-menu/collapsed-menu" ;
14+ import app from "../../app.scss?inline" ;
15+ import styles from "../../components/achievements/notification/achievement-notification.scss?inline" ;
16+ import root from "react-shadow" ;
1417
1518const notificationVariations = {
1619 default : "default" ,
@@ -36,14 +39,15 @@ export default function ThemeEditor() {
3639 const [ notificationAlignment , setNotificationAlignment ] =
3740 useState < AchievementCustomNotificationPosition > ( "top-left" ) ;
3841
42+ const [ shadowRootRef , setShadowRootRef ] = useState < HTMLElement | null > ( null ) ;
43+
3944 const achievementPreview = useMemo ( ( ) => {
4045 return {
41- achievement : {
42- ...generateAchievementCustomNotificationTest ( t , i18n . language ) ,
46+ achievement : generateAchievementCustomNotificationTest ( t , i18n . language , {
4347 isRare : notificationVariation === "rare" ,
4448 isHidden : notificationVariation === "hidden" ,
4549 isPlatinum : notificationVariation === "platinum" ,
46- } ,
50+ } ) ,
4751 position : notificationAlignment ,
4852 } ;
4953 } , [ t , i18n . language , notificationVariation , notificationAlignment ] ) ;
@@ -58,22 +62,28 @@ export default function ThemeEditor() {
5862 if ( loadedTheme ) {
5963 setTheme ( loadedTheme ) ;
6064 setCode ( loadedTheme . code ) ;
65+ if ( shadowRootRef ) {
66+ injectCustomCss ( loadedTheme . code , shadowRootRef ) ;
67+ }
6168 }
6269 } ) ;
6370 }
64- } , [ themeId ] ) ;
71+ } , [ themeId , shadowRootRef ] ) ;
6572
6673 const handleSave = useCallback ( async ( ) => {
6774 if ( theme ) {
6875 await window . electron . updateCustomTheme ( theme . id , code ) ;
6976 setHasUnsavedChanges ( false ) ;
7077 setIsClosingNotifications ( true ) ;
7178 setTimeout ( ( ) => {
72- injectCustomCss ( code ) ;
79+ if ( shadowRootRef ) {
80+ injectCustomCss ( code , shadowRootRef ) ;
81+ }
82+
7383 setIsClosingNotifications ( false ) ;
7484 } , 450 ) ;
7585 }
76- } , [ code , theme ] ) ;
86+ } , [ code , theme , shadowRootRef ] ) ;
7787
7888 useEffect ( ( ) => {
7989 const handleKeyDown = ( event : KeyboardEvent ) => {
@@ -185,11 +195,18 @@ export default function ThemeEditor() {
185195 />
186196
187197 < div className = "theme-editor__notification-preview-wrapper" >
188- < AchievementNotificationItem
189- position = { achievementPreview . position }
190- achievement = { achievementPreview . achievement }
191- isClosing = { isClosingNotifications }
192- />
198+ < root . div >
199+ < style type = "text/css" >
200+ { app } { styles }
201+ </ style >
202+ < section ref = { ( ref ) => setShadowRootRef ( ref ) } >
203+ < AchievementNotificationItem
204+ position = { achievementPreview . position }
205+ achievement = { achievementPreview . achievement }
206+ isClosing = { isClosingNotifications }
207+ />
208+ </ section >
209+ </ root . div >
193210 </ div >
194211 </ div >
195212 </ CollapsedMenu >
0 commit comments