diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 5ee0f080..7da7d857 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -15,9 +15,11 @@ from sys import platform from time import localtime, strftime, time from typing import TYPE_CHECKING -from config import applongname, appname, appversion, appversion_nobuild, config, copyright +from constants import applongname, appname, protocolhandler_redirect -if __name__ == "__main__": +# config will now cause an appname logger to be set up, so we need the +# console redirect before this +if __name__ == '__main__': def no_other_instance_running() -> bool: # noqa: CCR001 """ Ensure only one copy of the app is running under this user account. @@ -70,7 +72,7 @@ if __name__ == "__main__": and window_title(window_handle) == applongname \ 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): + 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 ShowWindow(window_handle, SW_RESTORE) @@ -140,6 +142,11 @@ if __name__ == "__main__": # unbuffered not allowed for text in python3, so use `1 for line buffering sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='wt', buffering=1) + # TODO: Test: Make *sure* this redirect is working, else py2exe is going to cause an exit popup + +# isort: off +from config import appversion, appversion_nobuild, config, copyright +# isort: on from EDMCLogging import edmclogger, logger, logging diff --git a/config.py b/config.py index 41d56f3f..7d077d2b 100644 --- a/config.py +++ b/config.py @@ -6,9 +6,9 @@ from os.path import expanduser, dirname, exists, isdir, join, normpath from sys import platform import semantic_version +from constants import applongname, appname + # Any of these may be imported by plugins -appname = 'EDMarketConnector' -applongname = 'E:D Market Connector' appcmdname = 'EDMC' # appversion **MUST** follow Semantic Versioning rules: # diff --git a/constants.py b/constants.py new file mode 100644 index 00000000..814471e4 --- /dev/null +++ b/constants.py @@ -0,0 +1,14 @@ +""" +All constants for the application. + +This file should contain all constants that the application uses, but that +means migrating the existing ones, so for now it's only the ones that we've +found necessary to move out of other files. +""" + +# config.py +appname = 'EDMarketConnector' +applongname = 'E:D Market Connector' + +# protocol.py +protocolhandler_redirect = 'edmc://auth' diff --git a/protocol.py b/protocol.py index 408b3082..a5b42554 100644 --- a/protocol.py +++ b/protocol.py @@ -5,7 +5,9 @@ import threading import urllib.request, urllib.error, urllib.parse import sys -from config import appname, config +from EDMCLogging import get_main_logger +from config import config +from constants import protocolhandler_redirect if sys.platform == 'win32': @@ -20,7 +22,7 @@ if sys.platform == 'win32': class GenericProtocolHandler(object): def __init__(self): - self.redirect = 'edmc://auth' # Base redirection URL + self.redirect = protocolhandler_redirect # Base redirection URL self.master = None self.lastpayload = None