From 6821b3e40ff6c88bd5199a4b3aae1465e8b706c2 Mon Sep 17 00:00:00 2001 From: QCanvas Date: Tue, 30 Jul 2024 13:42:50 +1000 Subject: [PATCH] Add portable install option --- pyproject.toml | 2 +- qcanvas/util/paths.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7b67c7f..a56eab6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "qcanvas" -version = "1.0.12.dev1" +version = "1.0.12.dev2" description = "QCanvas is a desktop client for Canvas LMS." authors = ["QCanvas "] readme = "README.md" diff --git a/qcanvas/util/paths.py b/qcanvas/util/paths.py index b114055..306c23f 100644 --- a/qcanvas/util/paths.py +++ b/qcanvas/util/paths.py @@ -10,6 +10,7 @@ _logger = logging.getLogger(__name__) +_is_running_portable = Path(".portable").exists() _is_running_on_windows = platform.system() == "Windows" _is_running_on_linux = platform.system() == "Linux" _is_running_as_pyinstaller = getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS") @@ -17,7 +18,9 @@ def client_settings() -> QSettings: - if _is_running_as_pyinstaller and _is_running_on_windows: + if _is_running_portable: + return QSettings("QCanvas.ini", QSettings.Format.IniFormat) + elif _is_running_as_pyinstaller and _is_running_on_windows: return QSettings( str(platformdirs.user_documents_path() / "QCanvasTeam" / "QCanvas.ini"), QSettings.Format.IniFormat, @@ -30,10 +33,11 @@ def client_settings() -> QSettings: def root() -> Path: root_path = Path() - if _is_running_as_flatpak: - root_path = Path(os.environ["XDG_DATA_HOME"]) - elif _is_running_as_pyinstaller: - root_path = platformdirs.user_data_path("QCanvasReborn", "QCanvasTeam") + if not _is_running_portable: + if _is_running_as_flatpak: + root_path = Path(os.environ["XDG_DATA_HOME"]) + elif _is_running_as_pyinstaller: + root_path = platformdirs.user_data_path("QCanvasReborn", "QCanvasTeam") print("Root path", root_path.absolute()) _logger.debug("Root path %s", root_path.absolute())