forked from Blendman974/faceclaw
Add options to load an app from a URL or a QR code
(The QR code reading does not work yet)
This commit is contained in:
1 parent
6e4ece5dc7
commit
92cd05b6ca
22 files changed
+685
-93
No files matched your search
@@ -5,6 +5,9 @@ dependencies {
|
||||
// implementation 'androidx.multidex:multidex:2.0.1'
|
||||
// WebSocket transport for the g2mirror terminal-mirroring client.
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
|
||||
// WebViewCompat.addDocumentStartJavaScript, for injecting the EvenHub bridge
|
||||
// shim into remotely hosted apps (developer "Load app from URL").
|
||||
implementation 'androidx.webkit:webkit:1.12.1'
|
||||
}
|
||||
|
||||
def faceclawSherpaOnnxVersion = "1.13.0"
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.faceclaw.app;
|
||||
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import androidx.webkit.WebViewCompat;
|
||||
import androidx.webkit.WebViewFeature;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Injects the EvenHub bridge shim at document start into a WebView that loads
|
||||
* a page over the real network (the developer "Load app from URL" flow).
|
||||
*
|
||||
* Packaged apps get the shim spliced into the HTML they are served
|
||||
* (FaceclawEvenHubWebViewClient), which is not an option for a page fetched
|
||||
* from a live server. WebViewCompat.addDocumentStartJavaScript is the
|
||||
* supported way to run script before any page script, and unlike an
|
||||
* onPageStarted evaluateJavascript it is guaranteed to win the race — apps
|
||||
* poll for window.flutter_inappwebview with a few seconds' patience, but the
|
||||
* timer shim must be in place before the app captures setTimeout.
|
||||
*
|
||||
* Requires WebView 83+; the caller falls back to onPageStarted injection when
|
||||
* this returns false.
|
||||
*/
|
||||
public final class FaceclawEvenHubDocumentStart {
|
||||
private static final String TAG = "FaceclawEvenHub";
|
||||
|
||||
private FaceclawEvenHubDocumentStart() {}
|
||||
|
||||
/**
|
||||
* @param originRule an allowed-origin rule, e.g. "https://example.com" or "*".
|
||||
* @return whether the script was registered.
|
||||
*/
|
||||
public static boolean install(WebView webView, String script, String originRule) {
|
||||
if (!WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) {
|
||||
Log.w(TAG, "document-start scripts unsupported; falling back to onPageStarted");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Set<String> rules = Collections.singleton(originRule);
|
||||
WebViewCompat.addDocumentStartJavaScript(webView, script, rules);
|
||||
return true;
|
||||
} catch (Throwable error) {
|
||||
Log.w(TAG, "addDocumentStartJavaScript failed for " + originRule, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-1
@@ -28,6 +28,12 @@ import java.util.Locale;
|
||||
* shouldInterceptRequest runs on a WebView-internal thread; it only touches
|
||||
* files, never the NativeScript runtime. Requests to other hosts fall
|
||||
* through to the network (the manifest whitelist is not yet enforced).
|
||||
*
|
||||
* A developer-loaded app ("Load app from URL") has no local root: host is
|
||||
* empty, nothing is intercepted, and the page loads normally from its server.
|
||||
* The shim is registered as a document-start script instead
|
||||
* (FaceclawEvenHubDocumentStart); injectOnPageStarted is the fallback for
|
||||
* WebView versions that lack that API.
|
||||
*/
|
||||
public class FaceclawEvenHubWebViewClient extends WebViewClient {
|
||||
private static final String TAG = "FaceclawEvenHub";
|
||||
@@ -35,19 +41,28 @@ public class FaceclawEvenHubWebViewClient extends WebViewClient {
|
||||
private final String rootDir;
|
||||
private final String host;
|
||||
private final String injectScript;
|
||||
private final boolean injectOnPageStarted;
|
||||
private final FaceclawEvenHubListener listener;
|
||||
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
public FaceclawEvenHubWebViewClient(
|
||||
String rootDir, String host, String injectScript, FaceclawEvenHubListener listener) {
|
||||
String rootDir,
|
||||
String host,
|
||||
String injectScript,
|
||||
boolean injectOnPageStarted,
|
||||
FaceclawEvenHubListener listener) {
|
||||
this.rootDir = rootDir;
|
||||
this.host = host;
|
||||
this.injectScript = injectScript;
|
||||
this.injectOnPageStarted = injectOnPageStarted;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
if (host == null || host.isEmpty()) {
|
||||
return null; // Remote app: everything comes from the network.
|
||||
}
|
||||
Uri url = request.getUrl();
|
||||
if (url == null || !host.equals(url.getHost())) {
|
||||
return null; // External hosts: normal network handling.
|
||||
@@ -79,6 +94,16 @@ public class FaceclawEvenHubWebViewClient extends WebViewClient {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) {
|
||||
super.onPageStarted(view, url, favicon);
|
||||
if (!injectOnPageStarted) return;
|
||||
// Best-effort: the document has committed but the parser has not run
|
||||
// the page's own scripts yet, so this usually lands first. Only used
|
||||
// when document-start scripts are unavailable.
|
||||
view.evaluateJavascript(injectScript, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, final String url) {
|
||||
mainHandler.post(new Runnable() {
|
||||
|
||||
Reference in new issue
Block a user