ReviewOS

also looking at this

craft-native/craft

feat(android): the app-state trio in Zig — ratchet 59 → 56

#184
Merged glennmichael123 wants to merge feat/android-app-state into main
6 files +422 -3
packages/android/templates/CraftBridge.kt.templatemodified+12-0
Changes to packages/android/templates/CraftBridge.kt.template
@@ -2128,11 +2128,21 @@ class CraftBridge(
21282128
21292129 @JavascriptInterface
21302130 fun getAppState(): String {
2131 // Null is "Zig declined". Otherwise this is the state Zig's observer
2132 // has been maintaining, and currentAppState below is the one this
2133 // file's observer maintains — whichever of the two is running.
2134 CraftNative.getAppState()?.let { return it }
2135
21312136 return currentAppState
21322137 }
21332138
21342139 @JavascriptInterface
21352140 fun startAppStateMonitoring() {
2141 // The observer object is CraftNative's, and so is the state it
2142 // maintains — which is why getAppState below has to reach the same
2143 // way. All three move together or none of them can.
2144 if (CraftNative.startAppStateMonitoring(activity)) return
2145
21362146 activity.runOnUiThread {
21372147 ProcessLifecycleOwner.get().lifecycle.addObserver(appStateObserver)
21382148 }
@@ -2140,6 +2150,8 @@ class CraftBridge(
21402150
21412151 @JavascriptInterface
21422152 fun stopAppStateMonitoring() {
2153 if (CraftNative.stopAppStateMonitoring(activity)) return
2154
21432155 activity.runOnUiThread {
21442156 ProcessLifecycleOwner.get().lifecycle.removeObserver(appStateObserver)
21452157 }