From 7c91288e6efc3405bbf553af4e7f1311ddbd011f Mon Sep 17 00:00:00 2001 From: Benexl Date: Sun, 13 Jul 2025 13:19:50 +0300 Subject: [PATCH] feat: improve desktop entry generation --- fastanime/cli/commands/config.py | 16 +++++++--------- fastanime/core/constants.py | 3 +++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/fastanime/cli/commands/config.py b/fastanime/cli/commands/config.py index e7cc99c..5aee4fb 100644 --- a/fastanime/cli/commands/config.py +++ b/fastanime/cli/commands/config.py @@ -105,7 +105,6 @@ def _generate_desktop_entry(): """ Generates a desktop entry for FastAnime. """ - import os import shutil import sys from pathlib import Path @@ -115,11 +114,11 @@ def _generate_desktop_entry(): from rich.prompt import Confirm from ... import __version__ - from ...core.constants import APP_NAME, ICON_PATH, PLATFORM + from ...core.constants import ICON_PATH, PLATFORM, PROJECT_NAME, USER_APPLICATIONS - FASTANIME_EXECUTABLE = shutil.which("fastanime") - if FASTANIME_EXECUTABLE: - cmds = f"{FASTANIME_EXECUTABLE} --rofi anilist" + EXECUTABLE = shutil.which("fastanime") + if EXECUTABLE: + cmds = f"{EXECUTABLE} --rofi anilist" else: cmds = f"{sys.executable} -m fastanime --rofi anilist" @@ -136,7 +135,7 @@ def _generate_desktop_entry(): desktop_entry = dedent( f""" [Desktop Entry] - Name={APP_NAME} + Name={PROJECT_NAME} Type=Application version={__version__} Path={Path().home()} @@ -147,9 +146,8 @@ def _generate_desktop_entry(): Categories=Entertainment """ ) - base = os.path.expanduser("~/.local/share/applications") - desktop_entry_path = os.path.join(base, f"{APP_NAME}.desktop") - if os.path.exists(desktop_entry_path): + desktop_entry_path = USER_APPLICATIONS / f"{PROJECT_NAME}.desktop" + if desktop_entry_path.exists(): if not Confirm.ask( f"The file already exists {desktop_entry_path}; or would you like to rewrite it", default=False, diff --git a/fastanime/core/constants.py b/fastanime/core/constants.py index a88cddd..a06b306 100644 --- a/fastanime/core/constants.py +++ b/fastanime/core/constants.py @@ -63,6 +63,9 @@ else: xdg_videos_dir = Path(os.environ.get("XDG_VIDEOS_DIR", Path.home() / "Videos")) USER_VIDEOS_DIR = xdg_videos_dir / APP_NAME +USER_APPLICATIONS = Path.home() / ".local" / "share" / "applications" + +# USER_APPLICATIONS.mkdir(parents=True,exist_ok=True) APP_DATA_DIR.mkdir(parents=True, exist_ok=True) APP_CACHE_DIR.mkdir(parents=True, exist_ok=True) USER_VIDEOS_DIR.mkdir(parents=True, exist_ok=True)