Migrate things into new UI design

This commit is contained in:
James Babcock committed 2026-07-07 00:52:47 -07:00
1 parent 1133f952e9
commit 68ab599856
21 files changed
+1262 -602

No files matched your search

@@ -14,14 +14,16 @@ import okhttp3.WebSocketListener;
/**
* Thin okhttp WebSocket wrapper for the TypeScript side. Text frames only
* (the g2mirror protocol is JSON-in-text-frames). All listener callbacks are
* posted to the main thread, where the NativeScript runtime expects them.
* (the g2mirror protocol is JSON-in-text-frames). Listener callbacks are
* posted to the Looper of the thread that constructed this object, so a JS
* isolate (main thread or app worker) always receives them on its own
* thread; a Looper-less constructing thread falls back to the main thread.
*/
public class FaceclawWebSocket {
private static final String TAG = "FaceclawWebSocket";
private static final Handler mainHandler = new Handler(Looper.getMainLooper());
private static volatile OkHttpClient sharedClient;
private final Handler callbackHandler;
private final WebSocket socket;
private volatile boolean closeRequested;
@@ -35,6 +37,8 @@ public class FaceclawWebSocket {
if (listener == null) {
throw new IllegalArgumentException("listener is required");
}
Looper looper = Looper.myLooper();
callbackHandler = new Handler(looper != null ? looper : Looper.getMainLooper());
Request.Builder builder = new Request.Builder().url(url.trim());
if (headerName != null && !headerName.isEmpty() && headerValue != null) {
builder.addHeader(headerName, headerValue);
@@ -51,7 +55,7 @@ public class FaceclawWebSocket {
+ " headers=[" + headerLog.toString().trim() + "]");
socket = getClient().newWebSocket(request, new WebSocketListener() {
@Override public void onOpen(WebSocket webSocket, Response response) {
mainHandler.post(() -> {
callbackHandler.post(() -> {
try {
listener.onOpen();
} catch (Throwable t) {
@@ -61,7 +65,7 @@ public class FaceclawWebSocket {
}
@Override public void onMessage(WebSocket webSocket, String text) {
mainHandler.post(() -> {
callbackHandler.post(() -> {
try {
listener.onTextMessage(text);
} catch (Throwable t) {
@@ -75,7 +79,7 @@ public class FaceclawWebSocket {
}
@Override public void onClosed(WebSocket webSocket, int code, String reason) {
mainHandler.post(() -> {
callbackHandler.post(() -> {
try {
listener.onClosed(code, reason == null ? "" : reason);
} catch (Throwable t) {
@@ -89,7 +93,7 @@ public class FaceclawWebSocket {
return;
}
final String message = t == null ? "unknown websocket failure" : String.valueOf(t);
mainHandler.post(() -> {
callbackHandler.post(() -> {
try {
listener.onFailure(message);
} catch (Throwable inner) {
@@ -85,10 +85,13 @@ public class BmpUtil {
}
private static int grayToNibble(int value) {
// Truncate rather than round up: the shell's color-key convention
// paints intentional black as 1 (0 being transparent), which must
// land on nibble 0, not a faintly-visible level 1.
if (value <= 0) {
return 0;
}
return Math.min(15, (value + 15) >> 4);
return Math.min(15, value >> 4);
}
private static void putUint16Le(byte[] buf, int offset, int value) {