Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.

Commit 91efee9

Browse files
authored
Merge pull request #169 from viu-media/feat/welcomescreen
2 parents c3ae5f9 + 69d3d2e commit 91efee9

6 files changed

Lines changed: 117 additions & 3 deletions

File tree

viu_media/cli/cli.py

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,102 @@ def cli(ctx: click.Context, **options: "Unpack[Options]"):
109109
)
110110
ctx.obj = config
111111

112+
if config.general.welcome_screen:
113+
import time
114+
115+
from ..core.constants import APP_CACHE_DIR, USER_NAME, SUPPORT_PROJECT_URL
116+
117+
last_welcomed_at_file = APP_CACHE_DIR / ".last_welcome"
118+
should_welcome = False
119+
if last_welcomed_at_file.exists():
120+
try:
121+
last_welcomed_at = float(
122+
last_welcomed_at_file.read_text(encoding="utf-8")
123+
)
124+
# runs once a day
125+
if (time.time() - last_welcomed_at) > 24 * 3600:
126+
should_welcome = True
127+
128+
except Exception as e:
129+
logger.warning(f"Failed to read welcome screen timestamp: {e}")
130+
131+
else:
132+
should_welcome = True
133+
if should_welcome:
134+
last_welcomed_at_file.write_text(str(time.time()), encoding="utf-8")
135+
136+
from rich.prompt import Confirm
137+
138+
if Confirm.ask(f"""\
139+
[green]How are you {USER_NAME} 🙂?
140+
If you like the project and are able to support it please consider buying me a coffee at {SUPPORT_PROJECT_URL}.
141+
If you would like to proceed to {SUPPORT_PROJECT_URL} select yes, otherwise enjoy your browser anime experience 😁.[/]
142+
This message can be disabled by switching off the welcome_screen option in the config and is only shown once every 24hrs.
143+
"""):
144+
from webbrowser import open
145+
146+
open(SUPPORT_PROJECT_URL)
147+
148+
if config.general.show_new_release:
149+
import time
150+
151+
from ..core.constants import APP_CACHE_DIR
152+
153+
last_release_file = APP_CACHE_DIR / ".last_release"
154+
should_print_release_notes = False
155+
if last_release_file.exists():
156+
last_release = last_release_file.read_text(encoding="utf-8")
157+
current_version = list(map(int, __version__.replace("v", "").split(".")))
158+
last_saved_version = list(
159+
map(int, last_release.replace("v", "").split("."))
160+
)
161+
if (
162+
(current_version[0] > last_saved_version[0])
163+
or (
164+
current_version[1] > last_saved_version[1]
165+
and current_version[0] == last_saved_version[0]
166+
)
167+
or (
168+
current_version[2] > last_saved_version[2]
169+
and current_version[0] == last_saved_version[0]
170+
and current_version[1] == last_saved_version[1]
171+
)
172+
):
173+
should_print_release_notes = True
174+
175+
else:
176+
should_print_release_notes = True
177+
if should_print_release_notes:
178+
last_release_file.write_text(__version__, encoding="utf-8")
179+
from .service.feedback import FeedbackService
180+
from .utils.update import check_for_updates, print_release_json, update_app
181+
from rich.prompt import Confirm
182+
183+
feedback = FeedbackService(config)
184+
feedback.info("Getting release notes...")
185+
is_latest, release_json = check_for_updates()
186+
if Confirm.ask(
187+
"Would you also like to update your config with the latest options and config notes"
188+
):
189+
import subprocess
190+
191+
cmd = ["viu", "config", "--update"]
192+
print(f"running '{' '.join(cmd)}'...")
193+
subprocess.run(cmd)
194+
195+
if is_latest:
196+
print_release_json(release_json)
197+
else:
198+
print_release_json(release_json)
199+
print("It seems theres another update waiting for you as well 😁")
200+
click.pause("Press Any Key To Proceed...")
201+
112202
if config.general.check_for_updates:
113203
import time
114204

115205
from ..core.constants import APP_CACHE_DIR
116206

117-
last_updated_at_file = APP_CACHE_DIR / "last_update"
207+
last_updated_at_file = APP_CACHE_DIR / ".last_update"
118208
should_check_for_update = False
119209
if last_updated_at_file.exists():
120210
try:

viu_media/cli/config/generate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
from pydantic_core import PydanticUndefined
1111

