Yokan / rebuild
Course 1 8624561

SettingsSearch.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/settings/SettingsSearch.kt

implementation186 lines
1package eu.friedcutlet.yokan.ui.screens.settings23import androidx.compose.runtime.Composable4import eu.friedcutlet.yokan.database.DbSettings5import eu.friedcutlet.yokan.services.http.platformSupportsCustomDns6import eu.friedcutlet.yokan.ui.navigation.SettingsPage7import org.jetbrains.compose.resources.stringResource8import yokan.composeapp.generated.resources.*910internal data class SettingsSearchOption(11    val id: String,12    val title: String,13    val page: SettingsPage,14    val aliases: String = "",15    val description: String = "",16    val currentValue: String = "",17    val anchored: Boolean = false,18)1920private fun normalizeSettingsQuery(value: String): String = value.lowercase()21    .replace("wi-fi", "wifi").replace("wi fi", "wifi")22    .replace('-', ' ').trim().split(Regex("\\s+")).joinToString(" ")2324internal fun searchSettingsOptions(options: List<SettingsSearchOption>, query: String): List<SettingsSearchOption> {25    val normalized = normalizeSettingsQuery(query)26    if (normalized.isEmpty()) return emptyList()27    val words = normalized.split(' ')28    return options.mapNotNull { option ->29        val title = normalizeSettingsQuery(option.title)30        val aliases = normalizeSettingsQuery(option.aliases)31        val details = normalizeSettingsQuery("${option.description} ${option.currentValue}")32        if (!words.all { it in "$title $aliases $details" }) return@mapNotNull null33        val score = when {34            title == normalized -> 035            title.startsWith(normalized) -> 136            words.all { it in title } -> 237            words.all { it in "$title $aliases" } -> 338            else -> 439        }40        option to score41    }.sortedWith(compareBy({ it.second }, { it.first.title }, { it.first.id })).map { it.first }42}4344/** Only explicitly safe values are indexed: never tokens, cookies, paths, accounts, or server URLs. */45@Composable46internal fun settingsSearchOptions(settings: DbSettings): List<SettingsSearchOption> = listOfNotNull(47    SettingsSearchOption("profiles", stringResource(Res.string.profiles_title), SettingsPage.Profiles, "account library create rename switch delete backup"),48    SettingsSearchOption("doh", stringResource(Res.string.tile_dns_over_https), SettingsPage.General, "dns encrypted resolver", anchored = true)49        .takeIf { platformSupportsCustomDns },50    SettingsSearchOption("dns-provider", "DNS provider", SettingsPage.General, "cloudflare google quad9 custom doh", "Available when DNS over HTTPS is enabled")51        .takeIf { platformSupportsCustomDns },52    SettingsSearchOption("user-agent", stringResource(Res.string.default_user_agent), SettingsPage.General, "browser http header", anchored = true),53    SettingsSearchOption("cloudflare", "Cloudflare bypass proxy", SettingsPage.General, "flaresolverr byparr"),54    SettingsSearchOption("weights", "Recommendations weights", SettingsPage.General, "genre setting synopsis theme reset"),55    SettingsSearchOption("discord", stringResource(Res.string.tile_discord_rpc), SettingsPage.Discord, "discord presence activity rpc", anchored = true),56    SettingsSearchOption("discord-account-add", "Discord accounts", SettingsPage.Discord, "discord login account switch token", anchored = true),57    SettingsSearchOption("discord-message", "Discord custom message", SettingsPage.Discord, "discord status buttons timestamp", anchored = true),58    SettingsSearchOption("discord-private", stringResource(Res.string.tile_hide_rpc_in_incognito), SettingsPage.Discord, "discord privacy", anchored = true),59    SettingsSearchOption("discord-categories", "Discord private categories", SettingsPage.Discord, "discord privacy hide category", anchored = true),60    SettingsSearchOption("discord-progress", stringResource(Res.string.tile_show_rpc_progress), SettingsPage.Discord, "discord progress", anchored = true),61    SettingsSearchOption("discord-title", stringResource(Res.string.tile_show_rpc_title), SettingsPage.Discord, "discord title", anchored = true),62    SettingsSearchOption("discord-cover", stringResource(Res.string.tile_show_rpc_cover), SettingsPage.Discord, "discord cover", anchored = true),63    SettingsSearchOption("system-theme", stringResource(Res.string.settings_follow_system_theme), SettingsPage.Appearance, "automatic dark light", anchored = true),64    SettingsSearchOption("app-icons", stringResource(Res.string.app_icon_title), SettingsPage.Appearance, "launcher icon torii light dark reset home screen", anchored = true),65    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),66    SettingsSearchOption("dark", stringResource(Res.string.settings_dark_mode), SettingsPage.Appearance, "night", "Turn off Follow system theme to change manually"),67    SettingsSearchOption("black", stringResource(Res.string.settings_pure_black_dark_mode), SettingsPage.Appearance, "oled amoled", "Available in dark mode"),68    SettingsSearchOption("theme", stringResource(Res.string.settings_theme), SettingsPage.Appearance, "palette color scheme"),69    SettingsSearchOption("blend", stringResource(Res.string.settings_blend_level), SettingsPage.Appearance, "color"),70    SettingsSearchOption("auto-scale", "Automatic UI scale", SettingsPage.Appearance, "system text size"),71    SettingsSearchOption("scale", stringResource(Res.string.ui_ui_scale), SettingsPage.Appearance, "size zoom accessibility", currentValue = "${(settings.uiScale * 100).toInt()}%"),72    SettingsSearchOption("language", stringResource(Res.string.settings_app_language), SettingsPage.Appearance, "locale translation", anchored = true),73    SettingsSearchOption("font", stringResource(Res.string.settings_font), SettingsPage.Appearance, "typeface typography", currentValue = settings.appFontFamily ?: "Default"),74    SettingsSearchOption("relative-time", stringResource(Res.string.settings_relative_timestamps), SettingsPage.Appearance, "dates time ago"),75    SettingsSearchOption("date-format", stringResource(Res.string.settings_date_format), SettingsPage.Appearance, "dates"),76    SettingsSearchOption("navigation-order", stringResource(Res.string.settings_reorder_navigation), SettingsPage.CustomNavigation, "hide tabs reorder navigation"),77    SettingsSearchOption("merge-library", stringResource(Res.string.merge_library_nav_mobile), SettingsPage.CustomNavigation, "navigation mobile tabs"),78    SettingsSearchOption("reader-mode", stringResource(Res.string.default_reading_mode), SettingsPage.Reader, "rtl ltr webtoon vertical horizontal", currentValue = settings.defaultReaderMode.name, anchored = true),79    SettingsSearchOption("hold-to-scroll", stringResource(Res.string.reader_hold_to_scroll), SettingsPage.Reader, "hold press scroll speed gesture continuous webtoon", anchored = true),80    SettingsSearchOption("automatic-layout", stringResource(Res.string.reader_layout_automatic), SettingsPage.Reader, "automatic layout detection pairing spread webtoon", anchored = true),81    SettingsSearchOption("reader-animation", stringResource(Res.string.double_tap_animation_speed), SettingsPage.Reader, "zoom motion"),82    SettingsSearchOption("reader-background", stringResource(Res.string.background_color), SettingsPage.Reader, "page color"),83    SettingsSearchOption("preload", stringResource(Res.string.page_preload_amount), SettingsPage.Reader, "prefetch cache pages", currentValue = "${settings.pagePreloadAmount} pages", anchored = true),84    SettingsSearchOption("reader-scale", stringResource(Res.string.scale_type), SettingsPage.Reader, "fit width height stretch"),85    SettingsSearchOption("reader-fullscreen", stringResource(Res.string.tile_full_screen_reader), SettingsPage.Reader, "fullscreen"),86    SettingsSearchOption("page-animation", stringResource(Res.string.animate_page_transitions), SettingsPage.Reader, "motion"),87    SettingsSearchOption("paged-crop", stringResource(Res.string.crop_borders), SettingsPage.Reader, "trim margins", anchored = true),88    SettingsSearchOption("gaps", stringResource(Res.string.show_page_gaps), SettingsPage.Reader, "spacing"),89    SettingsSearchOption("page-number", stringResource(Res.string.show_page_number), SettingsPage.Reader, "counter"),90    SettingsSearchOption("webtoon-padding", stringResource(Res.string.webtoon_side_padding), SettingsPage.Reader, "margins"),91    SettingsSearchOption("invert", stringResource(Res.string.invert_colors), SettingsPage.Reader, "negative"),92    SettingsSearchOption("grayscale", stringResource(Res.string.grayscale), SettingsPage.Reader, "monochrome"),93    SettingsSearchOption("tap-zones", stringResource(Res.string.use_page_tap_zones), SettingsPage.Reader, "gestures navigation"),94    SettingsSearchOption("keep-screen", stringResource(Res.string.keep_screen_on), SettingsPage.Reader, "awake sleep"),95    SettingsSearchOption("duplicates", stringResource(Res.string.tile_auto_read_duplicate_chapters), SettingsPage.Reader, "mark read"),96    SettingsSearchOption("release-defaults", stringResource(Res.string.releases_default_section), SettingsPage.Reader, "scanlator priority skip duplicate chapter releases", anchored = true),97    SettingsSearchOption("split-wide-pages", stringResource(Res.string.reader_split_wide_pages), SettingsPage.Reader, "double spread landscape halves paged webtoon"),98    SettingsSearchOption("rotate-wide-pages", stringResource(Res.string.reader_rotate_wide_pages), SettingsPage.Reader, "landscape spread orientation turn"),99    SettingsSearchOption("skip-read", stringResource(Res.string.reader_skip_read), SettingsPage.Reader, "chapter navigation next previous"),100    SettingsSearchOption("skip-filtered", stringResource(Res.string.reader_skip_filtered), SettingsPage.Reader, "chapter navigation filters"),101    SettingsSearchOption("chapter-transition", stringResource(Res.string.reader_always_show_transition), SettingsPage.Reader, "chapter end card"),102    SettingsSearchOption("save-title-folder", stringResource(Res.string.reader_save_title_folder), SettingsPage.Reader, "save image album directory"),103    SettingsSearchOption("volume-keys", stringResource(Res.string.reader_volume_keys), SettingsPage.Reader, "hardware buttons page turn"),104    SettingsSearchOption("subtitle-language", stringResource(Res.string.default_subtitle_language), SettingsPage.Player, "captions", anchored = true),105    SettingsSearchOption("mark-seen", stringResource(Res.string.tile_mark_episode_as_seen), SettingsPage.Player, "progress watched threshold"),106    SettingsSearchOption("skip-intro", stringResource(Res.string.tile_default_skip_intro_length), SettingsPage.Player, "seconds"),107    SettingsSearchOption("double-skip", stringResource(Res.string.tile_double_tap_skip_length), SettingsPage.Player, "seek seconds"),108    SettingsSearchOption("playback-speed", stringResource(Res.string.tile_default_playback_speed), SettingsPage.Player, "video speed", currentValue = "${settings.defaultPlaybackSpeed}x", anchored = true),109    SettingsSearchOption("libass", stringResource(Res.string.tile_use_libass), SettingsPage.Player, "subtitles rendering"),110    SettingsSearchOption("aniskip", stringResource(Res.string.tile_aniskip), SettingsPage.Player, "skip intro outro", anchored = true),111    SettingsSearchOption("auto-skip", stringResource(Res.string.tile_auto_skip), SettingsPage.Player, "aniskip", "Available when AniSkip is enabled"),112    SettingsSearchOption("aniskip-timeout", stringResource(Res.string.tile_aniskip_timeout), SettingsPage.Player, "skip timeout", "Available when AniSkip is enabled"),113    SettingsSearchOption("player-fullscreen", stringResource(Res.string.tile_fullscreen_player), SettingsPage.Player, "fullscreen video"),114    SettingsSearchOption("landscape", stringResource(Res.string.tile_force_landscape), SettingsPage.Player, "orientation rotate"),115    SettingsSearchOption("hardware", stringResource(Res.string.tile_enable_hardware_acceleration), SettingsPage.PlayerDecoder, "gpu performance", anchored = true),116    SettingsSearchOption("hwdec", stringResource(Res.string.tile_hardware_decoder), SettingsPage.PlayerDecoder, "hwdec codec", anchored = true),117    SettingsSearchOption("gpu-next", stringResource(Res.string.tile_gpu_next), SettingsPage.PlayerDecoder, "rendering"),118    SettingsSearchOption("debanding", stringResource(Res.string.debanding), SettingsPage.PlayerDecoder, "banding video"),119    SettingsSearchOption("yuv", stringResource(Res.string.tile_force_yuv420p), SettingsPage.PlayerDecoder, "black screen pixel format"),120    SettingsSearchOption("audio-language", "Preferred audio languages", SettingsPage.PlayerAudio, "jpn eng dub"),121    SettingsSearchOption("pitch", stringResource(Res.string.tile_audio_pitch_correction), SettingsPage.PlayerAudio, "audio speed"),122    SettingsSearchOption("channels", stringResource(Res.string.tile_audio_channel), SettingsPage.PlayerAudio, "stereo surround mono"),123    SettingsSearchOption("volume", "Volume boost cap", SettingsPage.PlayerAudio, "loudness amplification"),124    SettingsSearchOption("custom-button", "Add custom player button", SettingsPage.CustomButtons, "javascript command press long press startup favourite reorder"),125    SettingsSearchOption("mpv", stringResource(Res.string.tile_use_mpv_config), SettingsPage.PlayerAdvanced, "mpv.conf input.conf scripts shaders"),126    SettingsSearchOption("mpv-reset", "Redownload mpv config files", SettingsPage.PlayerAdvanced, "reset defaults replace"),127    SettingsSearchOption("torrent", "Torrent streaming", SettingsPage.Torrent, "torrserver magnet torrent port trackers proxy"),128    SettingsSearchOption("wifi", stringResource(Res.string.tile_only_on_wi_fi), SettingsPage.Downloads, "wifi wireless downloads", anchored = true),129    SettingsSearchOption("cbz", stringResource(Res.string.save_as_cbz_archive), SettingsPage.Downloads, "zip archive"),130    SettingsSearchOption("delete-read", stringResource(Res.string.delete_download_after_reading), SettingsPage.Downloads, "cleanup"),131    SettingsSearchOption("concurrent", stringResource(Res.string.allow_concurrent_downloads), SettingsPage.Downloads, "parallel simultaneous", anchored = true),132    SettingsSearchOption("concurrent-count", stringResource(Res.string.concurrent_downloads), SettingsPage.Downloads, "parallel limit", "Available when concurrent downloads are enabled"),133    SettingsSearchOption("delay", stringResource(Res.string.download_delay), SettingsPage.Downloads, "throttle jitter"),134    SettingsSearchOption("download-speed", "Download speed limit", SettingsPage.Downloads, "bandwidth throttle"),135    SettingsSearchOption("upload-speed", "Upload speed limit", SettingsPage.Downloads, "bandwidth throttle"),136    SettingsSearchOption("download-location", stringResource(Res.string.download_location), SettingsPage.Downloads, "folder path storage"),137    SettingsSearchOption("rescan", "Rescan local folders", SettingsPage.Downloads, "reindex scan"),138    SettingsSearchOption("add-folder", stringResource(Res.string.add_local_folder), SettingsPage.Downloads, "virtual folder usb local media"),139    SettingsSearchOption("destination", "Download destination", SettingsPage.Downloads, "virtual folder", "Choose a folder when Ask download destination is off"),140    SettingsSearchOption("ask-destination", "Ask download destination", SettingsPage.Downloads, "prompt folder"),141    SettingsSearchOption("update-progress", "Update progress after reading", SettingsPage.Tracking, "tracking chapter episode", anchored = true),142    SettingsSearchOption("connect-tracker", "Connect tracker", SettingsPage.Tracking, "anilist kitsu myanimelist mal simkl trakt oauth login logout"),143    SettingsSearchOption("tracking-edit", "Save tracking progress", SettingsPage.ManageTrackers, "score status unbind", "Select a connected tracker and a bound title"),144    SettingsSearchOption("sync-on", stringResource(Res.string.tile_sync_on), SettingsPage.Sync, "enable cloud hub", anchored = true),145    SettingsSearchOption("auto-sync", stringResource(Res.string.tile_auto_sync), SettingsPage.Sync, "frequency schedule", "Available when sync is enabled"),146    SettingsSearchOption("sync-history", stringResource(Res.string.tile_sync_histories), SettingsPage.Sync, "history"),147    SettingsSearchOption("sync-updates", stringResource(Res.string.tile_sync_updates), SettingsPage.Sync, "updates"),148    SettingsSearchOption("sync-settings", stringResource(Res.string.sync_enable_settings), SettingsPage.Sync, "preferences"),149    SettingsSearchOption("hub-login", "Sign in to sync server", SettingsPage.Sync, "yokan hub account"),150    SettingsSearchOption("sync-upload", "Upload only", SettingsPage.Sync, "push changes", "Requires a connected account and enabled sync"),151    SettingsSearchOption("sync-download", "Download only", SettingsPage.Sync, "pull changes", "Requires a connected account and enabled sync"),152    SettingsSearchOption("cloud-backup", "Upload backup", SettingsPage.Sync, "cloud snapshot", "Requires a connected cloud provider"),153    SettingsSearchOption("cloud-restore", "Restore latest", SettingsPage.Sync, "cloud backup", "Requires a connected cloud provider"),154    SettingsSearchOption("extension-updates", stringResource(Res.string.check_for_extension_updates), SettingsPage.Browse, "sources updates"),155    SettingsSearchOption("extension-auto", stringResource(Res.string.auto_extensions_updates), SettingsPage.Browse, "install updates", "Enable extension update checks first"),156    SettingsSearchOption("pinned", stringResource(Res.string.only_include_pinned_sources), SettingsPage.Browse, "global search"),157    SettingsSearchOption("nsfw", stringResource(Res.string.tile_show_nsfw_sources), SettingsPage.Browse, "adult explicit"),158    SettingsSearchOption("cookies", "Cookies", SettingsPage.Cookies, "delete clear web login privacy reveal hide values", anchored = true),159    SettingsSearchOption("clean-db", stringResource(Res.string.clean_database), SettingsPage.Browse, "cleanup cached entries"),160    SettingsSearchOption("clear-sources", "Clear installed sources", SettingsPage.Browse, "remove extensions", "Applies to the selected media type"),161    SettingsSearchOption("clear-library", "Clear library", SettingsPage.Browse, "delete favourites progress", "Applies to the selected media type"),162    SettingsSearchOption("clear-local", "Clear local library", SettingsPage.Browse, "remove indexed archives"),163    SettingsSearchOption("manga-repo", "Add manga repository", SettingsPage.MangaRepositories, "repo url extensions"),164    SettingsSearchOption("anime-repo", "Add anime repository", SettingsPage.AnimeRepositories, "repo url extensions"),165    SettingsSearchOption("novel-repo", "Add novel repository", SettingsPage.NovelRepositories, "repo url extensions"),166    SettingsSearchOption("server-install", "Install extension server", SettingsPage.ExtensionServer, "mihon apk jre bridge proxy", "Available actions depend on platform"),167    SettingsSearchOption("metadata-url", "Metadata server URL", SettingsPage.MetadataServer, "api lookup tags alternative titles"),168    SettingsSearchOption("lock", stringResource(Res.string.app_lock), SettingsPage.Security, "biometric device credential privacy", anchored = true),169    SettingsSearchOption("version", "Version", SettingsPage.About, "app version beta", anchored = true),170    SettingsSearchOption("app-update", stringResource(Res.string.tile_check_for_app_updates), SettingsPage.About, "upgrade release"),171    SettingsSearchOption("logs", stringResource(Res.string.tile_enable_logs), SettingsPage.About, "debug diagnostics logging"),172    SettingsSearchOption("developer-mode", "Developer mode", SettingsPage.Developer, "local recipe catalog loopback http testing"),173    SettingsSearchOption("developer-diagnostics", "Diagnostics and logs", SettingsPage.Developer, "memory heap graph errors warnings image cache hits network requests"),174    SettingsSearchOption("backup-create", "Create backup", SettingsPage.CreateBackup, "export data compression encryption"),175    SettingsSearchOption("backup-restore", "Restore backup", SettingsPage.DataAndStorage, "import merge replace recovery"),176    SettingsSearchOption("backup-frequency", stringResource(Res.string.backup_frequency), SettingsPage.DataAndStorage, "automatic schedule"),177    SettingsSearchOption("compression", stringResource(Res.string.compression_level), SettingsPage.DataAndStorage, "backup size"),178    SettingsSearchOption("cache", "Clear cache", SettingsPage.DataAndStorage, "storage free space"),179    SettingsSearchOption("library-updates", "Automatic library updates", SettingsPage.Library, "refresh schedule background"),180    SettingsSearchOption("category-tabs", "Display category tabs", SettingsPage.Library, "library layout"),181    SettingsSearchOption("counts", "Show number of items", SettingsPage.Library, "library count"),182    SettingsSearchOption("download-badges", "Show download badges", SettingsPage.Library, "library downloaded chapters"),183    SettingsSearchOption("language-badge", "Show source language", SettingsPage.Library, "library badge"),184    SettingsSearchOption("source-badge", "Show source badge", SettingsPage.Library, "library source"),185    SettingsSearchOption("category-create", "Add category", SettingsPage.Categories, "organise group titles rename reorder hidden update"),186)187

Search chapters, reference and source filenames.