GUI: Add some more debugging for non hidden console windows

This commit is contained in:
deajan 2025-06-12 13:07:13 +02:00
parent 524cfca026
commit 9b931847ac

View file

@ -7,11 +7,14 @@ __intname__ = "npbackup.gui.windows_gui_helper"
__author__ = "Orsiris de Jong"
__copyright__ = "Copyright (C) 2022-2025 NetInvent"
__license__ = "GPL-3.0-only"
__build__ = "2023020601"
__build__ = "2025061201"
import sys
import os
from logging import getLogger
logger = getLogger()
def handle_current_window(action: str = "minimize") -> None:
@ -29,6 +32,11 @@ def handle_current_window(action: str = "minimize") -> None:
current_executable = os.path.abspath(sys.argv[0])
# console window will have the name of current executable
hwndMain = win32gui.FindWindow(None, current_executable)
if not hwndMain:
logger.debug(
"No hwndmain found for current executable, trying foreground window"
)
hwndMain = win32gui.GetForegroundWindow()
if hwndMain:
if action == "minimize":
win32gui.ShowWindow(hwndMain, win32con.SW_MINIMIZE)
@ -38,3 +46,7 @@ def handle_current_window(action: str = "minimize") -> None:
raise ValueError(
f"Bad action parameter for handling current window: {action}"
)
else:
logger.debug(
f"No window found for current executable {current_executable}, cannot minimize/hide"
)