1212
from ...core.config import AppConfig
13-
from ...core.constants import APP_ASCII_ART, CLI_NAME, DISCORD_INVITE, REPO_HOME
13+
from ...core.constants import (
14+
APP_ASCII_ART,
15+
CLI_NAME,
16+
DISCORD_INVITE,
17+
REPO_HOME,
18+
SUPPORT_PROJECT_URL,
19+
)
1420

1521
# The header for the config file.
1622
config_asci = "\n".join(
@@ -38,6 +44,9 @@
3844
# Also join the discord server
3945
# where the anime tech community lives :)
4046
# {DISCORD_INVITE}
47+
# If you like the project and are able to support it please consider buying me a coffee at {SUPPORT_PROJECT_URL}.
48+
# 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 😂
49+
# Otherwise enjoy your terminal anime browser experience 😁
4150
#
4251
# ==============================================================================
4352
""".lstrip()

viu_media/core/config/defaults.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from ..utils import detect
33

44
# GeneralConfig
5+
GENERAL_WELCOME_SCREEN = True
56
GENERAL_PYGMENT_STYLE = "github-dark"
67
GENERAL_PREFERRED_SPINNER = "smiley"
78
GENERAL_API_CLIENT = "anilist"
@@ -32,6 +33,7 @@ def GENERAL_IMAGE_RENDERER():
3233

3334
GENERAL_MANGA_VIEWER = "feh"
3435
GENERAL_CHECK_FOR_UPDATES = True
36+
GENERAL_SHOW_NEW_RELEASE = True
3537
GENERAL_UPDATE_CHECK_INTERVAL = 12
3638
GENERAL_CACHE_REQUESTS = True
3739
GENERAL_MAX_CACHE_LIFETIME = "03:00:00"

viu_media/core/config/descriptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# GeneralConfig
22

3+
GENERAL_WELCOME_SCREEN = "Whether to enable the welcome screen, that runs once per day"
34
GENERAL_PYGMENT_STYLE = "The pygment style to use"
45
GENERAL_PREFERRED_SPINNER = "The spinner to use"
56
GENERAL_API_CLIENT = "The media database API to use (e.g., 'anilist', 'jikan')."
@@ -24,6 +25,9 @@
2425
)
2526
GENERAL_MANGA_VIEWER = "The external application to use for viewing manga pages."
2627
GENERAL_CHECK_FOR_UPDATES = "Automatically check for new versions of Viu on startup."
28+
GENERAL_SHOW_NEW_RELEASE = (
29+
"Whether to show release notes after every update when running the new version"
30+
)
2731
GENERAL_UPDATE_CHECK_INTERVAL = "The interval in hours to check for updates"
2832
GENERAL_CACHE_REQUESTS = (
2933
"Enable caching of network requests to speed up subsequent operations."

viu_media/core/config/model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ class GeneralConfig(BaseModel):
156156
default=defaults.GENERAL_API_CLIENT,
157157
description=desc.GENERAL_API_CLIENT,
158158
)
159+
welcome_screen: bool = Field(
160+
default=defaults.GENERAL_WELCOME_SCREEN, description=desc.GENERAL_WELCOME_SCREEN
161+
)
159162
provider: ProviderName = Field(
160163
default=ProviderName.ALLANIME,
161164
description=desc.GENERAL_PROVIDER,
@@ -192,6 +195,10 @@ class GeneralConfig(BaseModel):
192195
default=defaults.GENERAL_CHECK_FOR_UPDATES,
193196
description=desc.GENERAL_CHECK_FOR_UPDATES,
194197
)
198+
show_new_release: bool = Field(
199+
default=defaults.GENERAL_SHOW_NEW_RELEASE,
200+
description=desc.GENERAL_SHOW_NEW_RELEASE,
201+
)
195202
update_check_interval: float = Field(
196203
default=defaults.GENERAL_UPDATE_CHECK_INTERVAL,
197204
description=desc.GENERAL_UPDATE_CHECK_INTERVAL,

viu_media/core/constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
PROJECT_NAME = "viu-media"
1010
APP_NAME = os.environ.get(f"{CLI_NAME}_APP_NAME", CLI_NAME_LOWER)
1111

12-
USER_NAME = os.environ.get("USERNAME", "User")
12+
USER_NAME = os.environ.get("USERNAME", os.environ.get("USER", "User"))
13+
1314

1415
__version__ = metadata.version("viu_media")
1516

@@ -85,3 +86,4 @@
8586
USER_CONFIG = APP_DATA_DIR / "config.toml"
8687

8788
LOG_FILE = LOG_FOLDER / "app.log"
89+
SUPPORT_PROJECT_URL = "https://buymeacoffee.com/benexl"

0 commit comments

Comments
 (0)