@@ -8,15 +8,15 @@ export const useScreenRecord = (
8
8
watermarkText = `© ${ new Date ( ) . getFullYear ( ) } UI-TARS Desktop` ,
9
9
) => {
10
10
const [ isRecording , setIsRecording ] = useState ( false ) ;
11
- const [ recordedChunks , setRecordedChunks ] = useState < BlobPart [ ] > ( [ ] ) ;
11
+ const recordedChunksRef = useRef < BlobPart [ ] > ( [ ] ) ;
12
12
const mediaRecorderRef = useRef < MediaRecorder | null > ( null ) ;
13
13
const streamRef = useRef < MediaStream | null > ( null ) ;
14
14
const canvasRef = useRef < HTMLCanvasElement > ( null ) ;
15
15
const videoRef = useRef < HTMLVideoElement > ( null ) ;
16
16
17
17
const startRecording = async ( ) => {
18
18
try {
19
- setRecordedChunks ( [ ] ) ;
19
+ recordedChunksRef . current = [ ] ;
20
20
21
21
const { screenWidth, screenHeight } =
22
22
await window . electron . ipcRenderer . invoke ( 'get-screen-size' ) ;
@@ -91,7 +91,7 @@ export const useScreenRecord = (
91
91
92
92
recorder . onstop = ( ) => {
93
93
clearInterval ( drawInterval ) ;
94
- setRecordedChunks ( chunks ) ;
94
+ recordedChunksRef . current = chunks ;
95
95
} ;
96
96
97
97
mediaRecorderRef . current = recorder ;
@@ -105,7 +105,7 @@ export const useScreenRecord = (
105
105
106
106
useEffect ( ( ) => {
107
107
return ( ) => {
108
- setRecordedChunks ( [ ] ) ;
108
+ recordedChunksRef . current = [ ] ;
109
109
if ( mediaRecorderRef . current ) {
110
110
mediaRecorderRef . current . stop ( ) ;
111
111
}
@@ -127,9 +127,9 @@ export const useScreenRecord = (
127
127
} ;
128
128
129
129
const saveRecording = ( ) => {
130
- if ( recordedChunks . length === 0 ) return ;
130
+ if ( recordedChunksRef . current . length === 0 ) return ;
131
131
132
- const blob = new Blob ( recordedChunks , { type : 'video/mp4' } ) ;
132
+ const blob = new Blob ( recordedChunksRef . current , { type : 'video/mp4' } ) ;
133
133
const url = URL . createObjectURL ( blob ) ;
134
134
const a = document . createElement ( 'a' ) ;
135
135
a . href = url ;
@@ -139,7 +139,7 @@ export const useScreenRecord = (
139
139
URL . revokeObjectURL ( url ) ;
140
140
} ;
141
141
142
- const canSaveRecording = ! isRecording && recordedChunks . length > 0 ;
142
+ const canSaveRecording = ! isRecording && recordedChunksRef . current . length > 0 ;
143
143
144
144
return {
145
145
isRecording,
0 commit comments