also looking at this
feat(android): the app-state trio in Zig — ratchet 59 → 56
#184
6 files
+422
-3
| @@ -2128,11 +2128,21 @@ class CraftBridge( | ||
| 2128 | 2128 | |
| 2129 | 2129 | @JavascriptInterface |
| 2130 | 2130 | 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 | ||
| 2131 | 2136 | return currentAppState |
| 2132 | 2137 | } |
| 2133 | 2138 | |
| 2134 | 2139 | @JavascriptInterface |
| 2135 | 2140 | 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 | ||
| 2136 | 2146 | activity.runOnUiThread { |
| 2137 | 2147 | ProcessLifecycleOwner.get().lifecycle.addObserver(appStateObserver) |
| 2138 | 2148 | } |
| @@ -2140,6 +2150,8 @@ class CraftBridge( | ||
| 2140 | 2150 | |
| 2141 | 2151 | @JavascriptInterface |
| 2142 | 2152 | fun stopAppStateMonitoring() { |
| 2153 | if (CraftNative.stopAppStateMonitoring(activity)) return | |
| 2154 | ||
| 2143 | 2155 | activity.runOnUiThread { |
| 2144 | 2156 | ProcessLifecycleOwner.get().lifecycle.removeObserver(appStateObserver) |
| 2145 | 2157 | } |