Introducing a new way to review your PRs.

Read the announcement

junkfood02 / seal

🦭 Video/Audio Downloader for Android, based on yt-dlp

View on GitHub

13 documents · Updated Nov 16, 2026

docs / settings-and-preferences

Settings and Preferences

Overview

The settings area is a Compose navigation subgraph rooted at SettingsPage in app/…/SettingsPage.kt and wired in app/…/AppEntry.kt. SettingsPage is the hub: it renders hint cards for battery optimization and recurring sponsor prompts, then links to the covered settings routes (GENERAL_DOWNLOAD_PREFERENCES, DOWNLOAD_DIRECTORY, DOWNLOAD_FORMAT, NETWORK_PREFERENCES, TEMPLATE, APPEARANCE, INTERACTION, TROUBLESHOOTING, and ABOUT). Most subpages are standalone composables with their own scaffold/top app bar; app/…/BasePreferencePage.kt provides a shared scaffold for simpler pages such as troubleshooting.

Preference persistence is centralized in app/…/PreferenceUtil.kt. Preference keys are string constants such as EXTRACT_AUDIO, VIDEO_DIRECTORY, COOKIES, DARK_THEME_VALUE, AUTO_UPDATE, and DOWNLOAD_TYPE_INITIALIZATION. Primitive values are stored in MMKV.defaultMMKV() through extension helpers (getBoolean, updateBoolean, getInt, updateInt, getString, updateString, getLong, updateLong), with default maps for string, boolean, int, and long values. Compose pages either read/write those helpers directly or use booleanState, intState, and stringState delegates from the UI layer to keep UI state and MMKV state synchronized. PreferenceUtil.AppSettingsStateFlow is the exception for app-wide appearance state: modifyDarkThemePreference, modifyThemeSeedColor, and switchDynamicColor update both an in-memory state flow and MMKV so the theme can react immediately.

Routing under the settings graph is explicit in app/…/AppEntry.kt: Route.SETTINGS_PAGE shows the hub; Route.GENERAL_DOWNLOAD_PREFERENCES shows general download settings; Route.DOWNLOAD_DIRECTORY shows directory settings; Route.DOWNLOAD_FORMAT shows format settings; Route.SUBTITLE_PREFERENCES is reached from the format page; Route.NETWORK_PREFERENCES reaches cookie profiles and the cookie WebView generator; Route.TEMPLATE and Route.TEMPLATE_EDIT/{template_id} cover command templates; Route.APPEARANCE reaches Route.DARK_THEME and Route.LANGUAGES; Route.ABOUT reaches credits, sponsors, and auto-update; Route.TROUBLESHOOTING links back into cookie settings. Route.DOWNLOAD_DIRECTORY is registered twice in this graph, both pointing at DownloadDirectoryPreferences, so changes to that route should account for the duplicate registration.

The general/ subdirectory owns general download behavior. GeneralDownloadPreferences.kt toggles download notifications, configure-before-download, thumbnail creation, debug/detail printing, private mode, preview suppression, playlist downloads, download archive use, and SponsorBlock. It also performs a manual yt-dlp update via UpdateUtil.updateYtDlp() and shows YtdlpUpdateChannelDialog from YtdlpUpdateDialog.kt for yt-dlp stable/nightly and auto-update interval settings. AdvancedSettingDialogs.kt stores SponsorBlock categories in SPONSORBLOCK_CATEGORIES, and the download archive dialog edits the archive file returned by FileUtil.getArchiveFile() rather than an MMKV value.

The appearance/ subdirectory owns theme and language preferences. AppearancePreferences.kt previews the current look with a sample VideoCardV2, lets the user choose dynamic color or a seed/palette combination, and routes to dark theme and language pages. DarkThemePreferences.kt writes DARK_THEME_VALUE and high-contrast mode through PreferenceUtil.modifyDarkThemePreference. LanguagesPage.kt suggests locales from LocaleListCompat.getDefault(), lists all supported locales from LocaleLanguageCodeMap, saves the legacy locale integer through PreferenceUtil.saveLocalePreference, and calls setLanguage from app/…/LanguageSettings.kt. On Android 13+, it can open the system app-locale settings instead of only using in-app selection. LanguageSettings.kt is the durable mapping between Locale values and stable integer codes; its header comment says not to modify the assigned codes.

