Skip to content

Commit daf2c85

Browse files
committed
try to hide console window to fix windows focus issue when launching via icon click.
1 parent 9b54aa1 commit daf2c85

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,23 @@
22

33
import sys
44
import os
5+
import platform
56
import multiprocessing
67
multiprocessing.freeze_support()
78

9+
# On Windows, hide the console window when launched via icon (not from terminal).
10+
# When double-clicked, the process is the sole owner of its console.
11+
# When run from cmd/powershell, multiple processes share the console - don't hide it.
12+
if platform.system() == "Windows" and getattr(sys, 'frozen', False):
13+
import ctypes
14+
kernel32 = ctypes.windll.kernel32
15+
hwnd = kernel32.GetConsoleWindow()
16+
if hwnd:
17+
pid = ctypes.c_ulong()
18+
ctypes.windll.user32.GetWindowThreadProcessId(hwnd, ctypes.byref(pid))
19+
if pid.value == os.getpid():
20+
ctypes.windll.user32.ShowWindow(hwnd, 0) # SW_HIDE
21+
822
from pathlib import Path
923
from frontend.customhttpserver import CustomHTTPServer
1024
from frontend.api import API

0 commit comments

Comments
 (0)