fix: forced dark mode for iframe

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-04-11 16:50:43 +02:00
parent 419069376a
commit 1e9e04f829
3 changed files with 16 additions and 6 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { useApplicationState } from '../../../../hooks/common/use-application-state'
import { DarkModePreference } from '../../../../redux/dark-mode/types'
import { useSendToRenderer } from '../../../render-page/window-post-message-communicator/hooks/use-send-to-renderer'
import { CommunicationMessageType } from '../../../render-page/window-post-message-communicator/rendering-message'
import { useMemo } from 'react'
@ -14,16 +15,23 @@ import { useMemo } from 'react'
* @param forcedDarkMode Overwrites the value from the global application states if set.
* @param rendererReady Defines if the target renderer is ready
*/
export const useSendDarkModeStatusToRenderer = (forcedDarkMode: boolean | undefined, rendererReady: boolean): void => {
export const useSendDarkModeStatusToRenderer = (
rendererReady: boolean,
forcedDarkMode: DarkModePreference = DarkModePreference.AUTO
): void => {
const darkModePreference = useApplicationState((state) => state.darkMode.darkModePreference)
const darkMode = useMemo(() => {
return forcedDarkMode === DarkModePreference.AUTO ? darkModePreference : forcedDarkMode
}, [darkModePreference, forcedDarkMode])
useSendToRenderer(
useMemo(
() => ({
type: CommunicationMessageType.SET_DARKMODE,
preference: darkModePreference
preference: darkMode
}),
[darkModePreference]
[darkMode]
),
rendererReady
)

View file

@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { DarkModePreference } from '../../../redux/dark-mode/types'
import { cypressAttribute, cypressId } from '../../../utils/cypress-attribute'
import { Logger } from '../../../utils/logger'
import { isTestMode } from '../../../utils/test-modes'
@ -28,7 +29,7 @@ import React, { Fragment, useCallback, useEffect, useMemo, useRef, useState } fr
export interface RenderIframeProps extends RendererProps {
rendererType: RendererType
forcedDarkMode?: boolean
forcedDarkMode?: DarkModePreference
frameClasses?: string
onRendererStatusChange?: undefined | ((rendererReady: boolean) => void)
adaptFrameHeightToContent?: boolean
@ -144,7 +145,7 @@ export const RenderIframe: React.FC<RenderIframeProps> = ({
)
useEffectOnRenderTypeChange(rendererType, onIframeLoad)
useSendDarkModeStatusToRenderer(forcedDarkMode, rendererReady)
useSendDarkModeStatusToRenderer(rendererReady, forcedDarkMode)
useSendMarkdownToRenderer(markdownContentLines, rendererReady)
useSendScrollState(scrollState, rendererReady)

View file

@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { DarkModePreference } from '../../redux/dark-mode/types'
import { Logger } from '../../utils/logger'
import { AsyncLoadingBoundary } from '../common/async-loading-boundary/async-loading-boundary'
import { RenderIframe } from '../editor-page/renderer-pane/render-iframe'
@ -31,7 +32,7 @@ export const IntroCustomContent: React.FC = () => {
frameClasses={'w-100 overflow-y-hidden'}
markdownContentLines={value as string[]}
rendererType={RendererType.SIMPLE}
forcedDarkMode={true}
forcedDarkMode={DarkModePreference.DARK}
adaptFrameHeightToContent={true}
/>
</AsyncLoadingBoundary>