The interaction/ subdirectory currently owns the pre-download interaction default. InteractionPreferencePage.kt exposes DOWNLOAD_TYPE_INITIALIZATION; InterfaceCustomizationDialogs.kt lets the user choose between USE_PREVIOUS_SELECTION and NONE. PreferenceUtil.getDownloadType() later interprets this key and, when enabled, reads the last stored DOWNLOAD_TYPE value.

The network/ subdirectory covers transport, proxy, rate, IPv4, aria2, and cookies. NetworkPreferences.kt toggles RATE_LIMIT, CELLULAR_DOWNLOAD, ARIA2C, PROXY, FORCE_IPV4, and routes to cookie profiles. NetworkSettingDialogs.kt edits MAX_RATE, CONCURRENT, and PROXY_URL; the concurrent download slider maps to 1, 8, 16, or 24 fragments through PreferenceUtil.getConcurrentFragments(). Cookie state is split between preferences, the database, files, and Android WebView: CookieProfilesPage.kt toggles COOKIES and USER_AGENT, reads cookie profiles through CookiesViewModel, writes Netscape-format cookie file content to context.getCookiesFile(), can export that file via CreateDocument, and can clear Android CookieManager cookies. CookiesViewModel.kt persists CookieProfile rows through DatabaseUtil. WebViewPage.kt loads the editing profile URL in an Accompanist WebView, enables JavaScript/DOM storage/third-party cookies, stores the WebView user-agent string in USER_AGENT_STRING, and relies on the caller in AppEntry.kt to flush CookieManager when leaving the route.

The format/ subdirectory owns media format and subtitle preferences. DownloadFormatPreferences.kt controls audio extraction, audio conversion, metadata/artwork options, video format and resolution, MKV remuxing, format sorting, manual format selection, video clipping, and multi-audio-stream merging. It disables or forces options when custom commands, audio extraction, subtitles, or format sorting make them incompatible. SubtitlePreference.kt controls subtitle download, language selector, conversion, auto subtitles, auto-translated subtitles, embedding, and keeping subtitle sidecar files. FormatSettingDialogs.kt contains the reusable quick/settings dialogs for audio, video, format sorting, subtitle language, and subtitle conversion; it writes keys such as VIDEO_QUALITY, VIDEO_FORMAT, AUDIO_CONVERSION_FORMAT, SORTING_FIELDS, SUBTITLE_LANGUAGE, and CONVERT_SUBTITLE.

The directory/ subdirectory owns output locations and file naming. DownloadDirectoryPreferences.kt manages video/audio directories, SD-card tree URI, custom-command directory, subdirectory rules, private app directory mode, yt-dlp output template, restricted filenames, and temp-file cleanup. Directory choices are made through ActivityResultContracts.OpenDocumentTree; the selected URI is passed to App.updateDownloadDir, while visible path state is derived through FileUtil.getRealPath for non-SD-card selections. Android 11+ external-storage constraints are surfaced as a permission hint when chosen directories are outside public Downloads/Documents and Environment.isExternalStorageManager() is false. DirectoryPreferenceDialog.kt writes the website and playlist-title subdirectory toggles, while OutputTemplateDialog validates custom templates for required DownloadUtil.BASENAME and DownloadUtil.EXTENSION placeholders before saving OUTPUT_TEMPLATE and CUSTOM_OUTPUT_TEMPLATE.

The command/ subdirectory owns custom command templates. TemplateListPage.kt toggles CUSTOM_COMMAND, lists PreferenceUtil.templateListStateFlow, stores the selected template id in TEMPLATE_ID, supports multi-select deletion, and imports/exports templates as JSON via BackupUtil and DatabaseUtil. TemplateEditPage.kt creates or updates CommandTemplate database rows and can append reusable option shortcuts. CommandTemplateDialog.kt contains an older dialog-style editor plus OptionChipsDialog, which persists shortcut chips through DatabaseUtil.getShortcuts(), insertShortcut, and deleteShortcut.

