diff --git a/companion.py b/companion.py index 8866dc9c..c205b765 100644 --- a/companion.py +++ b/companion.py @@ -20,7 +20,6 @@ import json import numbers import os import random -import sys import threading import time import tkinter as tk @@ -39,7 +38,7 @@ from urllib3.util.retry import Retry import config as conf_module import killswitch import protocol -from config import config, user_agent +from config import config, user_agent, IS_FROZEN from edmc_data import companion_category_map as category_map from EDMCLogging import get_main_logger from monitor import monitor @@ -668,7 +667,7 @@ class Session: self.state = Session.STATE_INIT # Will try to authorize again on next login or query self.auth = None raise # Bad thing happened - if getattr(sys, 'frozen', False): + if IS_FROZEN: tk.messagebox.showinfo(title="Authentication Successful", # type: ignore message="Authentication with cAPI Successful.\n" "You may now close the Frontier login tab if it is still open.") diff --git a/config/__init__.py b/config/__init__.py index dbd1556f..9f2f3eb3 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -31,6 +31,7 @@ __all__ = [ "config", "get_update_feed", "config_logger", + "IS_FROZEN", ] import contextlib @@ -58,6 +59,7 @@ appcmdname = "EDMC" _static_appversion = "6.1.2-beta1" _cached_version: semantic_version.Version | None = None copyright = "© 2015-2019 Jonathan Harris, 2020-2026 EDCD" +IS_FROZEN = getattr(sys, 'frozen', False) update_interval = 8 * 60 * 60 # 8 Hours @@ -89,7 +91,7 @@ def git_shorthash_from_head() -> str | None: :return: str | None: None if we couldn't determine the short hash. """ - if getattr(sys, 'frozen', False) or not os.path.exists(".git"): + if IS_FROZEN or not os.path.exists(".git"): return None try: @@ -126,7 +128,7 @@ def appversion() -> semantic_version.Version: if _cached_version is not None: return _cached_version - if getattr(sys, "frozen", False): + if IS_FROZEN: # Running frozen, so we should have a .gitversion file # Yes, .parent because if frozen we're inside library.zip with open( diff --git a/config/windows.py b/config/windows.py index 947a71a0..99fe2bbe 100644 --- a/config/windows.py +++ b/config/windows.py @@ -14,7 +14,7 @@ import uuid import winreg import datetime import tomli_w -from config import config_logger +from config import config_logger, IS_FROZEN from win32comext.shell import shell from typing import Any, TYPE_CHECKING @@ -117,7 +117,7 @@ class WinConfigMinimal: def win_helper(config: Config) -> Config: """Set Environment Specific Variables for Windows Config.""" config_logger.debug("Windows environment detected. Setting platform-specific variables.") - if getattr(sys, "frozen", False): + if IS_FROZEN: config.respath_path = pathlib.Path(sys.executable).parent config.internal_plugin_dir_path = config.respath_path / "plugins" else: diff --git a/l10n.py b/l10n.py index 8fc499b5..60180229 100755 --- a/l10n.py +++ b/l10n.py @@ -19,7 +19,7 @@ from os import listdir, sep from typing import TextIO, cast from collections.abc import Iterable import pathlib -from config import config +from config import config, IS_FROZEN from EDMCLogging import get_main_logger # Note that this is also done in EDMarketConnector.py, and thus removing this here may not have a desired effect @@ -212,7 +212,7 @@ class Translations: def respath(self) -> pathlib.Path: """Path to localisation files.""" - if getattr(sys, 'frozen', False): + if IS_FROZEN: return pathlib.Path(sys.executable).parent.joinpath(LOCALISATION_DIR).resolve() if __file__: diff --git a/prefs.py b/prefs.py index 5223f3ea..84f87569 100644 --- a/prefs.py +++ b/prefs.py @@ -17,7 +17,7 @@ from collections.abc import Callable import plugin_browser import myNotebook as nb # noqa: N813 import plug -from config import appversion_nobuild, config +from config import appversion_nobuild, config, IS_FROZEN from EDMCLogging import edmclogger, get_main_logger from hotkey import hotkeymgr from l10n import translations as tr @@ -50,16 +50,15 @@ def open_folder(file: Path) -> None: def help_open_system_profiler(parent) -> None: """Open the EDMC System Profiler.""" - profiler_path = config.respath_path + if IS_FROZEN: + cmd = [str(Path(config.respath_path) / 'EDMCSystemProfiler.exe')] + else: + cmd = [sys.executable, str(Path(config.respath_path) / "EDMCSystemProfiler.py")] try: - if getattr(sys, 'frozen', False): - profiler_path /= 'EDMCSystemProfiler.exe' - subprocess.run(profiler_path, check=True) - else: - subprocess.run(['python', "EDMCSystemProfiler.py"], shell=False, check=True) + subprocess.Popen(cmd, shell=False) except Exception as err: parent.status["text"] = tr.tl("Error in System Profiler") # LANG: Catch & Record Profiler Errors - logger.exception(err) + logger.exception(f"Failed to launch System Profiler: {err}") class PrefsVersion: