Skip to content

refactor: avoid runBlocking on main thread in LocaleHelper #5082

Description

@harshsomankar123-tech

Is your feature request related to a problem? Please describe.

Currently, LocaleHelper.getAppLocale reads the user's preferred language from KiwixDataStore using runBlocking { kiwixDataStore.prefLanguage.first() }.

Because getAppLocale and getLocalizedString can be called from synchronous contexts on Dispatchers.Main (such as UI component rendering and ViewModel helpers), using runBlocking on the main thread can block the UI thread and potentially cause UI stutters or ANRs.

Describe the solution you'd like

Refactor LocaleHelper and its call sites to fetch the preferred language asynchronously using Kotlin Coroutines (suspend functions or a dedicated background dispatcher) instead of blocking the main thread with runBlocking.

Additional context

Originally noted in PR #4705 review comment by @MohitMaliFtechiz.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions