feat: add welcome screen message

This commit is contained in:
Benexl
2025-11-18 15:56:28 +03:00
parent 901c4422b5
commit f647b7419a
3 changed files with 50 additions and 3 deletions

View File

@@ -109,12 +109,48 @@ def cli(ctx: click.Context, **options: "Unpack[Options]"):
)
ctx.obj = config
if config.general.welcome_screen:
import time
from ..core.constants import APP_CACHE_DIR, USER_NAME, SUPPORT_PROJECT_URL
last_welcomed_at_file = APP_CACHE_DIR / ".last_welcome"
should_welcome = False
if last_welcomed_at_file.exists():
try:
last_welcomed_at = float(
last_welcomed_at_file.read_text(encoding="utf-8")
)
# runs once a day
if (time.time() - last_welcomed_at) > 24 * 3600:
should_welcome = True
except Exception as e:
logger.warning(f"Failed to check for update: {e}")
else:
should_welcome = True
if should_welcome:
last_welcomed_at_file.write_text(str(time.time()), encoding="utf-8")
from rich.prompt import Confirm
if Confirm.ask(f"""\
[green]How are you {USER_NAME} 🙂?
If you like the project and are able to support it please consider buying me a coffee at {SUPPORT_PROJECT_URL}.
If you would like to proceed to {SUPPORT_PROJECT_URL} select yes, otherwise enjoy your browser anime experience 😁.[/]
This messages can be disabled by switching off the welcome_screen option in the config and is only shown once every 24hrs.
"""):
from webbrowser import open
open(SUPPORT_PROJECT_URL)
if config.general.check_for_updates:
import time
from ..core.constants import APP_CACHE_DIR
last_updated_at_file = APP_CACHE_DIR / "last_update"
last_updated_at_file = APP_CACHE_DIR / ".last_update"
should_check_for_update = False
if last_updated_at_file.exists():
try:

View File

@@ -10,7 +10,13 @@ from pydantic.fields import ComputedFieldInfo, FieldInfo
from pydantic_core import PydanticUndefined
from ...core.config import AppConfig
from ...core.constants import APP_ASCII_ART, CLI_NAME, DISCORD_INVITE, REPO_HOME
from ...core.constants import (
APP_ASCII_ART,
CLI_NAME,
DISCORD_INVITE,
REPO_HOME,
SUPPORT_PROJECT_URL,
)
# The header for the config file.
config_asci = "\n".join(
@@ -38,6 +44,9 @@ CONFIG_FOOTER = f"""
# Also join the discord server
# where the anime tech community lives :)
# {DISCORD_INVITE}
# If you like the project and are able to support it please consider buying me a coffee at {SUPPORT_PROJECT_URL}.
# If you would like to connect with me join the discord server from there you can dm for hackathons, or even to tell me a joke 😂
# Otherwise enjoy your terminal anime browser experience 😁
#
# ==============================================================================
""".lstrip()

View File

@@ -9,7 +9,8 @@ CLI_NAME_LOWER = "viu"
PROJECT_NAME = "viu-media"
APP_NAME = os.environ.get(f"{CLI_NAME}_APP_NAME", CLI_NAME_LOWER)
USER_NAME = os.environ.get("USERNAME", "User")
USER_NAME = os.environ.get("USERNAME", os.environ.get("USER", "User"))
__version__ = metadata.version("viu_media")
@@ -85,3 +86,4 @@ USER_VIDEOS_DIR.mkdir(parents=True, exist_ok=True)
USER_CONFIG = APP_DATA_DIR / "config.toml"
LOG_FILE = LOG_FOLDER / "app.log"
SUPPORT_PROJECT_URL = "https://buymeacoffee.com/benexl"