11import * as React from 'react' ;
2- import { messageHandler , Messenger } from '@estruyf/vscode/dist/client/webview' ;
2+ import { Messenger } from '@estruyf/vscode/dist/client/webview' ;
33import { SlideLayout , WebViewMessages } from '../../constants' ;
44import { Markdown } from './Markdown' ;
55import { EventData } from '@estruyf/vscode' ;
66import { useScale } from '../hooks/useScale' ;
77import { useFileContents } from '../hooks/useFileContents' ;
88import useCursor from '../hooks/useCursor' ;
99import { SlideControls } from './SlideControls' ;
10+ import useTheme from '../hooks/useTheme' ;
1011
1112export interface IMarkdownPreviewProps {
1213 fileUri : string ;
@@ -18,14 +19,14 @@ export const MarkdownPreview: React.FunctionComponent<IMarkdownPreviewProps> = (
1819 webviewUrl
1920} : React . PropsWithChildren < IMarkdownPreviewProps > ) => {
2021 const { content, crntFilePath, getFileContents } = useFileContents ( ) ;
21- const [ vsCodeTheme , setVsCodeTheme ] = React . useState < any | undefined > ( undefined ) ;
2222 const [ theme , setTheme ] = React . useState < string | undefined > ( undefined ) ;
2323 const [ layout , setLayout ] = React . useState < string | undefined > ( undefined ) ;
2424 const [ bgStyles , setBgStyles ] = React . useState < any | null > ( null ) ;
2525 const [ showControls , setShowControls ] = React . useState ( false ) ;
2626 const ref = React . useRef < HTMLDivElement > ( null ) ;
2727 const slideRef = React . useRef < HTMLDivElement > ( null ) ;
2828 const { cursorVisible, resetCursorTimeout } = useCursor ( ) ;
29+ const { vsCodeTheme } = useTheme ( ) ;
2930 useScale ( ref , slideRef ) ;
3031
3132 const messageListener = ( message : MessageEvent < EventData < any > > ) => {
@@ -68,24 +69,6 @@ export const MarkdownPreview: React.FunctionComponent<IMarkdownPreviewProps> = (
6869 React . useEffect ( ( ) => {
6970 Messenger . listen ( messageListener ) ;
7071
71- messageHandler . request < any | null > ( WebViewMessages . toVscode . getTheme ) . then ( ( theme ) => {
72- if ( theme === null ) {
73- // Check if light or dark theme
74- const elm = document . body . getAttribute ( `data-vscode-theme-kind` ) ;
75- if ( elm === 'vscode-light' ) {
76- setVsCodeTheme ( "github-light" ) ;
77- } else if ( elm === 'vscode-dark' ) {
78- setVsCodeTheme ( "github-dark" ) ;
79- } else if ( elm === 'vscode-high-contrast' ) {
80- setVsCodeTheme ( "github-dark-high-contrast" ) ;
81- } else {
82- setVsCodeTheme ( "github-light-high-contrast" ) ;
83- }
84- } else {
85- setVsCodeTheme ( theme ) ;
86- }
87- } ) ;
88-
8972 return ( ) => {
9073 Messenger . unlisten ( messageListener ) ;
9174 } ;
0 commit comments