Skip to content

Commit

Permalink
Support autostart when running from source
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilXD committed Oct 27, 2024
1 parent d8687b6 commit b792423
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
# The Lib folder is also spelled in lowercase: 'lib'
version_info = sys.version_info
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:
Expand Down Expand Up @@ -90,6 +95,7 @@ def _merge_vars(base_vars: JsonType, vars: JsonType) -> None:
# Development paths
VENV_PATH = Path(WORKING_DIR, "env")
SITE_PACKAGES_PATH = Path(VENV_PATH, SYS_SITE_PACKAGES)
SCRIPTS_PATH = Path(VENV_PATH, SYS_SCRIPTS)
# Translations path
# 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")
Expand Down
12 changes: 9 additions & 3 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
from utils import resource_path, set_root_icon, webopen, Game, _T
from constants import (
SELF_PATH,
IS_PACKAGED,
SCRIPTS_PATH,
WINDOW_TITLE,
LOGGING_LEVELS,
MAX_WEBSOCKETS,
Expand Down Expand Up @@ -1742,7 +1744,7 @@ def _get_self_path(self) -> str:
return f'"{SELF_PATH.resolve()!s}"'

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
for lvl_idx, lvl_value in LOGGING_LEVELS.items():
if lvl_value == self._settings.logging_level:
Expand All @@ -1751,7 +1753,10 @@ def _get_autostart_path(self) -> str:
break
if self._vars["tray"].get():
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:
autostart_folder: Path = Path("~/.config/autostart").expanduser()
Expand Down Expand Up @@ -2407,11 +2412,12 @@ async def main(exit_event: asyncio.Event):
tray=False,
priority=[],
proxy=URL(),
alter=lambda: None,
language="English",
autostart_tray=False,
exclude={"Lit Game"},
tray_notifications=True,
alter=lambda: None,
logging_level=LOGGING_LEVELS[0],
priority_mode=PriorityMode.PRIORITY_ONLY,
)
)
Expand Down

0 comments on commit b792423

Please sign in to comment.