Fix popup console window during notification sounds on Windows #113

Closed
opened 2026-10-27 13:43:01 +01:00 by adam · 2 comments
Owner

Currently, when a notification sound is triggered on Windows, a blank command prompt window briefly pops up (specifically when ffplay or other CLI players are executed via subprocess.run). This interrupts the user experience and briefly steals focus.
Adding just creationflags=0x08000000 (CREATE_NO_WINDOW) is sometimes ignored by ffplay. The most reliable way to completely suppress the console window on Windows is to use subprocess.STARTUPINFO() with the STARTF_USESHOWWINDOW flag alongside the CREATE_NO_WINDOW creation flag.
Suggested Fix:
In contact/message_handlers/rx_handler.py, inside the play_sound() function, replace the standard subprocess.run call with a platform-specific check:

if platform.system() == "Windows": 
                su = subprocess.STARTUPINFO()
                su.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                subprocess.run(
                    cmd, 
                    check=True, 
                    stdout=subprocess.DEVNULL, 
                    stderr=subprocess.DEVNULL, 
                    creationflags=0x08000000, 
                    startupinfo=su
                )
            else:
                subprocess.run(
                    cmd, 
                    check=True, 
                    stdout=subprocess.DEVNULL, 
                    stderr=subprocess.DEVNULL
                )

This ensures that the audio player runs completely in the background without displaying a black terminal window to the Windows user, while leaving the behavior unchanged for macOS and Linux.

Currently, when a notification sound is triggered on Windows, a blank command prompt window briefly pops up (specifically when ffplay or other CLI players are executed via subprocess.run). This interrupts the user experience and briefly steals focus. Adding just creationflags=0x08000000 (CREATE_NO_WINDOW) is sometimes ignored by ffplay. The most reliable way to completely suppress the console window on Windows is to use subprocess.STARTUPINFO() with the STARTF_USESHOWWINDOW flag alongside the CREATE_NO_WINDOW creation flag. Suggested Fix: In contact/message_handlers/rx_handler.py, inside the play_sound() function, replace the standard subprocess.run call with a platform-specific check: ``` if platform.system() == "Windows": su = subprocess.STARTUPINFO() su.dwFlags |= subprocess.STARTF_USESHOWWINDOW subprocess.run( cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, creationflags=0x08000000, startupinfo=su ) else: subprocess.run( cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) ``` This ensures that the audio player runs completely in the background without displaying a black terminal window to the Windows user, while leaving the behavior unchanged for macOS and Linux. <!-- github-sync-id:5928604105 -->
adam closed this issue 2026-10-27 13:43:02 +01:00
Author
Owner

Looks good, please submit a PR and I'll review.

Looks good, please submit a PR and I'll review. <!-- github-comment-id:6275540676 -->
Author
Owner

closed by #320

closed by #320 <!-- github-comment-id:6278594391 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/contact#113