From 50d9e41d47e52dc3aaa6fc9417218ac2bc17cd8a Mon Sep 17 00:00:00 2001 From: Bruno Marques Date: Mon, 22 Jul 2024 10:25:25 +0100 Subject: [PATCH] Fixed pywin32 call --- EDMarketConnector.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 4139621fe..0eef0614c 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -267,7 +267,7 @@ def handle_edmc_callback_or_foregrounding() -> None: # noqa: CCR001 # If *this* instance hasn't locked, then another already has and we # now need to do the edmc:// checks for auth callback if locked != JournalLockResult.LOCKED: - from ctypes import windll, create_unicode_buffer, WINFUNCTYPE + from ctypes import windll, WINFUNCTYPE from ctypes.wintypes import BOOL, HWND, LPARAM import win32gui import win32api @@ -302,25 +302,22 @@ def enumwindowsproc(window_handle, l_param): # noqa: CCR001 :param l_param: The second parameter to the EnumWindows() call. :return: False if we found a match, else True to continue iteration """ - # class name limited to 256 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576 - cls = create_unicode_buffer(257) # This conditional is exploded to make debugging slightly easier - if win32gui.GetClassName(window_handle, cls, 257): - if cls.value == 'TkTopLevel': - if window_title(window_handle) == applongname: - if GetProcessHandleFromHwnd(window_handle): - # If GetProcessHandleFromHwnd succeeds then the app is already running as this user - if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler_redirect): - CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) - # Wait for it to be responsive to avoid ShellExecute recursing - win32gui.ShowWindow(window_handle, win32con.SW_RESTORE) - win32api.ShellExecute(0, None, sys.argv[1], None, None, win32con.SW_RESTORE) - - else: - ShowWindowAsync(window_handle, win32con.SW_RESTORE) - win32gui.SetForegroundWindow(window_handle) - - return False # Indicate window found, so stop iterating + if win32gui.GetClassName(window_handle) == 'TkTopLevel': + if window_title(window_handle) == applongname: + if GetProcessHandleFromHwnd(window_handle): + # If GetProcessHandleFromHwnd succeeds then the app is already running as this user + if len(sys.argv) > 1 and sys.argv[1].startswith(protocolhandler_redirect): + CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) + # Wait for it to be responsive to avoid ShellExecute recursing + win32gui.ShowWindow(window_handle, win32con.SW_RESTORE) + win32api.ShellExecute(0, None, sys.argv[1], None, None, win32con.SW_RESTORE) + + else: + ShowWindowAsync(window_handle, win32con.SW_RESTORE) + win32gui.SetForegroundWindow(window_handle) + + return False # Indicate window found, so stop iterating # Indicate that EnumWindows() needs to continue iterating return True # Do not remove, else this function as a callback breaks