Modern Apps git

← Modern-Apps.git

web: always enable ad and tracker blocking

Commit
3179a6ffd9f1bd71fe64e0a342bf2f79515bedb9
Author
Vayun Mathur <[email protected]>
When
2026-08-02 21:36 UTC (4 months ago)
Parents
34eb7a7

Diff

web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt b/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.ktindex 4848a0591d..0307b7bd8d 100644--- a/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt@@ -124,10 +124,7 @@ fun SettingsPage(             item {                 ListItem(                     headlineContent = { Text(stringResource(R.string.ad_tracker_blocking)) },-                    supportingContent = { Text(stringResource(R.string.blocks_doubleclick_googletagmanager_anal)) },-                    trailingContent = {-                        Switch(checked = viewModel.adBlockEnabled, onCheckedChange = { viewModel.updateAdBlock(it) })-                    }+                    supportingContent = { Text(stringResource(R.string.blocks_doubleclick_googletagmanager_anal) + " — Always on") }                 )             } 
web/src/main/java/com/vayunmathur/web/ui/WebViewBrowser.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/WebViewBrowser.kt b/web/src/main/java/com/vayunmathur/web/ui/WebViewBrowser.ktindex 77c6870d27..9b7d4bcaa3 100644--- a/web/src/main/java/com/vayunmathur/web/ui/WebViewBrowser.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/WebViewBrowser.kt@@ -163,11 +163,9 @@ fun WebViewBrowser(                     )                      override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {-                        if (viewModel.adBlockEnabled) {-                            val host = request.url.host ?: ""-                            if (adHosts.any { host.contains(it) }) {-                                return WebResourceResponse("text/plain", "utf-8", "".byteInputStream())-                            }+                        val host = request.url.host ?: ""+                        if (adHosts.any { host.contains(it) }) {+                            return WebResourceResponse("text/plain", "utf-8", "".byteInputStream())                         }                         return super.shouldInterceptRequest(view, request)                     }
web/src/main/java/com/vayunmathur/web/util/WebViewModel.kt
diff --git a/web/src/main/java/com/vayunmathur/web/util/WebViewModel.kt b/web/src/main/java/com/vayunmathur/web/util/WebViewModel.ktindex a1d1e7cedb..e47ab633b5 100644--- a/web/src/main/java/com/vayunmathur/web/util/WebViewModel.kt+++ b/web/src/main/java/com/vayunmathur/web/util/WebViewModel.kt@@ -41,7 +41,6 @@ private const val P_CACHE_MODE = "web_cache_mode" private const val P_JS_ENABLED = "web_js_enabled" private const val P_BLOCK_THIRD_PARTY = "web_block_third_party" private const val P_DESKTOP_MODE = "web_desktop_mode"-private const val P_ADBLOCK = "web_adblock" private const val P_SEARCH_ENGINE = "web_search_engine"  data class PermissionPrompt(@@ -77,7 +76,8 @@ class WebViewModel(     var jsEnabled by mutableStateOf(true)     var blockThirdPartyCookies by mutableStateOf(false)     var desktopMode by mutableStateOf(false)-    var adBlockEnabled by mutableStateOf(false)+    /** Ad/tracker blocking is always enabled — cannot be disabled. */+    val adBlockEnabled: Boolean = true      private val _bookmarks = MutableStateFlow<List<Bookmark>>(emptyList())     val bookmarks: StateFlow<List<Bookmark>> = _bookmarks@@ -134,14 +134,12 @@ class WebViewModel(                     val js = sp.getBoolean(P_JS_ENABLED, true)                     val blockThird = sp.getBoolean(P_BLOCK_THIRD_PARTY, false)                     val desktop = sp.getBoolean(P_DESKTOP_MODE, false)-                    val adblock = sp.getBoolean(P_ADBLOCK, false)                     withContext(Dispatchers.Main) {                         cacheModeName?.let { runCatching { CacheMode.valueOf(it) }.getOrNull()?.let { cm -> cacheMode = cm } }                         searchEngineName?.let { runCatching { SearchEngine.valueOf(it) }.getOrNull()?.let { se -> searchEngine = se } }                         jsEnabled = js                         blockThirdPartyCookies = blockThird                         desktopMode = desktop-                        adBlockEnabled = adblock                          if (savedTabs != null) {                             runCatching {@@ -360,11 +358,6 @@ class WebViewModel(         persistPrefs()     } -    fun updateAdBlock(enabled: Boolean) {-        adBlockEnabled = enabled-        persistPrefs()-    }-     // ---- PWA / Installed sites ----     fun installAsPwa(         tabId: String,@@ -635,7 +628,6 @@ class WebViewModel(                     .putBoolean(P_JS_ENABLED, jsEnabled)                     .putBoolean(P_BLOCK_THIRD_PARTY, blockThirdPartyCookies)                     .putBoolean(P_DESKTOP_MODE, desktopMode)-                    .putBoolean(P_ADBLOCK, adBlockEnabled)                     .apply()             } catch (e: Exception) { Log.e(TAG, "persistPrefs failed", e) }         }