From 3381ca38057a21bceb74663ec5291ca99b9bf3ce Mon Sep 17 00:00:00 2001 From: arabcoders Date: Fri, 19 Jun 2026 17:41:04 +0300 Subject: [PATCH] refactor: re-design simple mode toggle. --- FAQ.md | 25 +- app/features/ytdlp/utils.py | 5 +- app/routes/api/_static.py | 12 +- ui/app/components/AppRoot.vue | 159 +++ ui/app/components/ConnectionBanner.vue | 43 + ui/app/components/Markdown.vue | 4 + ui/app/components/SettingsPanel.vue | 97 +- ui/app/components/Simple.vue | 1576 ------------------------ ui/app/components/ThemeButton.vue | 66 + ui/app/composables/useMode.ts | 130 ++ ui/app/layouts/default.vue | 1126 +++++++---------- ui/app/middleware/mode.global.ts | 35 + ui/app/pages/index.vue | 10 - ui/app/pages/simple.vue | 1471 +++++++++++++++++++++- ui/tests/composables/useMode.test.ts | 44 + 15 files changed, 2459 insertions(+), 2344 deletions(-) create mode 100644 ui/app/components/AppRoot.vue create mode 100644 ui/app/components/ConnectionBanner.vue delete mode 100644 ui/app/components/Simple.vue create mode 100644 ui/app/components/ThemeButton.vue create mode 100644 ui/app/composables/useMode.ts create mode 100644 ui/app/middleware/mode.global.ts create mode 100644 ui/tests/composables/useMode.test.ts diff --git a/FAQ.md b/FAQ.md index 31a68061..6b7bee3a 100644 --- a/FAQ.md +++ b/FAQ.md @@ -3,6 +3,9 @@ Certain configuration values can be set via environment variables, using the `-e` parameter on the docker command line, or the `environment:` section in `compose.yaml` file. +
+Click to expand + | Environment Variable | Description | Default | | ------------------------------- | ------------------------------------------------------------------- | --------------------- | | TZ | The timezone to use for the application | `(not_set)` | @@ -61,19 +64,19 @@ or the `environment:` section in `compose.yaml` file. | YTP_THUMB_GENERATE | Enable ffmpeg thumbnail generation when no local thumbnail exists. | `true` | | YTP_THUMB_SIDECAR | Save generated thumbnails next to media instead of temp cache. | `false` | | YTP_DISABLE_EXEC | Strip some dangerous yt-dlp options. | `false` | +
> [!NOTE] -> To raise the maximum workers for specific extractor, you need to add a ENV variable that follows the pattern `YTP_MAX_WORKERS_FOR_`. -> The extractor name must be in uppercase, to know the extractor name, check the log for the specific extractor used for the download. -> The limit should not exceed the `YTP_MAX_WORKERS` value as it will be ignored. - -> [!IMPORTANT] -> The env variable `YTP_SIMPLE_MODE` only control what being displayed for first time visitor, the users can still switch between the two modes via the WebUI settings page. - -## Notes about YTP_AUTO_CLEAR_HISTORY_DAYS - -- `0` days means no automatic clearing of the download history. lowest value that will trigger the clearing is `1` day. -- This setting will **NOT** delete the downloaded files, it will only clear the history from the database. +> To raise the worker limit for a specific extractor, set an env variable using this format: `YTP_MAX_WORKERS_FOR_` +> The extractor name must be uppercase. You can find the extractor name in the download logs. This value cannot be +> higher than `YTP_MAX_WORKERS`; higher values are ignored. +> +> `YTP_SIMPLE_MODE=true` only applies when the browser has no saved layout choice yet. Users can still choose a layout in +> WebUI Settings. `/?simple=1` forces and saves Simple for that browser. +> +> `YTP_AUTO_CLEAR_HISTORY_DAYS` `0` days means no automatic clearing of the download history. lowest value that will +> trigger the clearing is `1` day. This setting will **NOT** delete the downloaded files, it will only clear the +> history from the database. # Browser extensions & bookmarklets diff --git a/app/features/ytdlp/utils.py b/app/features/ytdlp/utils.py index dd64c0f4..1751069c 100644 --- a/app/features/ytdlp/utils.py +++ b/app/features/ytdlp/utils.py @@ -131,10 +131,9 @@ class LogWrapper: if level < target.level: continue - if target.logger: - log_kwargs = {**kwargs} - log_kwargs.setdefault("stacklevel", 3) if isinstance(target.target, logging.Logger): + log_kwargs: dict[str, Any] = {**kwargs} + log_kwargs.setdefault("stacklevel", 3) target.target.log(level, msg, *args, **log_kwargs) elif callable(target.target): target.target(level, msg, *args, **kwargs) diff --git a/app/routes/api/_static.py b/app/routes/api/_static.py index 6ea4a0f0..ed807402 100644 --- a/app/routes/api/_static.py +++ b/app/routes/api/_static.py @@ -144,7 +144,7 @@ async def serve_static_file(request: Request, config: Config) -> StreamResponse: else: return web.json_response({"error": "File not found.", "file": path}, status=web.HTTPNotFound.status_code) - return web.FileResponse( + response = web.FileResponse( path=file_path, headers={ "Pragma": "public", @@ -154,6 +154,16 @@ async def serve_static_file(request: Request, config: Config) -> StreamResponse: status=web.HTTPOk.status_code, ) + if STATIC_STATE.index_file is not None and file_path == STATIC_STATE.index_file: + response.set_cookie( + name="simple_mode", + value="true" if config.simple_mode else "false", + path=config.base_path if "/" != config.base_path else "/", + samesite="Lax", + ) + + return response + def setup_static_routes(root_path: Path, config: Config) -> None: """ diff --git a/ui/app/components/AppRoot.vue b/ui/app/components/AppRoot.vue new file mode 100644 index 00000000..912498eb --- /dev/null +++ b/ui/app/components/AppRoot.vue @@ -0,0 +1,159 @@ + + + diff --git a/ui/app/components/ConnectionBanner.vue b/ui/app/components/ConnectionBanner.vue new file mode 100644 index 00000000..5f28f83b --- /dev/null +++ b/ui/app/components/ConnectionBanner.vue @@ -0,0 +1,43 @@ + + + diff --git a/ui/app/components/Markdown.vue b/ui/app/components/Markdown.vue index 06f8cb45..06ff4a57 100644 --- a/ui/app/components/Markdown.vue +++ b/ui/app/components/Markdown.vue @@ -264,6 +264,10 @@ .markdown-alert-caution { --markdown-alert-accent: var(--ui-error); } +.docs-markdown details summary { + cursor: pointer; + user-select: none; +}