11/* eslint-disable no-shadow */
22/* eslint-disable no-underscore-dangle */
33/* eslint-disable @typescript-eslint/ban-ts-comment */
4- import { memo , useRef , useEffect } from "react" ;
4+ import { memo , useRef , useEffect , useCallback } from "react" ;
55import { useLive2DConfig } from "@/context/live2d-config-context" ;
66import { useIpcHandlers } from "@/hooks/utils/use-ipc-handlers" ;
77import { useInterrupt } from "@/hooks/utils/use-interrupt" ;
@@ -23,7 +23,7 @@ export const Live2D = memo(
2323 const { modelInfo } = useLive2DConfig ( ) ;
2424 const internalContainerRef = useRef < HTMLDivElement > ( null ) ;
2525 const { aiState } = useAiState ( ) ;
26- const { resetExpression } = useLive2DExpression ( ) ;
26+ const { resetExpression, setExpression } = useLive2DExpression ( ) ;
2727
2828 // Get canvasRef from useLive2DResize
2929 const { canvasRef } = useLive2DResize ( {
@@ -55,6 +55,28 @@ export const Live2D = memo(
5555 }
5656 } , [ aiState , modelInfo , resetExpression ] ) ;
5757
58+ // Expose setExpression for console testing
59+ useEffect ( ( ) => {
60+ const testSetExpression = ( expressionValue : string | number ) => {
61+ const lappAdapter = ( window as any ) . getLAppAdapter ?.( ) ;
62+ if ( lappAdapter ) {
63+ setExpression ( expressionValue , lappAdapter , `[Console Test] Set expression to: ${ expressionValue } ` ) ;
64+ } else {
65+ console . error ( '[Console Test] LAppAdapter not found.' ) ;
66+ }
67+ } ;
68+
69+ // Expose the function to the window object
70+ ( window as any ) . testSetExpression = testSetExpression ;
71+ console . log ( '[Debug] testSetExpression function exposed to window.' ) ;
72+
73+ // Cleanup function to remove the function from window when the component unmounts
74+ return ( ) => {
75+ delete ( window as any ) . testSetExpression ;
76+ console . log ( '[Debug] testSetExpression function removed from window.' ) ;
77+ } ;
78+ } , [ setExpression ] ) ;
79+
5880 const handlePointerDown = ( e : React . PointerEvent ) => {
5981 handlers . onMouseDown ( e ) ;
6082 } ;
0 commit comments