Notifications menu; UI refinements; teleprompt by sharing a text file

This commit is contained in:
James Babcock committed 2026-05-17 17:05:54 -07:00
1 parent ef6cb3bf55
commit 8d6fe60c79
12 files changed
+991 -36

No files matched your search

+1 -11
View File
@@ -2,8 +2,6 @@ import { Utils } from "@nativescript/core";
declare const com: any;
const FRAME_METRICS_LISTENER_MIN_INTERVAL_MS = 5_000;
export type CommunicatorPhase =
| "disconnected"
| "connecting"
@@ -75,7 +73,6 @@ export class FaceclawCommunicatorBridge {
private readonly batteryListeners = new Set<(state: HeadsetBatteryState) => void>();
private readonly evenAppConflictListeners = new Set<(message: string) => void>();
private readonly frameMetricsListeners = new Set<(metrics: FrameMetrics) => void>();
private lastFrameMetricsListenerEmitAtMs = 0;
constructor(addresses: { right: string; left: string; ring?: string }) {
const context = Utils.android.getApplicationContext();
@@ -135,14 +132,7 @@ export class FaceclawCommunicatorBridge {
for (const waiter of waiters) {
setTimeout(() => waiter(metrics), 0);
}
const now = Date.now();
if (
this.lastFrameMetricsListenerEmitAtMs === 0 ||
now - this.lastFrameMetricsListenerEmitAtMs >= FRAME_METRICS_LISTENER_MIN_INTERVAL_MS
) {
this.lastFrameMetricsListenerEmitAtMs = now;
this.emitAsync(this.frameMetricsListeners, metrics);
}
this.emitAsync(this.frameMetricsListeners, metrics);
},
});
this.communicator.setListener(this.listenerProxy);
+96
View File
@@ -9,6 +9,29 @@ const ICON_CACHE_MS = 5_000;
let cachedIcons: GrayImage[] = [];
let cachedAtMs = 0;
export type AndroidNotificationAction = {
index: number;
title: string;
enabled: boolean;
};
export type AndroidNotification = {
key: string;
packageName: string;
appName: string;
title: string;
text: string;
bigText: string;
subText: string;
infoText: string;
summaryText: string;
category: string;
lines: string[];
postTime: number;
when: number;
actions: AndroidNotificationAction[];
};
export function readActiveNotificationIcons(maxIcons: number): GrayImage[] {
if (!global.isAndroid || maxIcons <= 0) return [];
@@ -36,3 +59,76 @@ export function readActiveNotificationIcons(maxIcons: number): GrayImage[] {
cachedAtMs = now;
return icons.map(icon => icon.clone());
}
export function readActiveNotifications(maxNotifications = 50): AndroidNotification[] {
if (!global.isAndroid || maxNotifications <= 0) return [];
try {
const json = String(
com.faceclaw.app.FaceclawMediaNotificationListenerService.getActiveNotificationsJson(
Math.max(0, Math.round(maxNotifications)),
),
);
const parsed = JSON.parse(json);
if (!Array.isArray(parsed)) return [];
return parsed.map(normalizeNotification).filter((item): item is AndroidNotification => Boolean(item));
} catch {
return [];
}
}
export function invokeNotificationAction(notificationKey: string, actionIndex: number): boolean {
if (!global.isAndroid || !notificationKey) return false;
cachedAtMs = 0;
return Boolean(
com.faceclaw.app.FaceclawMediaNotificationListenerService.invokeNotificationAction(
notificationKey,
Math.round(actionIndex),
),
);
}
export function dismissNotification(notificationKey: string): boolean {
if (!global.isAndroid || !notificationKey) return false;
cachedAtMs = 0;
return Boolean(
com.faceclaw.app.FaceclawMediaNotificationListenerService.dismissNotification(notificationKey),
);
}
function normalizeNotification(value: any): AndroidNotification | null {
if (!value || typeof value !== "object") return null;
const key = String(value.key ?? "");
if (!key) return null;
const actions = Array.isArray(value.actions)
? value.actions.map(normalizeAction).filter((item): item is AndroidNotificationAction => Boolean(item))
: [];
return {
key,
packageName: String(value.packageName ?? ""),
appName: String(value.appName ?? value.packageName ?? ""),
title: String(value.title ?? ""),
text: String(value.text ?? ""),
bigText: String(value.bigText ?? ""),
subText: String(value.subText ?? ""),
infoText: String(value.infoText ?? ""),
summaryText: String(value.summaryText ?? ""),
category: String(value.category ?? ""),
lines: Array.isArray(value.lines) ? value.lines.map((line: unknown) => String(line)).filter(Boolean) : [],
postTime: Number(value.postTime) || 0,
when: Number(value.when) || 0,
actions,
};
}
function normalizeAction(value: any): AndroidNotificationAction | null {
if (!value || typeof value !== "object") return null;
const title = String(value.title ?? "");
if (!title) return null;
const index = Number(value.index);
if (!Number.isFinite(index)) return null;
return {
index,
title,
enabled: Boolean(value.enabled),
};
}
+94
View File
@@ -0,0 +1,94 @@
import { Application, isAndroid } from "@nativescript/core";
const MAX_SHARED_TEXT_CHARS = 200_000;
export function registerShareIntentHandler(): void {
if (!isAndroid) {
return;
}
Application.on(Application.launchEvent, (args) => {
const intent = (args as { android?: android.content.Intent }).android;
if (intent) {
void handleShareIntent(intent);
}
});
Application.android.on(Application.android.activityNewIntentEvent, (args) => {
const intent = (args as { intent?: android.content.Intent }).intent;
if (intent) {
Application.android.foregroundActivity?.setIntent(intent);
void handleShareIntent(intent);
}
});
}
async function handleShareIntent(intent: android.content.Intent): Promise<void> {
const text = readPlainTextShare(intent);
if (text === null) {
return;
}
const { dashboardController } = await import("../g2/dashboard-controller");
await dashboardController.openTelepromptDocument(text);
}
function readPlainTextShare(intent: android.content.Intent): string | null {
if (intent.getAction() !== android.content.Intent.ACTION_SEND) {
return null;
}
const mimeType = intent.getType();
if (mimeType !== null && !mimeType.toLowerCase().startsWith("text/")) {
return null;
}
const directText = intent.getCharSequenceExtra(android.content.Intent.EXTRA_TEXT);
if (directText !== null) {
return limitSharedText(String(directText));
}
const stream = intent.getParcelableExtra(android.content.Intent.EXTRA_STREAM) as android.net.Uri | null;
if (stream === null) {
return null;
}
return readTextUri(stream);
}
function readTextUri(uri: android.net.Uri): string | null {
const activity = Application.android.foregroundActivity ?? Application.android.startActivity;
const resolver = activity?.getContentResolver();
if (!resolver) {
return null;
}
const inputStream = resolver.openInputStream(uri);
if (inputStream === null) {
return null;
}
const reader = new java.io.BufferedReader(
new java.io.InputStreamReader(inputStream, java.nio.charset.Charset.forName("UTF-8")),
);
try {
const lines: string[] = [];
let totalLength = 0;
let line: string | null;
while ((line = reader.readLine()) !== null) {
const next = lines.length === 0 ? line : `\n${line}`;
if (totalLength + next.length > MAX_SHARED_TEXT_CHARS) {
lines.push(next.slice(0, MAX_SHARED_TEXT_CHARS - totalLength));
break;
}
lines.push(next);
totalLength += next.length;
}
return lines.join("");
} finally {
reader.close();
}
}
function limitSharedText(text: string): string {
return text.length <= MAX_SHARED_TEXT_CHARS ? text : text.slice(0, MAX_SHARED_TEXT_CHARS);
}