diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubChromeClient.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubChromeClient.kt new file mode 100644 index 00000000..0b03f8d9 --- /dev/null +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubChromeClient.kt @@ -0,0 +1,22 @@ +package com.faceclaw.app + +import android.util.Log +import android.webkit.ConsoleMessage +import android.webkit.WebChromeClient + +/** + * Surfaces a hosted EvenHub app's console in logcat (tag FaceclawEvenHubConsole). + * Native rather than a NativeScript-extended WebChromeClient: chatty apps log + * many lines a second, and each one used to cost a Java->JS callback plus three + * JS->Java calls back to read the message, all on the main thread. + */ +class FaceclawEvenHubChromeClient : WebChromeClient() { + override fun onConsoleMessage(message: ConsoleMessage): Boolean { + Log.i(TAG, "${message.message()} (${message.sourceId()}:${message.lineNumber()})") + return true + } + + private companion object { + const val TAG = "FaceclawEvenHubConsole" + } +} diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt index 90c8c1e7..d099d419 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubJsBridge.kt @@ -23,4 +23,10 @@ class FaceclawEvenHubJsBridge(private val listener: FaceclawEvenHubListener) { listener.onEvenAppMessage(handlerName, argsJson, callId) } } + + /** The page's timer shim has work due before the host's next tick. */ + @JavascriptInterface + fun wakeTimers() { + FaceclawEvenHubWebViewHost.getInstance().wakeTimers() + } } diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.kt b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.kt index 7e563d0e..19d5a5a0 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.kt +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawEvenHubWebViewHost.kt @@ -1,6 +1,7 @@ package com.faceclaw.app import android.app.Activity +import android.content.MutableContextWrapper import android.os.Build import android.os.Handler import android.os.Looper @@ -10,6 +11,7 @@ import android.webkit.WebView import android.widget.FrameLayout import java.util.ArrayList +import java.util.HashMap /** * Keeps EvenHub app WebViews alive and rendering while the phone shows the @@ -38,9 +40,11 @@ import java.util.ArrayList * crawl even though the renderer is still alive. Host-initiated * evaluateJavascript is NOT subject to that throttle, so we drive the app's * timers ourselves: a document-start shim replaces setTimeout/setInterval (and - * requestAnimationFrame) with JS queues fired by window.__fcTimerTick() / - * __fcRafTick(), and this host ticks those on the main thread at a fixed rate - * regardless of screen state. The main Looper keeps running under the + * requestAnimationFrame) with JS queues fired by window.__fcTick(), and this + * host ticks those on the main thread regardless of screen state. The tick + * returns when the page next has work, so an idle page isn't evaluated at + * 60Hz; work scheduled between ticks wakes the host through + * FaceclawEvenHubJsBridge.wakeTimers. The main Looper keeps running under the * foreground service, so the tick survives the screen turning off. (Matches the * official Even app's approach.) * @@ -54,30 +58,87 @@ import java.util.ArrayList * timers/onResume asserted on attach. The main Looper keeps ticking under the * foreground service, so apps keep driving their glasses windows in the * background. + * + * Activity recreation: this host outlives any one activity (it is a process + * singleton, and apps keep running while the activity is destroyed and + * recreated, e.g. after an app update or a config change). The overlay lives in + * one activity's content view, so attach and showOnPhone first move it, with + * every WebView in it, into the activity they are given if it isn't already + * there; otherwise "show" would raise it in a dead window. WebViews are created + * on a MutableContextWrapper whose base is re-pointed at the same time, so the + * dialogs Chromium opens from the page (e.g. a