Skip to content

Commit 3ca6932

Browse files
committed
Fix: Prevent console window flashing on Windows
- Add CREATE_NO_WINDOW flag to all subprocess calls on Windows - Add --noconsole flag to PyInstaller for extra safety - Fixes brief command prompt window appearing on startup Changes: - network_monitor.py: Use CREATE_NO_WINDOW for ping and ipconfig - build.py: Add --noconsole flag for Windows builds
1 parent 800770e commit 3ca6932

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def build_executable():
8585
'--name=AMI',
8686
'--windowed', # No console window
8787
'--onefile', # Single executable
88+
'--noconsole' if sys.platform == 'win32' else '', # Extra flag for Windows
8889
f'--icon={icon_file}' if icon_file.exists() else '',
8990
'--add-data', f'{config_file}{os.pathsep}.', # Include config.json
9091
f'--paths={src_dir}', # Add src directory to Python path

src/network_monitor.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ def ping_host(self, host: str, timeout: int = 5) -> PingResult:
103103
timeout_ms = str(timeout * 1000)
104104

105105
# Run ping command
106+
kwargs = {
107+
'capture_output': True,
108+
'text': True,
109+
}
110+
if sys.platform == 'win32':
111+
kwargs['creationflags'] = subprocess.CREATE_NO_WINDOW
106112
result = subprocess.run(
107113
['ping', param, '1', timeout_param, timeout_ms, host],
108-
capture_output=True,
109-
text=True,
114+
**kwargs,
110115
timeout=timeout + 1
111116
)
112117

@@ -416,7 +421,7 @@ def _detect_vpn(self, isp_text: Optional[str]) -> Tuple[bool, str]:
416421
pass
417422
elif plat == 'win32':
418423
try:
419-
out = subprocess.check_output(['ipconfig', '/all'], text=True, timeout=3, creationflags=0)
424+
out = subprocess.check_output(['ipconfig', '/all'], text=True, timeout=3, creationflags=subprocess.CREATE_NO_WINDOW)
420425
patterns = ['TAP', 'TUN', 'WireGuard', 'PPP adapter', 'NordLynx']
421426
if any(pat.lower() in out.lower() for pat in patterns):
422427
self._last_vpn_status = (True, 'adapter')

0 commit comments

Comments
 (0)