@@ -359,7 +359,30 @@ export function registerIpcHandlers(
359359 onRecordingStateChange ?: ( recording : boolean , sourceName : string ) => void ,
360360 switchToHud ?: ( ) => void ,
361361) {
362- ipcMain . handle ( "countdown-overlay-show" , async ( _ , value : number ) => {
362+ const countdownOverlayState = {
363+ visible : false ,
364+ value : null as number | null ,
365+ } ;
366+
367+ const flushCountdownOverlayState = ( win : BrowserWindow ) => {
368+ if ( win . isDestroyed ( ) ) {
369+ return ;
370+ }
371+
372+ win . webContents . send ( "countdown-overlay-value" , countdownOverlayState . value ) ;
373+ if ( countdownOverlayState . visible && ! win . isVisible ( ) ) {
374+ setTimeout ( ( ) => {
375+ if ( ! win . isDestroyed ( ) && countdownOverlayState . visible && ! win . isVisible ( ) ) {
376+ win . showInactive ( ) ;
377+ }
378+ } , 16 ) ;
379+ }
380+ } ;
381+
382+ ipcMain . handle ( "countdown-overlay-show" , ( _ , value : number ) => {
383+ countdownOverlayState . visible = true ;
384+ countdownOverlayState . value = value ;
385+
363386 const win = getCountdownOverlayWindow ( ) ?? createCountdownOverlayWindow ( ) ;
364387 if ( win . isDestroyed ( ) ) {
365388 return ;
@@ -368,38 +391,47 @@ export function registerIpcHandlers(
368391 if ( win . webContents . isLoading ( ) ) {
369392 win . webContents . once ( "did-finish-load" , ( ) => {
370393 if ( ! win . isDestroyed ( ) ) {
371- win . webContents . send ( "countdown-overlay-value" , value ) ;
372- win . showInactive ( ) ;
394+ flushCountdownOverlayState ( win ) ;
373395 }
374396 } ) ;
375397 } else {
376- win . webContents . send ( "countdown-overlay-value" , value ) ;
377- win . showInactive ( ) ;
398+ flushCountdownOverlayState ( win ) ;
378399 }
379400 } ) ;
380401
381402 ipcMain . handle ( "countdown-overlay-set-value" , ( _ , value : number ) => {
403+ countdownOverlayState . value = value ;
404+
382405 const win = getCountdownOverlayWindow ( ) ;
383406 if ( ! win || win . isDestroyed ( ) ) {
384407 return ;
385408 }
386409
410+ if ( win . webContents . isLoading ( ) ) {
411+ return ;
412+ }
413+
387414 win . webContents . send ( "countdown-overlay-value" , value ) ;
388415 } ) ;
389416
390417 ipcMain . handle ( "countdown-overlay-hide" , ( ) => {
418+ countdownOverlayState . visible = false ;
419+ countdownOverlayState . value = null ;
420+
391421 const win = getCountdownOverlayWindow ( ) ;
392422 if ( ! win || win . isDestroyed ( ) ) {
393423 return ;
394424 }
395425
396- win . hide ( ) ;
426+ if ( ! win . webContents . isLoading ( ) ) {
427+ win . webContents . send ( "countdown-overlay-value" , countdownOverlayState . value ) ;
428+ }
397429 } ) ;
398430
399431 ipcMain . handle ( "switch-to-hud" , ( ) => {
400432 if ( switchToHud ) switchToHud ( ) ;
401433 } ) ;
402- ipcMain . handle ( "start-new-recording" , async ( ) => {
434+ ipcMain . handle ( "start-new-recording" , ( ) => {
403435 try {
404436 setCurrentRecordingSessionState ( null ) ;
405437 if ( switchToHud ) {
0 commit comments