feat: improve desktop entry generation

This commit is contained in:
Benexl
2025-07-13 13:19:50 +03:00
parent de2ba342ad
commit 7c91288e6e
2 changed files with 10 additions and 9 deletions

View File

@@ -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,

View File

@@ -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)