@@ -92,6 +92,7 @@ const CloudRecorder = () => {
9292 const recoveryAttempted = useRef ( false ) ;
9393 const screenTrackLostRef = useRef ( false ) ;
9494 const screenTrackMonitor = useRef ( null ) ;
95+ const pausedStateRef = useRef ( false ) ;
9596
9697 // This checks if the recording was previously initialized
9798 const isInit = useRef ( false ) ;
@@ -557,6 +558,14 @@ const CloudRecorder = () => {
557558 }
558559 } ;
559560
561+ const setRecordingTimingState = async ( nextState ) => {
562+ try {
563+ await chrome . storage . local . set ( nextState ) ;
564+ } catch ( err ) {
565+ console . warn ( "Failed to persist recording timing state:" , err ) ;
566+ }
567+ } ;
568+
560569 const flushPendingChunks = async ( ) => {
561570 if ( screenUploader . current ) {
562571 try {
@@ -627,6 +636,14 @@ const CloudRecorder = () => {
627636
628637 // Stop the silent audio keep-alive
629638 stopTabKeepAlive ( ) ;
639+ await setRecordingTimingState ( {
640+ recording : false ,
641+ paused : false ,
642+ recordingStartTime : null ,
643+ pausedAt : null ,
644+ totalPausedMs : 0 ,
645+ } ) ;
646+ pausedStateRef . current = false ;
630647
631648 const { projectId, multiMode, multiSceneCount, recordingToScene } =
632649 await chrome . storage . local . get ( [
@@ -1184,7 +1201,15 @@ const CloudRecorder = () => {
11841201 screenTimer . current . notificationInterval = timerInterval ;
11851202 screenTimer . current . warned = warned ;
11861203
1187- chrome . storage . local . set ( { recording : true } ) ;
1204+ const recordingStartTime = Date . now ( ) ;
1205+ await setRecordingTimingState ( {
1206+ recording : true ,
1207+ paused : false ,
1208+ recordingStartTime,
1209+ pausedAt : null ,
1210+ totalPausedMs : 0 ,
1211+ } ) ;
1212+ pausedStateRef . current = false ;
11881213 persistSessionState ( { status : "recording" } ) ;
11891214 setStarted ( true ) ;
11901215 } catch ( err ) {
@@ -1623,7 +1648,14 @@ const CloudRecorder = () => {
16231648 }
16241649 }
16251650 isFinishing . current = true ;
1626- chrome . storage . local . set ( { recording : false } ) ;
1651+ await setRecordingTimingState ( {
1652+ recording : false ,
1653+ paused : false ,
1654+ recordingStartTime : null ,
1655+ pausedAt : null ,
1656+ totalPausedMs : 0 ,
1657+ } ) ;
1658+ pausedStateRef . current = false ;
16271659 stopAllIntervals ( ) ;
16281660
16291661 await stopAllRecorders ( ) ;
@@ -2357,6 +2389,7 @@ const CloudRecorder = () => {
23572389 return true ;
23582390 } else if ( request . type === "pause-recording-tab" ) {
23592391 if ( ! isInit . current ) return ;
2392+ if ( pausedStateRef . current ) return ;
23602393
23612394 // Pause all active recorders
23622395 if (
@@ -2387,8 +2420,14 @@ const CloudRecorder = () => {
23872420 cameraTimer . current . total += now - cameraTimer . current . start ;
23882421 cameraTimer . current . paused = true ;
23892422 }
2423+ pausedStateRef . current = true ;
2424+ void setRecordingTimingState ( {
2425+ paused : true ,
2426+ pausedAt : now ,
2427+ } ) ;
23902428 } else if ( request . type === "resume-recording-tab" ) {
23912429 if ( ! isInit . current ) return ;
2430+ if ( ! pausedStateRef . current ) return ;
23922431
23932432 // Resume all paused recorders
23942433 if ( screenRecorder . current && screenRecorder . current . state === "paused" ) {
@@ -2410,6 +2449,23 @@ const CloudRecorder = () => {
24102449 cameraTimer . current . start = now ;
24112450 cameraTimer . current . paused = false ;
24122451 }
2452+ pausedStateRef . current = false ;
2453+ void ( async ( ) => {
2454+ try {
2455+ const { pausedAt, totalPausedMs } = await chrome . storage . local . get ( [
2456+ "pausedAt" ,
2457+ "totalPausedMs" ,
2458+ ] ) ;
2459+ const additional = pausedAt ? Math . max ( 0 , now - pausedAt ) : 0 ;
2460+ await setRecordingTimingState ( {
2461+ paused : false ,
2462+ pausedAt : null ,
2463+ totalPausedMs : ( totalPausedMs || 0 ) + additional ,
2464+ } ) ;
2465+ } catch ( err ) {
2466+ console . warn ( "Failed to update resume timing state:" , err ) ;
2467+ }
2468+ } ) ( ) ;
24132469 } else if ( request . type === "dismiss-recording" ) {
24142470 if ( ! isInit . current ) return ;
24152471 dismissRecording ( ) ;
0 commit comments