package eu.friedcutlet.yokan.ui.screens.settings import androidx.compose.runtime.Composable import eu.friedcutlet.yokan.database.DbSettings import eu.friedcutlet.yokan.services.http.platformSupportsCustomDns import eu.friedcutlet.yokan.ui.navigation.SettingsPage import org.jetbrains.compose.resources.stringResource import yokan.composeapp.generated.resources.* internal data class SettingsSearchOption( val id: String, val title: String, val page: SettingsPage, val aliases: String = "", val description: String = "", val currentValue: String = "", val anchored: Boolean = false, ) private fun normalizeSettingsQuery(value: String): String = value.lowercase() .replace("wi-fi", "wifi").replace("wi fi", "wifi") .replace('-', ' ').trim().split(Regex("\\s+")).joinToString(" ") internal fun searchSettingsOptions(options: List, query: String): List { val normalized = normalizeSettingsQuery(query) if (normalized.isEmpty()) return emptyList() val words = normalized.split(' ') return options.mapNotNull { option -> val title = normalizeSettingsQuery(option.title) val aliases = normalizeSettingsQuery(option.aliases) val details = normalizeSettingsQuery("${option.description} ${option.currentValue}") if (!words.all { it in "$title $aliases $details" }) return@mapNotNull null val score = when { title == normalized -> 0 title.startsWith(normalized) -> 1 words.all { it in title } -> 2 words.all { it in "$title $aliases" } -> 3 else -> 4 } option to score }.sortedWith(compareBy({ it.second }, { it.first.title }, { it.first.id })).map { it.first } } /** Only explicitly safe values are indexed: never tokens, cookies, paths, accounts, or server URLs. */ @Composable internal fun settingsSearchOptions(settings: DbSettings): List = listOfNotNull( SettingsSearchOption("profiles", stringResource(Res.string.profiles_title), SettingsPage.Profiles, "account library create rename switch delete backup"), SettingsSearchOption("doh", stringResource(Res.string.tile_dns_over_https), SettingsPage.General, "dns encrypted resolver", anchored = true) .takeIf { platformSupportsCustomDns }, SettingsSearchOption("dns-provider", "DNS provider", SettingsPage.General, "cloudflare google quad9 custom doh", "Available when DNS over HTTPS is enabled") .takeIf { platformSupportsCustomDns }, SettingsSearchOption("user-agent", stringResource(Res.string.default_user_agent), SettingsPage.General, "browser http header", anchored = true), SettingsSearchOption("cloudflare", "Cloudflare bypass proxy", SettingsPage.General, "flaresolverr byparr"), SettingsSearchOption("weights", "Recommendations weights", SettingsPage.General, "genre setting synopsis theme reset"), SettingsSearchOption("discord", stringResource(Res.string.tile_discord_rpc), SettingsPage.Discord, "discord presence activity rpc", anchored = true), SettingsSearchOption("discord-account-add", "Discord accounts", SettingsPage.Discord, "discord login account switch token", anchored = true), SettingsSearchOption("discord-message", "Discord custom message", SettingsPage.Discord, "discord status buttons timestamp", anchored = true), SettingsSearchOption("discord-private", stringResource(Res.string.tile_hide_rpc_in_incognito), SettingsPage.Discord, "discord privacy", anchored = true), SettingsSearchOption("discord-categories", "Discord private categories", SettingsPage.Discord, "discord privacy hide category", anchored = true), SettingsSearchOption("discord-progress", stringResource(Res.string.tile_show_rpc_progress), SettingsPage.Discord, "discord progress", anchored = true), SettingsSearchOption("discord-title", stringResource(Res.string.tile_show_rpc_title), SettingsPage.Discord, "discord title", anchored = true), SettingsSearchOption("discord-cover", stringResource(Res.string.tile_show_rpc_cover), SettingsPage.Discord, "discord cover", anchored = true), SettingsSearchOption("system-theme", stringResource(Res.string.settings_follow_system_theme), SettingsPage.Appearance, "automatic dark light", anchored = true), SettingsSearchOption("app-icons", stringResource(Res.string.app_icon_title), SettingsPage.Appearance, "launcher icon torii light dark reset home screen", anchored = true), SettingsSearchOption("eink-mode", stringResource(Res.string.eink_mode), SettingsPage.Appearance, "eink e-ink epaper e-reader kindle kobo boox ghosting refresh grayscale", currentValue = if (settings.einkMode) settings.einkPreset.label else "", anchored = true), SettingsSearchOption("dark", stringResource(Res.string.settings_dark_mode), SettingsPage.Appearance, "night", "Turn off Follow system theme to change manually"), SettingsSearchOption("black", stringResource(Res.string.settings_pure_black_dark_mode), SettingsPage.Appearance, "oled amoled", "Available in dark mode"), SettingsSearchOption("theme", stringResource(Res.string.settings_theme), SettingsPage.Appearance, "palette color scheme"), SettingsSearchOption("blend", stringResource(Res.string.settings_blend_level), SettingsPage.Appearance, "color"), SettingsSearchOption("auto-scale", "Automatic UI scale", SettingsPage.Appearance, "system text size"), SettingsSearchOption("scale", stringResource(Res.string.ui_ui_scale), SettingsPage.Appearance, "size zoom accessibility", currentValue = "${(settings.uiScale * 100).toInt()}%"), SettingsSearchOption("language", stringResource(Res.string.settings_app_language), SettingsPage.Appearance, "locale translation", anchored = true), SettingsSearchOption("font", stringResource(Res.string.settings_font), SettingsPage.Appearance, "typeface typography", currentValue = settings.appFontFamily ?: "Default"), SettingsSearchOption("relative-time", stringResource(Res.string.settings_relative_timestamps), SettingsPage.Appearance, "dates time ago"), SettingsSearchOption("date-format", stringResource(Res.string.settings_date_format), SettingsPage.Appearance, "dates"), SettingsSearchOption("navigation-order", stringResource(Res.string.settings_reorder_navigation), SettingsPage.CustomNavigation, "hide tabs reorder navigation"), SettingsSearchOption("merge-library", stringResource(Res.string.merge_library_nav_mobile), SettingsPage.CustomNavigation, "navigation mobile tabs"), SettingsSearchOption("reader-mode", stringResource(Res.string.default_reading_mode), SettingsPage.Reader, "rtl ltr webtoon vertical horizontal", currentValue = settings.defaultReaderMode.name, anchored = true), SettingsSearchOption("hold-to-scroll", stringResource(Res.string.reader_hold_to_scroll), SettingsPage.Reader, "hold press scroll speed gesture continuous webtoon", anchored = true), SettingsSearchOption("automatic-layout", stringResource(Res.string.reader_layout_automatic), SettingsPage.Reader, "automatic layout detection pairing spread webtoon", anchored = true), SettingsSearchOption("reader-animation", stringResource(Res.string.double_tap_animation_speed), SettingsPage.Reader, "zoom motion"), SettingsSearchOption("reader-background", stringResource(Res.string.background_color), SettingsPage.Reader, "page color"), SettingsSearchOption("preload", stringResource(Res.string.page_preload_amount), SettingsPage.Reader, "prefetch cache pages", currentValue = "${settings.pagePreloadAmount} pages", anchored = true), SettingsSearchOption("reader-scale", stringResource(Res.string.scale_type), SettingsPage.Reader, "fit width height stretch"), SettingsSearchOption("reader-fullscreen", stringResource(Res.string.tile_full_screen_reader), SettingsPage.Reader, "fullscreen"), SettingsSearchOption("page-animation", stringResource(Res.string.animate_page_transitions), SettingsPage.Reader, "motion"), SettingsSearchOption("paged-crop", stringResource(Res.string.crop_borders), SettingsPage.Reader, "trim margins", anchored = true), SettingsSearchOption("gaps", stringResource(Res.string.show_page_gaps), SettingsPage.Reader, "spacing"), SettingsSearchOption("page-number", stringResource(Res.string.show_page_number), SettingsPage.Reader, "counter"), SettingsSearchOption("webtoon-padding", stringResource(Res.string.webtoon_side_padding), SettingsPage.Reader, "margins"), SettingsSearchOption("invert", stringResource(Res.string.invert_colors), SettingsPage.Reader, "negative"), SettingsSearchOption("grayscale", stringResource(Res.string.grayscale), SettingsPage.Reader, "monochrome"), SettingsSearchOption("tap-zones", stringResource(Res.string.use_page_tap_zones), SettingsPage.Reader, "gestures navigation"), SettingsSearchOption("keep-screen", stringResource(Res.string.keep_screen_on), SettingsPage.Reader, "awake sleep"), SettingsSearchOption("duplicates", stringResource(Res.string.tile_auto_read_duplicate_chapters), SettingsPage.Reader, "mark read"), SettingsSearchOption("release-defaults", stringResource(Res.string.releases_default_section), SettingsPage.Reader, "scanlator priority skip duplicate chapter releases", anchored = true), SettingsSearchOption("split-wide-pages", stringResource(Res.string.reader_split_wide_pages), SettingsPage.Reader, "double spread landscape halves paged webtoon"), SettingsSearchOption("rotate-wide-pages", stringResource(Res.string.reader_rotate_wide_pages), SettingsPage.Reader, "landscape spread orientation turn"), SettingsSearchOption("skip-read", stringResource(Res.string.reader_skip_read), SettingsPage.Reader, "chapter navigation next previous"), SettingsSearchOption("skip-filtered", stringResource(Res.string.reader_skip_filtered), SettingsPage.Reader, "chapter navigation filters"), SettingsSearchOption("chapter-transition", stringResource(Res.string.reader_always_show_transition), SettingsPage.Reader, "chapter end card"), SettingsSearchOption("save-title-folder", stringResource(Res.string.reader_save_title_folder), SettingsPage.Reader, "save image album directory"), SettingsSearchOption("volume-keys", stringResource(Res.string.reader_volume_keys), SettingsPage.Reader, "hardware buttons page turn"), SettingsSearchOption("subtitle-language", stringResource(Res.string.default_subtitle_language), SettingsPage.Player, "captions", anchored = true), SettingsSearchOption("mark-seen", stringResource(Res.string.tile_mark_episode_as_seen), SettingsPage.Player, "progress watched threshold"), SettingsSearchOption("skip-intro", stringResource(Res.string.tile_default_skip_intro_length), SettingsPage.Player, "seconds"), SettingsSearchOption("double-skip", stringResource(Res.string.tile_double_tap_skip_length), SettingsPage.Player, "seek seconds"), SettingsSearchOption("playback-speed", stringResource(Res.string.tile_default_playback_speed), SettingsPage.Player, "video speed", currentValue = "${settings.defaultPlaybackSpeed}x", anchored = true), SettingsSearchOption("libass", stringResource(Res.string.tile_use_libass), SettingsPage.Player, "subtitles rendering"), SettingsSearchOption("aniskip", stringResource(Res.string.tile_aniskip), SettingsPage.Player, "skip intro outro", anchored = true), SettingsSearchOption("auto-skip", stringResource(Res.string.tile_auto_skip), SettingsPage.Player, "aniskip", "Available when AniSkip is enabled"), SettingsSearchOption("aniskip-timeout", stringResource(Res.string.tile_aniskip_timeout), SettingsPage.Player, "skip timeout", "Available when AniSkip is enabled"), SettingsSearchOption("player-fullscreen", stringResource(Res.string.tile_fullscreen_player), SettingsPage.Player, "fullscreen video"), SettingsSearchOption("landscape", stringResource(Res.string.tile_force_landscape), SettingsPage.Player, "orientation rotate"), SettingsSearchOption("hardware", stringResource(Res.string.tile_enable_hardware_acceleration), SettingsPage.PlayerDecoder, "gpu performance", anchored = true), SettingsSearchOption("hwdec", stringResource(Res.string.tile_hardware_decoder), SettingsPage.PlayerDecoder, "hwdec codec", anchored = true), SettingsSearchOption("gpu-next", stringResource(Res.string.tile_gpu_next), SettingsPage.PlayerDecoder, "rendering"), SettingsSearchOption("debanding", stringResource(Res.string.debanding), SettingsPage.PlayerDecoder, "banding video"), SettingsSearchOption("yuv", stringResource(Res.string.tile_force_yuv420p), SettingsPage.PlayerDecoder, "black screen pixel format"), SettingsSearchOption("audio-language", "Preferred audio languages", SettingsPage.PlayerAudio, "jpn eng dub"), SettingsSearchOption("pitch", stringResource(Res.string.tile_audio_pitch_correction), SettingsPage.PlayerAudio, "audio speed"), SettingsSearchOption("channels", stringResource(Res.string.tile_audio_channel), SettingsPage.PlayerAudio, "stereo surround mono"), SettingsSearchOption("volume", "Volume boost cap", SettingsPage.PlayerAudio, "loudness amplification"), SettingsSearchOption("custom-button", "Add custom player button", SettingsPage.CustomButtons, "javascript command press long press startup favourite reorder"), SettingsSearchOption("mpv", stringResource(Res.string.tile_use_mpv_config), SettingsPage.PlayerAdvanced, "mpv.conf input.conf scripts shaders"), SettingsSearchOption("mpv-reset", "Redownload mpv config files", SettingsPage.PlayerAdvanced, "reset defaults replace"), SettingsSearchOption("torrent", "Torrent streaming", SettingsPage.Torrent, "torrserver magnet torrent port trackers proxy"), SettingsSearchOption("wifi", stringResource(Res.string.tile_only_on_wi_fi), SettingsPage.Downloads, "wifi wireless downloads", anchored = true), SettingsSearchOption("cbz", stringResource(Res.string.save_as_cbz_archive), SettingsPage.Downloads, "zip archive"), SettingsSearchOption("delete-read", stringResource(Res.string.delete_download_after_reading), SettingsPage.Downloads, "cleanup"), SettingsSearchOption("concurrent", stringResource(Res.string.allow_concurrent_downloads), SettingsPage.Downloads, "parallel simultaneous", anchored = true), SettingsSearchOption("concurrent-count", stringResource(Res.string.concurrent_downloads), SettingsPage.Downloads, "parallel limit", "Available when concurrent downloads are enabled"), SettingsSearchOption("delay", stringResource(Res.string.download_delay), SettingsPage.Downloads, "throttle jitter"), SettingsSearchOption("download-speed", "Download speed limit", SettingsPage.Downloads, "bandwidth throttle"), SettingsSearchOption("upload-speed", "Upload speed limit", SettingsPage.Downloads, "bandwidth throttle"), SettingsSearchOption("download-location", stringResource(Res.string.download_location), SettingsPage.Downloads, "folder path storage"), SettingsSearchOption("rescan", "Rescan local folders", SettingsPage.Downloads, "reindex scan"), SettingsSearchOption("add-folder", stringResource(Res.string.add_local_folder), SettingsPage.Downloads, "virtual folder usb local media"), SettingsSearchOption("destination", "Download destination", SettingsPage.Downloads, "virtual folder", "Choose a folder when Ask download destination is off"), SettingsSearchOption("ask-destination", "Ask download destination", SettingsPage.Downloads, "prompt folder"), SettingsSearchOption("update-progress", "Update progress after reading", SettingsPage.Tracking, "tracking chapter episode", anchored = true), SettingsSearchOption("connect-tracker", "Connect tracker", SettingsPage.Tracking, "anilist kitsu myanimelist mal simkl trakt oauth login logout"), SettingsSearchOption("tracking-edit", "Save tracking progress", SettingsPage.ManageTrackers, "score status unbind", "Select a connected tracker and a bound title"), SettingsSearchOption("sync-on", stringResource(Res.string.tile_sync_on), SettingsPage.Sync, "enable cloud hub", anchored = true), SettingsSearchOption("auto-sync", stringResource(Res.string.tile_auto_sync), SettingsPage.Sync, "frequency schedule", "Available when sync is enabled"), SettingsSearchOption("sync-history", stringResource(Res.string.tile_sync_histories), SettingsPage.Sync, "history"), SettingsSearchOption("sync-updates", stringResource(Res.string.tile_sync_updates), SettingsPage.Sync, "updates"), SettingsSearchOption("sync-settings", stringResource(Res.string.sync_enable_settings), SettingsPage.Sync, "preferences"), SettingsSearchOption("hub-login", "Sign in to sync server", SettingsPage.Sync, "yokan hub account"), SettingsSearchOption("sync-upload", "Upload only", SettingsPage.Sync, "push changes", "Requires a connected account and enabled sync"), SettingsSearchOption("sync-download", "Download only", SettingsPage.Sync, "pull changes", "Requires a connected account and enabled sync"), SettingsSearchOption("cloud-backup", "Upload backup", SettingsPage.Sync, "cloud snapshot", "Requires a connected cloud provider"), SettingsSearchOption("cloud-restore", "Restore latest", SettingsPage.Sync, "cloud backup", "Requires a connected cloud provider"), SettingsSearchOption("extension-updates", stringResource(Res.string.check_for_extension_updates), SettingsPage.Browse, "sources updates"), SettingsSearchOption("extension-auto", stringResource(Res.string.auto_extensions_updates), SettingsPage.Browse, "install updates", "Enable extension update checks first"), SettingsSearchOption("pinned", stringResource(Res.string.only_include_pinned_sources), SettingsPage.Browse, "global search"), SettingsSearchOption("nsfw", stringResource(Res.string.tile_show_nsfw_sources), SettingsPage.Browse, "adult explicit"), SettingsSearchOption("cookies", "Cookies", SettingsPage.Cookies, "delete clear web login privacy reveal hide values", anchored = true), SettingsSearchOption("clean-db", stringResource(Res.string.clean_database), SettingsPage.Browse, "cleanup cached entries"), SettingsSearchOption("clear-sources", "Clear installed sources", SettingsPage.Browse, "remove extensions", "Applies to the selected media type"), SettingsSearchOption("clear-library", "Clear library", SettingsPage.Browse, "delete favourites progress", "Applies to the selected media type"), SettingsSearchOption("clear-local", "Clear local library", SettingsPage.Browse, "remove indexed archives"), SettingsSearchOption("manga-repo", "Add manga repository", SettingsPage.MangaRepositories, "repo url extensions"), SettingsSearchOption("anime-repo", "Add anime repository", SettingsPage.AnimeRepositories, "repo url extensions"), SettingsSearchOption("novel-repo", "Add novel repository", SettingsPage.NovelRepositories, "repo url extensions"), SettingsSearchOption("server-install", "Install extension server", SettingsPage.ExtensionServer, "mihon apk jre bridge proxy", "Available actions depend on platform"), SettingsSearchOption("metadata-url", "Metadata server URL", SettingsPage.MetadataServer, "api lookup tags alternative titles"), SettingsSearchOption("lock", stringResource(Res.string.app_lock), SettingsPage.Security, "biometric device credential privacy", anchored = true), SettingsSearchOption("version", "Version", SettingsPage.About, "app version beta", anchored = true), SettingsSearchOption("app-update", stringResource(Res.string.tile_check_for_app_updates), SettingsPage.About, "upgrade release"), SettingsSearchOption("logs", stringResource(Res.string.tile_enable_logs), SettingsPage.About, "debug diagnostics logging"), SettingsSearchOption("developer-mode", "Developer mode", SettingsPage.Developer, "local recipe catalog loopback http testing"), SettingsSearchOption("developer-diagnostics", "Diagnostics and logs", SettingsPage.Developer, "memory heap graph errors warnings image cache hits network requests"), SettingsSearchOption("backup-create", "Create backup", SettingsPage.CreateBackup, "export data compression encryption"), SettingsSearchOption("backup-restore", "Restore backup", SettingsPage.DataAndStorage, "import merge replace recovery"), SettingsSearchOption("backup-frequency", stringResource(Res.string.backup_frequency), SettingsPage.DataAndStorage, "automatic schedule"), SettingsSearchOption("compression", stringResource(Res.string.compression_level), SettingsPage.DataAndStorage, "backup size"), SettingsSearchOption("cache", "Clear cache", SettingsPage.DataAndStorage, "storage free space"), SettingsSearchOption("library-updates", "Automatic library updates", SettingsPage.Library, "refresh schedule background"), SettingsSearchOption("category-tabs", "Display category tabs", SettingsPage.Library, "library layout"), SettingsSearchOption("counts", "Show number of items", SettingsPage.Library, "library count"), SettingsSearchOption("download-badges", "Show download badges", SettingsPage.Library, "library downloaded chapters"), SettingsSearchOption("language-badge", "Show source language", SettingsPage.Library, "library badge"), SettingsSearchOption("source-badge", "Show source badge", SettingsPage.Library, "library source"), SettingsSearchOption("category-create", "Add category", SettingsPage.Categories, "organise group titles rename reorder hidden update"), )