package org.meshbay.client.shell import android.content.Context import android.view.View import android.webkit.WebView /** * While `keepVisible` is set, the WebView is told its window stayed visible * when the screen turns off. Chromium then never marks the page hidden, and * its freeze of hidden pages — exactly 60 s after hiding, measured (spike * S-2a C) — never starts. Set only while a cast runs or music plays: a page that is never * hidden is never throttled, which is the battery cost the freeze exists to * avoid. */ class ShellWebView(context: Context) : WebView(context) { var keepVisible = false override fun onWindowVisibilityChanged(visibility: Int) { super.onWindowVisibilityChanged(if (keepVisible) View.VISIBLE else visibility) } override fun onVisibilityChanged(changedView: View, visibility: Int) { super.onVisibilityChanged(changedView, if (keepVisible) View.VISIBLE else visibility) } }