@@ -380,8 +380,14 @@ <h3>
380380
381381 // Send immediate heartbeat first to prevent freeze at zero
382382 if ( methodFromStart !== 3 ) {
383- let remainingMs = ( ( method === 1 ) ? workTime : restTime ) - new Date ( ) . getTime ( ) + startTime -
384- ( times === 0 ? firstTimeDiscount : 0 ) ;
383+ let remainingMs ;
384+ if ( ! isClockWorking ) {
385+ // When paused, use the stored time values to avoid time drift
386+ remainingMs = ( hours * 3600 + minutes * 60 + seconds ) * 1000 ;
387+ } else {
388+ remainingMs = ( ( method === 1 ) ? workTime : restTime ) - new Date ( ) . getTime ( ) + startTime -
389+ ( times === 0 ? firstTimeDiscount : 0 ) ;
390+ }
385391 if ( remainingMs < 0 ) remainingMs = 0 ;
386392 ipc . send ( "floating-heartbeat" , {
387393 remainingSeconds : Math . floor ( remainingMs / 1000 ) ,
@@ -404,8 +410,14 @@ <h3>
404410 if ( methodFromStart !== 3 )
405411 for ( let floatingRepeater = 1 ; floatingRepeater < 5 ; floatingRepeater ++ )
406412 setTimeout ( function ( ) {
407- let remainingMs = ( ( method === 1 ) ? workTime : restTime ) - new Date ( ) . getTime ( ) + startTime -
408- ( times === 0 ? firstTimeDiscount : 0 ) ;
413+ let remainingMs ;
414+ if ( ! isClockWorking ) {
415+ // When paused, use the stored time values to avoid time drift
416+ remainingMs = ( hours * 3600 + minutes * 60 + seconds ) * 1000 ;
417+ } else {
418+ remainingMs = ( ( method === 1 ) ? workTime : restTime ) - new Date ( ) . getTime ( ) + startTime -
419+ ( times === 0 ? firstTimeDiscount : 0 ) ;
420+ }
409421 if ( remainingMs < 0 ) remainingMs = 0 ;
410422 ipc . send ( "floating-heartbeat" , {
411423 remainingSeconds : Math . floor ( remainingMs / 1000 ) ,
@@ -848,6 +860,15 @@ <h3>
848860 ipc . on ( 'remote-control-msg' , function ( event , message ) {
849861 if ( hasSoonFinishTipPosted ) return ; // ban stopping after tip posted
850862
863+ if ( message && typeof message === "object" && message . type === "stop-set" ) {
864+ let desiredWorking = ! ! message . desiredWorking ;
865+ if ( ( desiredWorking && ! isClockWorking ) || ( ! desiredWorking && isClockWorking ) ) {
866+ stopper ( ) ;
867+ }
868+ ipc . send ( "floating-conversation" , { topic : "stop-sync" , val : isClockWorking } ) ;
869+ return ;
870+ }
871+
851872 if ( message === "skipper" ) skipper ( ) ;
852873 else if ( message === "back" ) {
853874 if ( methodFromStart === 3 || ( ( ! store . get ( "islocked" ) ) && ( ! isFeatureDisabled ( store . get ( 'disable-backing' ) , method ) ) ) )
@@ -903,6 +924,25 @@ <h3>
903924 msg : i18n . __ ( 'alarm-for-not-using-wnr-dialog-box-content' )
904925 } ) ;
905926 } , 600000 ) ;
927+ if ( hasFloating ) {
928+ if ( methodFromStart === 3 ) {
929+ ipc . send ( "floating-heartbeat" , {
930+ remainingSeconds : hours * 3600 + minutes * 60 + seconds ,
931+ totalMs : 0 ,
932+ method : 3 ,
933+ isWorking : isClockWorking ,
934+ isOnlyRest : isOnlyRest
935+ } ) ;
936+ } else {
937+ ipc . send ( "floating-heartbeat" , {
938+ remainingSeconds : hours * 3600 + minutes * 60 + seconds ,
939+ totalMs : ( method === 1 ) ? workTime : restTime ,
940+ method : method ,
941+ isWorking : isClockWorking ,
942+ isOnlyRest : isOnlyRest
943+ } ) ;
944+ }
945+ }
906946 } else {
907947 if ( pauseInt != null )
908948 window . clearTimeout ( pauseInt ) ;
@@ -918,6 +958,25 @@ <h3>
918958 isClockWorking = 1 ; //to restart
919959 ipc . send ( "tray-image-change" , "start" ) ;
920960 if ( pausingTimeout ) window . clearInterval ( pausingTimeout ) ;
961+ if ( hasFloating ) {
962+ if ( methodFromStart === 3 ) {
963+ ipc . send ( "floating-heartbeat" , {
964+ remainingSeconds : hours * 3600 + minutes * 60 + seconds ,
965+ totalMs : 0 ,
966+ method : 3 ,
967+ isWorking : isClockWorking ,
968+ isOnlyRest : isOnlyRest
969+ } ) ;
970+ } else {
971+ ipc . send ( "floating-heartbeat" , {
972+ remainingSeconds : hours * 3600 + minutes * 60 + seconds ,
973+ totalMs : ( method === 1 ) ? workTime : restTime ,
974+ method : method ,
975+ isWorking : isClockWorking ,
976+ isOnlyRest : isOnlyRest
977+ } ) ;
978+ }
979+ }
921980 }
922981 }
923982
0 commit comments