From 3a57128e287e4c551a82b260faa940b7f0a9bfcd Mon Sep 17 00:00:00 2001 From: Athanasius Date: Wed, 14 Oct 2020 20:00:03 +0100 Subject: [PATCH] EDMarketConnector: Care about "are we already running?" check 1) Don't log in this check, we're a different process. 2) But we've stomped the plain log file already! 3) Python 3.8.6 seems to not like sys.exit(0) from that ctypes code, so `return False` instead and check the return from EnumWindows(). --- EDMarketConnector.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 08070efb..5ad83f88 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -1357,8 +1357,8 @@ def enforce_single_instance() -> None: # noqa: CCR001 and 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): - logger.debug('Browser invoked us directly with auth response. ' - 'Forwarding the response to the other app instance.') + # logger.debug('Browser invoked us directly with auth response. ' + # 'Forwarding the response to the other app instance.') CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) # Wait for it to be responsive to avoid ShellExecute recursing ShowWindow(window_handle, SW_RESTORE) @@ -1368,12 +1368,13 @@ def enforce_single_instance() -> None: # noqa: CCR001 ShowWindowAsync(window_handle, SW_RESTORE) SetForegroundWindow(window_handle) - logger.info(f'A running {applongname} process was found, exiting.') - sys.exit(0) + # logger.info(f'A running {applongname} process was found, exiting.') + return False return True - EnumWindows(enumwindowsproc, 0) + if not EnumWindows(enumwindowsproc, 0): + sys.exit(0) def test_logging() -> None: