[docs] KeepHerSafeApps: Round trip on the tablet, the page between Android's bars, review, gaps closed, lessons

This commit is contained in:
2026-11-17 22:22:36 +01:00
parent e262b8f295
commit d5f37b3149
13 changed files with 243 additions and 32 deletions
@@ -6,12 +6,17 @@ package cz.mareknovak.domi.rosea
import android.app.Activity
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.webkit.JavascriptInterface
import android.webkit.WebView
import androidx.activity.enableEdgeToEdge
import androidx.annotation.Keep
import androidx.core.graphics.Insets
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
class MainActivity : TauriActivity() {
private var webView: WebView? = null
@@ -20,6 +25,31 @@ class MainActivity : TauriActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
// Tauri's activity draws edge to edge, and the WebView does not reliably report the bars as
// env(safe-area-inset-*): the clock sat over the title and the navigation bar over *Bring her
// back from a file* (keep-her-safe-apps review). So the page is kept between the bars, and
// the bars show the garden's own paper, light or dark as the system is.
paintBehindBars()
val bars = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content)) { view, insets ->
val inset = insets.getInsets(bars)
view.setPadding(inset.left, inset.top, inset.right, inset.bottom)
WindowInsetsCompat.Builder(insets)
.setInsets(WindowInsetsCompat.Type.systemBars(), Insets.NONE)
.setInsets(WindowInsetsCompat.Type.displayCutout(), Insets.NONE)
.build()
}
}
// The manifest lets the activity live through a theme change (uiMode), so the paint follows it here.
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
paintBehindBars()
}
private fun paintBehindBars() {
val night = (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
window.decorView.setBackgroundColor(Color.parseColor(if (night) PAPER_DARK else PAPER))
}
// *Save her to a file*: Android WebView does nothing with a blob download, so the game asks
@@ -83,5 +113,8 @@ class MainActivity : TauriActivity() {
private const val TAG = "RoseaFile"
private val NAME = Regex("^rose-\\d{4}-\\d{2}-\\d{2}\\.json$")
private const val MAX_CHARS = 8 * 1024 * 1024
// --paper in packages/ui/src/tokens.css, light and dark; a test holds them equal.
private const val PAPER = "#fbf6f1"
private const val PAPER_DARK = "#1d1819"
}
}
@@ -50,6 +50,17 @@ describe('the Android save bridge', () => {
expect(kotlin).toMatch(/@JavascriptInterface\s+fun save\(name: String, text: String\)/);
});
it("paints behind the system bars with the garden's own paper, light and dark", () => {
const tokens = readFileSync(join(HERE, '..', '..', '..', 'packages', 'ui', 'src', 'tokens.css'), 'utf8');
const papers = [...tokens.matchAll(/--paper:\s*(#[0-9a-f]{6})/gi)].map((m) => m[1]!.toLowerCase());
expect(papers).toHaveLength(2);
expect(/PAPER = "(#[0-9a-f]{6})"/i.exec(kotlin)?.[1]?.toLowerCase()).toBe(papers[0]);
expect(/PAPER_DARK = "(#[0-9a-f]{6})"/i.exec(kotlin)?.[1]?.toLowerCase()).toBe(papers[1]);
// A source check only; the proof is the tablet's screenshot (review). Exact call and padding:
expect(kotlin).toMatch(/ViewCompat\.setOnApplyWindowInsetsListener\(findViewById\(android\.R\.id\.content\)\)/);
expect(kotlin).toMatch(/view\.setPadding\(inset\.left, inset\.top, inset\.right, inset\.bottom\)/);
});
it('asks Android for nothing: the save screen needs no permission', () => {
// Asking at run time or naming one; the APK check (aapt2) refuses any declared in the manifest.
expect(kotlin).not.toMatch(/requestPermissions\(|Manifest\.permission|checkSelfPermission/);