From c6575a08887f1d07cf4118e6bc7c1de2b8114cf0 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 27 Jun 2026 18:42:27 -0400 Subject: [PATCH] fix(napplet): drop algorithmic darkening so dark-by-default sites aren't corrupted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit setAlgorithmicDarkeningAllowed(true) was added to force-darken pages that don't implement prefers-color-scheme. Combined with nightThemedContext (which forces the embed WebView's isLightTheme=false), it now also runs on pages that are ALREADY dark but don't declare CSS color-scheme support — e.g. ditto.pub, which ships by default — and algorithmically inverts their nav bars to light, leaving "dark content, light bars". prefers-color-scheme: dark is driven by isLightTheme (nightThemedContext) INDEPENDENTLY of algorithmic darkening — device-verified: embedded pages still report prefersDark=true with darkening off — so dropping it keeps real dark-aware sites dark while no longer corrupting dark-by-default ones. The trade-off (a site with no dark mode of its own renders light instead of being force-inverted) matches how a real mobile browser behaves. Removed from all four embed/host WebView configs (browser + nsite/napplet, embedded + full-screen) along with the now-unused WebSettingsCompat import. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../amethyst/napplethost/NappletBrowserActivity.kt | 4 ---- .../amethyst/napplethost/NappletBrowserService.kt | 4 ---- .../vitorpamplona/amethyst/napplethost/NappletHostActivity.kt | 4 ---- .../vitorpamplona/amethyst/napplethost/NappletHostService.kt | 4 ---- 4 files changed, 16 deletions(-) diff --git a/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletBrowserActivity.kt b/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletBrowserActivity.kt index 5eef258f37..ef053427ea 100644 --- a/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletBrowserActivity.kt +++ b/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletBrowserActivity.kt @@ -60,7 +60,6 @@ import androidx.webkit.JavaScriptReplyProxy import androidx.webkit.ProxyConfig import androidx.webkit.ProxyController import androidx.webkit.WebMessageCompat -import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewCompat import androidx.webkit.WebViewFeature import com.vitorpamplona.amethyst.commons.browser.OmniboxInput @@ -315,9 +314,6 @@ class NappletBrowserActivity : ComponentActivity() { safeBrowsingEnabled = true } } - if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) { - WebSettingsCompat.setAlgorithmicDarkeningAllowed(wv.settings, true) - } WebView.setWebContentsDebuggingEnabled(false) wv.webViewClient = BrowserClient() wv.webChromeClient = BrowserChromeClient() diff --git a/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletBrowserService.kt b/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletBrowserService.kt index 5f000eef66..3ba6e87554 100644 --- a/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletBrowserService.kt +++ b/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletBrowserService.kt @@ -48,7 +48,6 @@ import androidx.annotation.RequiresApi import androidx.privacysandbox.ui.provider.toCoreLibInfo import androidx.webkit.JavaScriptReplyProxy import androidx.webkit.WebMessageCompat -import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewCompat import androidx.webkit.WebViewFeature import com.vitorpamplona.amethyst.commons.browser.OmniboxInput @@ -313,9 +312,6 @@ class NappletBrowserService : Service() { safeBrowsingEnabled = true } } - if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) { - WebSettingsCompat.setAlgorithmicDarkeningAllowed(wv.settings, true) - } WebView.setWebContentsDebuggingEnabled(false) wv.webViewClient = BrowserClient(tab) wv.webChromeClient = BrowserChromeClient(tab) diff --git a/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletHostActivity.kt b/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletHostActivity.kt index d6b3b878c5..4861ab7798 100644 --- a/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletHostActivity.kt +++ b/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletHostActivity.kt @@ -62,7 +62,6 @@ import androidx.webkit.JavaScriptReplyProxy import androidx.webkit.ProxyConfig import androidx.webkit.ProxyController import androidx.webkit.WebMessageCompat -import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewCompat import androidx.webkit.WebViewFeature import com.vitorpamplona.amethyst.commons.napplet.NappletWebContract @@ -507,9 +506,6 @@ class NappletHostActivity : ComponentActivity() { safeBrowsingEnabled = true } } - if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) { - WebSettingsCompat.setAlgorithmicDarkeningAllowed(webView.settings, true) - } // Disable the overscroll stretch/glow: forcing a scroll past the content edge stretched the // WebView's output and exposed the shell document's background behind the applet iframe at the // seam (a stray white band at the bottom). The applet's own content still scrolls normally. diff --git a/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletHostService.kt b/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletHostService.kt index 79de4ee87e..b2fe56b483 100644 --- a/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletHostService.kt +++ b/nappletHost/src/main/kotlin/com/vitorpamplona/amethyst/napplethost/NappletHostService.kt @@ -50,7 +50,6 @@ import androidx.webkit.JavaScriptReplyProxy import androidx.webkit.ProxyConfig import androidx.webkit.ProxyController import androidx.webkit.WebMessageCompat -import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewCompat import androidx.webkit.WebViewFeature import com.vitorpamplona.amethyst.commons.napplet.NappletWebContract @@ -340,9 +339,6 @@ class NappletHostService : Service() { safeBrowsingEnabled = true } } - if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)) { - WebSettingsCompat.setAlgorithmicDarkeningAllowed(wv.settings, true) - } wv.overScrollMode = View.OVER_SCROLL_NEVER WebView.setWebContentsDebuggingEnabled(false) wv.webViewClient = HostClient(tab)