@@ -28,7 +28,6 @@ import dagger.Lazy
2828import dagger.Module
2929import dagger.Provides
3030import dagger.SingleInstanceIn
31- import kotlinx.coroutines.runBlocking
3231import kotlinx.coroutines.withContext
3332import logcat.logcat
3433import org.iq80.leveldb.DB
@@ -39,7 +38,7 @@ import java.nio.charset.StandardCharsets
3938import javax.inject.Inject
4039
4140interface WebLocalStorageManager {
42- fun clearWebLocalStorage ()
41+ suspend fun clearWebLocalStorage ()
4342}
4443
4544@ContributesBinding(AppScope ::class )
@@ -56,40 +55,36 @@ class DuckDuckGoWebLocalStorageManager @Inject constructor(
5655 private var keysToDelete = emptyList<String >()
5756 private var matchingRegex = emptyList<String >()
5857
59- override fun clearWebLocalStorage () = runBlocking {
60- withContext(dispatcherProvider.io()) {
61- val settings = androidBrowserConfigFeature.webLocalStorage().getSettings()
62- val webLocalStorageSettings = webLocalStorageSettingsJsonParser.parseJson(settings)
58+ override suspend fun clearWebLocalStorage () = withContext(dispatcherProvider.io()) {
59+ val settings = androidBrowserConfigFeature.webLocalStorage().getSettings()
60+ val webLocalStorageSettings = webLocalStorageSettingsJsonParser.parseJson(settings)
6361
64- val fireproofedDomains = withContext(dispatcherProvider.io()) {
65- fireproofWebsiteRepository.fireproofWebsitesSync().map { it.domain }
66- }
62+ val fireproofedDomains = fireproofWebsiteRepository.fireproofWebsitesSync().map { it.domain }
6763
68- domains = webLocalStorageSettings.domains.list + fireproofedDomains
69- keysToDelete = webLocalStorageSettings.keysToDelete.list
70- matchingRegex = webLocalStorageSettings.matchingRegex.list
64+ domains = webLocalStorageSettings.domains.list + fireproofedDomains
65+ keysToDelete = webLocalStorageSettings.keysToDelete.list
66+ matchingRegex = webLocalStorageSettings.matchingRegex.list
7167
72- logcat { " WebLocalStorageManager: Allowed domains: $domains " }
73- logcat { " WebLocalStorageManager: Keys to delete: $keysToDelete " }
74- logcat { " WebLocalStorageManager: Matching regex: $matchingRegex " }
68+ logcat { " WebLocalStorageManager: Allowed domains: $domains " }
69+ logcat { " WebLocalStorageManager: Keys to delete: $keysToDelete " }
70+ logcat { " WebLocalStorageManager: Matching regex: $matchingRegex " }
7571
76- val db = databaseProvider.get()
77- db.iterator().use { iterator ->
78- iterator.seekToFirst()
72+ val db = databaseProvider.get()
73+ db.iterator().use { iterator ->
74+ iterator.seekToFirst()
7975
80- while (iterator.hasNext()) {
81- val entry = iterator.next()
82- val key = String (entry.key, StandardCharsets .UTF_8 )
76+ while (iterator.hasNext()) {
77+ val entry = iterator.next()
78+ val key = String (entry.key, StandardCharsets .UTF_8 )
8379
84- val domainForMatchingAllowedKey = getDomainForMatchingAllowedKey(key)
85- if (domainForMatchingAllowedKey == null ) {
80+ val domainForMatchingAllowedKey = getDomainForMatchingAllowedKey(key)
81+ if (domainForMatchingAllowedKey == null ) {
82+ db.delete(entry.key)
83+ logcat { " WebLocalStorageManager: Deleted key: $key " }
84+ } else if (settingsDataStore.clearDuckAiData && domainForMatchingAllowedKey == DUCKDUCKGO_DOMAIN ) {
85+ if (keysToDelete.any { key.endsWith(it) }) {
8686 db.delete(entry.key)
8787 logcat { " WebLocalStorageManager: Deleted key: $key " }
88- } else if (settingsDataStore.clearDuckAiData && domainForMatchingAllowedKey == DUCKDUCKGO_DOMAIN ) {
89- if (keysToDelete.any { key.endsWith(it) }) {
90- db.delete(entry.key)
91- logcat { " WebLocalStorageManager: Deleted key: $key " }
92- }
9388 }
9489 }
9590 }
0 commit comments