Skip to content

The only downloader you need. 下载器的集大成者。

fix(linux): use persistent path for AppImage desktop entries

XiaoYouChR88c7b6d86561
diff --git a/app/config/paths.py b/app/config/paths.py
index 4bde970b..36540d20 100644
--- a/app/config/paths.py
+++ b/app/config/paths.py
@@ -1,11 +1,19 @@
from __future__ import annotations
+import os
import shutil
import sys
from pathlib import Path
from PySide6.QtCore import QStandardPaths
+EXECUTABLE_PATH: str = (
+ os.environ["APPIMAGE"]
+ if sys.platform == "linux" and "APPIMAGE" in os.environ
+ else sys.executable if "__compiled__" in globals()
+ else str((Path(__file__).parent.parent.parent / "Ghost-Downloader-3.py").resolve())
+)
+
EXECUTABLE_DIR = (
Path(sys.executable).resolve().parent
if "__compiled__" in globals()
diff --git a/app/platform/file_association.py b/app/platform/file_association.py
index 5839ef6a..28afe7ab 100644
--- a/app/platform/file_association.py
+++ b/app/platform/file_association.py
@@ -9,7 +9,7 @@ from loguru import logger
from PySide6.QtCore import QCoreApplication
from app.config.constants import DESKTOP_ID
-from app.config.paths import EXECUTABLE_DIR
+from app.config.paths import EXECUTABLE_DIR, EXECUTABLE_PATH
if sys.platform == "win32":
import ctypes
@@ -71,7 +71,7 @@ def _registerLinux(fileTypes: list[FileType]) -> None:
desktopDir.mkdir(parents=True, exist_ok=True)
serviceDir.mkdir(parents=True, exist_ok=True)
- appPath = QCoreApplication.applicationFilePath()
+ appPath = EXECUTABLE_PATH
desktopFile.write_text(
"[Desktop Entry]\n"
diff --git a/app/platform/run_at_login.py b/app/platform/run_at_login.py
index d610b64b..b2a63464 100644
--- a/app/platform/run_at_login.py
+++ b/app/platform/run_at_login.py
@@ -6,6 +6,9 @@ from pathlib import Path
from PySide6.QtCore import QCoreApplication
+if sys.platform == "linux":
+ from app.config.paths import EXECUTABLE_PATH
+
def setRunAtLogin(enabled: bool) -> None:
if sys.platform == "win32":
@@ -72,7 +75,7 @@ def _setLinux(enabled: bool) -> None:
f"Version={VERSION}\n"
"Name=Ghost Downloader 3\n"
"Comment=A multi-threading downloader with QThread based on PySide6\n"
- f'Exec="{QCoreApplication.applicationFilePath()}" --silence\n'
+ f'Exec="{EXECUTABLE_PATH}" --silence\n'
"StartupNotify=false\n"
"Terminal=false\n",
encoding="utf-8",
diff --git a/app/platform/url_scheme.py b/app/platform/url_scheme.py
index e7ed3bfa..1f741408 100644
--- a/app/platform/url_scheme.py
+++ b/app/platform/url_scheme.py
@@ -64,6 +64,7 @@ if sys.platform == "linux":
from pathlib import Path
from app.config.constants import DESKTOP_ID
+ from app.config.paths import EXECUTABLE_PATH
def _registerLinux(scheme: str) -> None:
desktopDir = Path.home() / ".local/share/applications"
@@ -79,12 +80,11 @@ if sys.platform == "linux":
desktopFile.write_text(content, encoding="utf-8")
else:
desktopDir.mkdir(parents=True, exist_ok=True)
- appPath = QCoreApplication.applicationFilePath()
desktopFile.write_text(
"[Desktop Entry]\n"
"Type=Application\n"
"Name=Ghost Downloader\n"
- f"Exec={appPath} %U\n"
+ f"Exec={EXECUTABLE_PATH} %U\n"
"Icon=ghost-downloader\n"
"Terminal=false\n"
"Categories=Network;Utility;\n"