Support autostart when running from source

This commit is contained in:
DevilXD committed 2024-10-27 13:13:30 +01:00
1 parent d8687b6d1b
commit b7924231a4
2 files changed
+15 -3

No files matched your search

+6
View File
@@ -33,6 +33,11 @@ else:
# The Lib folder is also spelled in lowercase: 'lib' # The Lib folder is also spelled in lowercase: 'lib'
version_info = sys.version_info version_info = sys.version_info
SYS_SITE_PACKAGES = f"lib/python{version_info.major}.{version_info.minor}/site-packages" SYS_SITE_PACKAGES = f"lib/python{version_info.major}.{version_info.minor}/site-packages"
# scripts venv path changes depending on the system platform
if sys.platform == "win32":
SYS_SCRIPTS = "Scripts"
else:
SYS_SCRIPTS = "bin"
def _resource_path(relative_path: Path | str) -> Path: def _resource_path(relative_path: Path | str) -> Path:
@@ -90,6 +95,7 @@ WORKING_DIR = SELF_PATH.parent
# Development paths # Development paths
VENV_PATH = Path(WORKING_DIR, "env") VENV_PATH = Path(WORKING_DIR, "env")
SITE_PACKAGES_PATH = Path(VENV_PATH, SYS_SITE_PACKAGES) SITE_PACKAGES_PATH = Path(VENV_PATH, SYS_SITE_PACKAGES)
SCRIPTS_PATH = Path(VENV_PATH, SYS_SCRIPTS)
# Translations path # Translations path
# NOTE: These don't have to be available to the end-user, so the path points to the internal dir # NOTE: These don't have to be available to the end-user, so the path points to the internal dir
LANG_PATH = _resource_path("lang") LANG_PATH = _resource_path("lang")
+9 -3
View File
@@ -34,6 +34,8 @@ from exceptions import MinerException, ExitRequest
from utils import resource_path, set_root_icon, webopen, Game, _T from utils import resource_path, set_root_icon, webopen, Game, _T
from constants import ( from constants import (
SELF_PATH, SELF_PATH,
IS_PACKAGED,
SCRIPTS_PATH,
WINDOW_TITLE, WINDOW_TITLE,
LOGGING_LEVELS, LOGGING_LEVELS,
MAX_WEBSOCKETS, MAX_WEBSOCKETS,
@@ -1742,7 +1744,7 @@ class SettingsPanel:
return f'"{SELF_PATH.resolve()!s}"' return f'"{SELF_PATH.resolve()!s}"'
def _get_autostart_path(self) -> str: def _get_autostart_path(self) -> str:
flags: list[str] = [''] # this will add a space between self path and flags flags: list[str] = []
# if applicable, include the current logging level as well # if applicable, include the current logging level as well
for lvl_idx, lvl_value in LOGGING_LEVELS.items(): for lvl_idx, lvl_value in LOGGING_LEVELS.items():
if lvl_value == self._settings.logging_level: if lvl_value == self._settings.logging_level:
@@ -1751,7 +1753,10 @@ class SettingsPanel:
break break
if self._vars["tray"].get(): if self._vars["tray"].get():
flags.append("--tray") flags.append("--tray")
return self._get_self_path() + ' '.join(flags) if not IS_PACKAGED:
# non-packaged autostart has to be done through the venv path pythonw
return f"\"{SCRIPTS_PATH / 'pythonw'!s}\" {self._get_self_path()} {' '.join(flags)}"
return f"{self._get_self_path()} {' '.join(flags)}"
def _get_linux_autostart_filepath(self) -> Path: def _get_linux_autostart_filepath(self) -> Path:
autostart_folder: Path = Path("~/.config/autostart").expanduser() autostart_folder: Path = Path("~/.config/autostart").expanduser()
@@ -2407,11 +2412,12 @@ if __name__ == "__main__":
tray=False, tray=False,
priority=[], priority=[],
proxy=URL(), proxy=URL(),
alter=lambda: None,
language="English", language="English",
autostart_tray=False, autostart_tray=False,
exclude={"Lit Game"}, exclude={"Lit Game"},
tray_notifications=True, tray_notifications=True,
alter=lambda: None, logging_level=LOGGING_LEVELS[0],
priority_mode=PriorityMode.PRIORITY_ONLY, priority_mode=PriorityMode.PRIORITY_ONLY,
) )
) )