The troubleshooting/ subdirectory provides fast access to fragile settings. TroubleShootingPage.kt uses BasePreferencePage, links to known Seal and yt-dlp issue trackers, duplicates the yt-dlp manual update affordance and update-channel dialog, routes to Route.COOKIE_PROFILE, and exposes RESTRICT_FILENAMES directly.

The about/ subdirectory owns product/about pages. AboutPage.kt opens repository, release, Telegram, and Matrix URLs; routes to sponsors, credits, and update settings; toggles app AUTO_UPDATE; and copies version/package reports. UpdatePage.kt controls app auto-update and channel (STABLE/PRE_RELEASE) and invokes UpdateUtil.checkForUpdate() before showing UpdateDialog. CreditsPage.kt lists third-party projects and licenses. SponsorPage.kt fetches GitHub sponsor data through SponsorUtil.getSponsors(), categorizes sponsors by tier, resets SHOW_SPONSOR_MSG, opens the GitHub Sponsors page, and shows sponsor profiles in a modal bottom sheet.

Coupling

  • If a preference key or default changes in app/…/PreferenceUtil.kt, verify every settings page that reads that key and every downstream consumer that builds download options from it. The UI often writes raw MMKV keys directly, so renaming SUBTITLE_LANGUAGE, SORTING_FIELDS, COOKIES, or directory/template keys without migration silently resets user behavior.
  • If LocaleLanguageCodeMap in app/…/LanguageSettings.kt is changed, preserve existing integer assignments and update LanguagesPage.kt expectations. Pre-Android-13 locale persistence stores only the integer code via PreferenceUtil.saveLocalePreference; reusing a code changes existing users' selected language.
  • If custom command behavior changes, verify GeneralDownloadPreferences.kt, DownloadFormatPreferences.kt, NetworkPreferences.kt, and DownloadDirectoryPreferences.kt. These pages disable many normal download settings when CUSTOM_COMMAND is enabled; a new custom-command capability may require changing several enable/disable gates.
  • If cookie storage changes, update CookieProfilesPage.kt, CookiesViewModel.kt, WebViewPage.kt, and PreferenceUtil.COOKIE_HEADER together. Cookie profiles are database rows, exported/consumed as Netscape cookie file content, and partly populated via Android CookieManager; schema or format drift will not be caught by the preference toggle alone.
  • If route constants in app/…/Route.kt change, update both the settings hub links in SettingsPage.kt and the graph entries in AppEntry.kt. Several subpages navigate by callback rather than importing routes directly, so broken links can show up only when pressing a settings item.
  • If output template constants or filename placeholder rules in DownloadUtil change, update OutputTemplateDialog in DownloadDirectoryPreferences.kt. The dialog currently enforces DownloadUtil.BASENAME and DownloadUtil.EXTENSION locally before saving the template.
  • If app or yt-dlp update policy changes, verify AboutPage.kt, UpdatePage.kt, GeneralDownloadPreferences.kt, TroubleShootingPage.kt, and YtdlpUpdateDialog.kt. App auto-update and yt-dlp auto-update use separate keys and channels (AUTO_UPDATE/UPDATE_CHANNEL vs. YT_DLP_AUTO_UPDATE/YT_DLP_UPDATE_CHANNEL/YT_DLP_UPDATE_INTERVAL).

Risks

  • app/…/WebViewPage.kt defines helpers for converting WebView cookies to the Cookie model, but the page currently does not add cookies to the view model before dismissing; it relies on CookieManager.flush() from AppEntry.kt. If cookie generation is expected to persist profile content automatically, closing the WebView can leave the database profile unchanged.
  • app/…/AppEntry.kt registers Route.DOWNLOAD_DIRECTORY twice. If one registration is edited or wrapped with different arguments/transitions, the effective route behavior may diverge from what reviewers expect.
  • app/…/DownloadDirectoryPreferences.kt validates Android 11+ directory access with string containment against public Downloads/Documents. If FileUtil.getRealPath() returns a path variant that does not contain those exact public directory strings, the page can show a permission warning or disable private-directory controls even for a usable location.
  • app/…/FormatSettingDialogs.kt opens the sorting-formats documentation URL from SubtitleLanguageDialogImpl instead of the subtitle-options URL declared in the same file. If users follow the subtitle language docs link, they are sent to format sorting docs.