forked from Blendman974/faceclaw
Add tokens and faceclaw-input script, which allows using a CLI utility as an input device for the glasses
This commit is contained in:
1 parent
313ba85708
commit
ccb320c66f
32 files changed
+1785
-12
No files matched your search
@@ -362,7 +362,8 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
// Enter ("\r") after a wrapper-side pause so paste-detecting apps
|
||||
// (e.g. Claude Code) submit instead of inserting a newline.
|
||||
if (window && window.kind === "view") {
|
||||
window.client.submitInput(message.text);
|
||||
if (message.submit === false) window.client.sendInput(message.text);
|
||||
else window.client.submitInput(message.text);
|
||||
} else if (window && window.kind === "hub" && window.mode === "add") {
|
||||
terminalNewConnectionSetting.set(message.text);
|
||||
scheduleRender(window);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { startRemoteInput } from "../remote/service";
|
||||
import { acceptInput, resetRingInputFilter } from "../ui/input-monitor";
|
||||
import { Application, ImageSource } from "@nativescript/core";
|
||||
import { EvenAIStatus, EvenAIStatusName, EventSourceType, EventSourceTypeName, OsEventTypeList, OsEventTypeName, WatchGestureType, WatchGestureTypeName } from "./events";
|
||||
@@ -404,6 +405,15 @@ class DashboardController {
|
||||
this.syncAssistantBridge();
|
||||
// The watch drives the same synthetic-input path as the phone UI's test
|
||||
// buttons, plus app/window/lock commands; it mirrors the state below.
|
||||
startRemoteInput({
|
||||
ready: () => this.phase === "connected" || this.phase === "charging",
|
||||
locked: () => this.glassesLocked,
|
||||
input: (gesture, source) => this.injectSyntheticRingInput(gesture, source),
|
||||
acceptsText: () => !!shell.foregroundWindow()?.receiveTextInput,
|
||||
text: (text, submit) => { if (!shell.isScreenOn()) shell.wake("window"); shell.sendTextToForegroundWindow(text, { submit }); this.requestShellRender(); },
|
||||
assistantAvailable: () => shell.isAssistantAvailable(),
|
||||
assistant: text => shell.sendToAssistant(text),
|
||||
});
|
||||
this.wearRemote = new WearRemote({
|
||||
apps: LAUNCHABLE_APPS,
|
||||
injectInput: (kind) => this.injectSyntheticRingInput(kind, "watch"),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { startRemoteInput } from "../remote/service"
|
||||
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
|
||||
import { acceptInput, resetRingInputFilter } from "../ui/input-monitor";
|
||||
import { bindIosNotifications, iosNotificationsChanged, onIosNotificationPopup } from '../native/notification-icons.ios'
|
||||
@@ -170,6 +171,23 @@ export class IosPreviewController {
|
||||
shell.openNotificationModal(key, woke)
|
||||
this.requestShellRender()
|
||||
})
|
||||
startRemoteInput({
|
||||
ready: () => this.runtimeRunning,
|
||||
locked: () => this.glassesLocked,
|
||||
input: (gesture, source) => {
|
||||
// Share the controller queue with physical input. A discrete hold includes its release.
|
||||
const task = this.inputQueue.then(async () => {
|
||||
await this.receiveInput(makeInputEvent({ type: gesture, source } as InputEventPayload))
|
||||
if (gesture === 'long-press') await this.receiveInput(makeInputEvent({ type: 'long-press-release', source }))
|
||||
})
|
||||
this.inputQueue = task.catch(error => this.fail(error))
|
||||
return task
|
||||
},
|
||||
acceptsText: () => !!shell.foregroundWindow()?.receiveTextInput,
|
||||
text: (text, submit) => { if (!shell.isScreenOn()) shell.wake('window'); shell.sendTextToForegroundWindow(text, { submit }); this.requestShellRender() },
|
||||
assistantAvailable: () => shell.isAssistantAvailable(),
|
||||
assistant: text => shell.sendToAssistant(text),
|
||||
})
|
||||
registerSystemTools()
|
||||
registerWindowTools({ apps: ALL_APPS.filter(app => !iosAppUnavailableReason(app.appId)),
|
||||
launchApp: id => this.launchApp(id), requestShellRender: () => this.requestShellRender() })
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { createListenerPool, type InterfaceAddress } from '../remote/listeners';
|
||||
declare const FaceclawRemoteInput: any;
|
||||
export function remoteNative() {
|
||||
return createListenerPool(() => {
|
||||
const native = FaceclawRemoteInput.alloc().init();
|
||||
return { start: (port, address) => String(native.startAddress(port, address)), stop: () => native.stop(),
|
||||
nextRequest: () => native.nextRequest(), complete: (id, response) => native.completeResponse(id, response) };
|
||||
});
|
||||
}
|
||||
export function remoteInterfaces(): InterfaceAddress[] { return JSON.parse(String(FaceclawRemoteInput.interfaces())); }
|
||||
export function randomTokenSecret(): string { return String(FaceclawRemoteInput.shared().randomSecret()); }
|
||||
export function tokenHash(value: string): string { return String(FaceclawRemoteInput.shared().tokenDigest(value)); }
|
||||
export function copyRemoteToken(value: string): void { UIPasteboard.generalPasteboard.string = value; }
|
||||
@@ -0,0 +1,17 @@
|
||||
import { createListenerPool, type InterfaceAddress } from '../remote/listeners';
|
||||
import { Utils } from '@nativescript/core';
|
||||
declare const com: any;
|
||||
export function remoteNative() {
|
||||
return createListenerPool(() => {
|
||||
const native = new com.faceclaw.app.FaceclawRemoteInput();
|
||||
return { start: (port, address) => String(native.startAddress(port, address)), stop: () => native.stop(),
|
||||
nextRequest: () => native.nextRequest(), complete: (id, response) => native.complete(id, response) };
|
||||
});
|
||||
}
|
||||
export function remoteInterfaces(): InterfaceAddress[] { return JSON.parse(String(com.faceclaw.app.FaceclawRemoteInput.interfaces())); }
|
||||
export function randomTokenSecret(): string { return String(com.faceclaw.app.FaceclawRemoteInput.getInstance().randomSecret()); }
|
||||
export function tokenHash(value: string): string { return String(com.faceclaw.app.FaceclawRemoteInput.getInstance().hash(value)); }
|
||||
export function copyRemoteToken(value: string): void {
|
||||
const context = Utils.android.getApplicationContext();
|
||||
context.getSystemService('clipboard').setPrimaryClip(android.content.ClipData.newPlainText('Faceclaw input token', value));
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/** Interface selection never returns wildcard, Wi-Fi, cellular or LAN addresses. */
|
||||
export type InterfaceAddress = { name: string; address: string; pointToPoint: boolean };
|
||||
export const INTERFACE_STORAGE_KEY = 'remoteInput.interface';
|
||||
export function isTunnelInterface(item: InterfaceAddress): boolean {
|
||||
if (/^(wlan|wifi|wl|en\d|eth\d|rmnet|ccmni|pdp_ip|ap\d|p2p)/i.test(item.name)) return false;
|
||||
return item.pointToPoint || /^(tailscale|utun\d|tun\d|wg\d)/i.test(item.name);
|
||||
}
|
||||
function isTailnetAddress(address: string): boolean {
|
||||
const parts = address.split('.').map(Number);
|
||||
return /^fd7a:115c:a1e0:/i.test(address) || (parts.length === 4 && parts[0] === 100 && parts[1] >= 64 && parts[1] <= 127);
|
||||
}
|
||||
export function listenerAddresses(interfaces: InterfaceAddress[], selection: string): string[] {
|
||||
const addresses = ['127.0.0.1'];
|
||||
if (selection === 'localhost') return addresses;
|
||||
const tunnels = interfaces.filter(isTunnelInterface);
|
||||
// A generic tun/utun name alone does not identify Tailscale. Its dedicated
|
||||
// IPv6 prefix does; CGNAT IPv4 alone could belong to an unrelated VPN.
|
||||
const tailscaleNames = new Set(tunnels.filter(item => /^tailscale/i.test(item.name) ||
|
||||
/^fd7a:115c:a1e0:/i.test(item.address)).map(item => item.name));
|
||||
for (const item of tunnels) {
|
||||
const selected = selection === 'tailscale'
|
||||
? tailscaleNames.has(item.name) && isTailnetAddress(item.address)
|
||||
: selection === `interface:${item.name}`;
|
||||
if (selected && item.address !== '0.0.0.0' && item.address !== '::' && !item.address.startsWith('fe80:')) addresses.push(item.address);
|
||||
}
|
||||
return [...new Set(addresses)].sort();
|
||||
}
|
||||
|
||||
export type NativeListener = {
|
||||
start(port: number, address: string): string;
|
||||
stop(): void;
|
||||
nextRequest(): string | null;
|
||||
complete(id: number, response: string): void;
|
||||
};
|
||||
/** Independent sockets preserve localhost access while adding/removing a VPN. */
|
||||
export function createListenerPool(create: () => NativeListener) {
|
||||
let nextId = 0, cursor = 0;
|
||||
const entries = new Map<string, { id: number; listener: NativeListener }>();
|
||||
return {
|
||||
start(port: number, addresses: string[]): string {
|
||||
for (const [address, entry] of entries) if (!addresses.includes(address)) { entry.listener.stop(); entries.delete(address); }
|
||||
const failures: string[] = [];
|
||||
for (const address of addresses) if (!entries.has(address)) {
|
||||
const listener = create();
|
||||
const error = listener.start(port, address);
|
||||
if (error) { listener.stop(); failures.push(`${address}: ${error}`); }
|
||||
else entries.set(address, { id: ++nextId, listener });
|
||||
}
|
||||
return failures.join('\n');
|
||||
},
|
||||
addresses(): string[] { return [...entries.keys()]; },
|
||||
stop(): void { for (const entry of entries.values()) entry.listener.stop(); entries.clear(); },
|
||||
nextRequest(): string | null {
|
||||
const active = [...entries.values()];
|
||||
for (let i = 0; i < active.length; i++) {
|
||||
const entry = active[cursor++ % active.length];
|
||||
const raw = entry.listener.nextRequest();
|
||||
if (raw) {
|
||||
const request = JSON.parse(String(raw));
|
||||
return JSON.stringify({ ...request, id: `${entry.id}/${request.id}` });
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
complete(id: string, response: string): void {
|
||||
const [entryId, requestId] = id.split('/').map(Number);
|
||||
for (const entry of entries.values()) if (entry.id === entryId) entry.listener.complete(requestId, response);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/** Local input API v1. Transport: one UTF-8 JSON line per TCP connection. */
|
||||
export const REMOTE_PORT = 8791;
|
||||
export const PERMISSIONS = ['input', 'text', 'assistant'] as const;
|
||||
export type Permission = typeof PERMISSIONS[number];
|
||||
export const GESTURES = ['click', 'double-click', 'long-press', 'short-then-long-press',
|
||||
'scroll-up', 'scroll-down', 'swipe-up', 'swipe-down', 'swipe-left', 'swipe-right'] as const;
|
||||
export type RemoteGesture = typeof GESTURES[number];
|
||||
export type TokenRecord = { id: string; name: string; hash: string; permissions: Permission[]; createdAt: number };
|
||||
export type RemoteHost = {
|
||||
ready(): boolean;
|
||||
locked(): boolean;
|
||||
input(gesture: RemoteGesture, source: 'watch' | 'ring'): Promise<void>;
|
||||
acceptsText(): boolean;
|
||||
text(text: string, submit: boolean): void;
|
||||
assistantAvailable(): boolean;
|
||||
assistant(text: string): void;
|
||||
};
|
||||
export type Reply = { ok: true } | { ok: false; error: string; message: string };
|
||||
const error = (code: string, message: string): Reply => ({ ok: false, error: code, message });
|
||||
|
||||
export class TokenStore {
|
||||
constructor(private readonly read: () => string, private readonly write: (json: string) => void,
|
||||
private readonly random: () => string, private readonly hash: (value: string) => string) {}
|
||||
list(): TokenRecord[] {
|
||||
try {
|
||||
const parsed = JSON.parse(this.read());
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
return parsed.filter((r): r is TokenRecord => r && typeof r.id === 'string' &&
|
||||
typeof r.name === 'string' && /^[a-f0-9]{64}$/.test(r.hash) && typeof r.createdAt === 'number' &&
|
||||
Array.isArray(r.permissions) && r.permissions.every((p: Permission) => PERMISSIONS.includes(p)));
|
||||
} catch { return []; }
|
||||
}
|
||||
create(name: string, permissions: Permission[]): { token: string; record: TokenRecord } {
|
||||
if (!name.trim() || name.length > 80) throw new Error('Enter a token name (1–80 characters).');
|
||||
if (!permissions.length || !permissions.every(p => PERMISSIONS.includes(p))) throw new Error('Select at least one permission.');
|
||||
const records = this.list();
|
||||
if (records.length >= 32) throw new Error('Revoke a token before creating more (maximum 32).');
|
||||
const secret = this.random();
|
||||
if (!/^[a-f0-9]{64}$/.test(secret)) throw new Error('Secure random token generation failed.');
|
||||
const token = `fc1_${secret}`;
|
||||
const hash = this.hash(token);
|
||||
const record = { id: hash.slice(0, 16), name: name.trim(), hash, permissions: [...new Set(permissions)], createdAt: Date.now() };
|
||||
this.write(JSON.stringify([...records, record]));
|
||||
return { token, record };
|
||||
}
|
||||
permissions(id: string, permissions: Permission[]): void {
|
||||
if (!permissions.every(p => PERMISSIONS.includes(p))) throw new Error('Invalid permission.');
|
||||
this.write(JSON.stringify(this.list().map(r => r.id === id ? { ...r, permissions: [...new Set(permissions)] } : r)));
|
||||
}
|
||||
revoke(id: string): void { this.write(JSON.stringify(this.list().filter(r => r.id !== id))); }
|
||||
authenticate(token: unknown): TokenRecord | undefined {
|
||||
if (typeof token !== 'string' || !/^fc1_[a-f0-9]{64}$/.test(token)) return undefined;
|
||||
const digest = this.hash(token);
|
||||
// Compare fixed-size digests without an early exit on mismatching bytes.
|
||||
return this.list().find(r => {
|
||||
let difference = r.hash.length ^ digest.length;
|
||||
for (let i = 0; i < 64; i++) difference |= r.hash.charCodeAt(i) ^ digest.charCodeAt(i);
|
||||
return difference === 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleRequest(body: string, tokens: TokenStore, host: RemoteHost): Promise<Reply> {
|
||||
let request: any;
|
||||
try { request = JSON.parse(body); } catch { return error('bad_request', 'Expected a JSON object.'); }
|
||||
if (!request || typeof request !== 'object' || Array.isArray(request)) return error('bad_request', 'Expected a JSON object.');
|
||||
const token = tokens.authenticate(request.token);
|
||||
if (!token) return error('unauthorized', 'Invalid or revoked token.');
|
||||
if (request.version !== 1 || (request.action !== 'ping' && !PERMISSIONS.includes(request.action))) return error('bad_request', 'Expected version 1 and action ping, input, text or assistant.');
|
||||
if (request.action === 'ping') {
|
||||
if (request.permission !== undefined && !PERMISSIONS.includes(request.permission)) return error('bad_request', 'Invalid permission.');
|
||||
if (request.permission && !token.permissions.includes(request.permission)) return error('forbidden', `Token lacks ${request.permission} permission.`);
|
||||
return { ok: true };
|
||||
}
|
||||
if (request.action === 'text' && request.submit !== undefined && typeof request.submit !== 'boolean') return error('bad_request', 'submit must be a boolean.');
|
||||
if (!token.permissions.includes(request.action)) return error('forbidden', `Token lacks ${request.action} permission.`);
|
||||
if (request.action === 'input') {
|
||||
if (!GESTURES.includes(request.gesture) || !['watch', 'ring'].includes(request.source ?? 'watch') ||
|
||||
(request.source === 'ring' && request.gesture.startsWith('swipe-'))) {
|
||||
return error('bad_request', 'Invalid gesture or source; directions require watch input.');
|
||||
}
|
||||
} else if (typeof request.text !== 'string' || !request.text.trim() || request.text.length > 8000 || request.text.includes('\0')) {
|
||||
return error('bad_request', 'Text must contain 1–8000 characters without NUL.');
|
||||
}
|
||||
if (!host.ready()) return error('unavailable', 'Faceclaw is not ready for input.');
|
||||
// Gestures follow the normal lock-screen path. Text must never bypass it.
|
||||
if (request.action !== 'input' && host.locked()) return error('locked', 'The glasses are locked.');
|
||||
try {
|
||||
if (request.action === 'input') await host.input(request.gesture, request.source ?? 'watch');
|
||||
else if (request.action === 'text') {
|
||||
if (!host.acceptsText()) return error('unavailable', 'The foreground window does not accept text.');
|
||||
host.text(request.text, request.submit !== false);
|
||||
} else {
|
||||
if (!host.assistantAvailable()) return error('unavailable', 'Set up the voice assistant in Settings first.');
|
||||
host.assistant(request.text);
|
||||
}
|
||||
return { ok: true };
|
||||
} catch { return error('failed', 'Faceclaw could not deliver the request.'); }
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { getStringSetting, setStringSetting, onSettingsStoreChanged } from '../native/settings-store';
|
||||
import { remoteNative, remoteInterfaces, randomTokenSecret, tokenHash } from '../native/remote-input';
|
||||
import { INTERFACE_STORAGE_KEY, listenerAddresses } from './listeners';
|
||||
import { TokenStore, handleRequest, REMOTE_PORT, type RemoteHost } from './protocol';
|
||||
export const TOKEN_STORAGE_KEY = 'remoteInput.tokens.v1';
|
||||
export const remoteTokens = new TokenStore(() => getStringSetting(TOKEN_STORAGE_KEY, '[]'),
|
||||
value => setStringSetting(TOKEN_STORAGE_KEY, value), randomTokenSecret, tokenHash);
|
||||
let status = 'No tokens; listener stopped.';
|
||||
export function remoteInputStatus(): string { return status; }
|
||||
export function remoteInterfaceSelection(): string { return getStringSetting(INTERFACE_STORAGE_KEY, 'tailscale'); }
|
||||
export function selectRemoteInterface(value: string): void { setStringSetting(INTERFACE_STORAGE_KEY, value); }
|
||||
|
||||
/** Owned by the main controller. Native socket work never enters a JS isolate. */
|
||||
export function startRemoteInput(host: RemoteHost): () => void {
|
||||
const native = remoteNative();
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
let busy = false;
|
||||
let networkTimer: ReturnType<typeof setInterval> | null = null;
|
||||
const sync = () => {
|
||||
if (!remoteTokens.list().length) {
|
||||
native.stop();
|
||||
if (timer !== null) clearInterval(timer);
|
||||
timer = null;
|
||||
if (networkTimer !== null) clearInterval(networkTimer);
|
||||
networkTimer = null;
|
||||
status = 'No tokens; listener stopped.';
|
||||
return;
|
||||
}
|
||||
const selection = remoteInterfaceSelection();
|
||||
const addresses = listenerAddresses(remoteInterfaces(), selection);
|
||||
const failure = native.start(REMOTE_PORT, addresses);
|
||||
status = `Listening on ${native.addresses().map(address => `${address.includes(':') ? `[${address}]` : address}:${REMOTE_PORT}`).join(', ') || 'no addresses'}.`;
|
||||
if (selection !== 'localhost' && addresses.length === 1) status += '\nSelected tunnel not found; localhost only. Enable Tailscale or select its tunnel interface.';
|
||||
if (failure) status += `\n${failure}`;
|
||||
// Reconcile after VPN reconnects/address changes; unchanged sockets stay open.
|
||||
if (networkTimer === null) networkTimer = setInterval(sync, 3000);
|
||||
if (timer !== null) return;
|
||||
timer = setInterval(() => {
|
||||
if (busy) return;
|
||||
const raw = native.nextRequest();
|
||||
if (!raw) return;
|
||||
const request = JSON.parse(String(raw));
|
||||
if (Date.now() >= request.expiresAt) return;
|
||||
busy = true;
|
||||
void handleRequest(request.body, remoteTokens, host)
|
||||
.then(reply => native.complete(request.id, JSON.stringify(reply)))
|
||||
.catch(() => native.complete(request.id, JSON.stringify({ ok: false, error: 'failed', message: 'Request failed.' })))
|
||||
.finally(() => { busy = false; });
|
||||
}, 15);
|
||||
};
|
||||
sync();
|
||||
const off = onSettingsStoreChanged(key => { if (key === TOKEN_STORAGE_KEY || key === INTERFACE_STORAGE_KEY) sync(); });
|
||||
return () => { off(); if (timer !== null) clearInterval(timer); if (networkTimer !== null) clearInterval(networkTimer); native.stop(); };
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { remoteTokens, remoteInputStatus, remoteInterfaceSelection, selectRemoteInterface } from '../../remote/service';
|
||||
import { PERMISSIONS, type Permission } from '../../remote/protocol';
|
||||
import { isTunnelInterface } from '../../remote/listeners';
|
||||
import { copyRemoteToken, remoteInterfaces } from '../../native/remote-input';
|
||||
import { TextViewerLayer } from '../../apps/files/text-viewer';
|
||||
import { ConfigSettingString, textSettingMenuItem } from '../dashboard-settings';
|
||||
import { getDefaultSmallFont } from '../../graphics/ui-fonts';
|
||||
import { drawRightValueMenuItem, type MenuItem } from '../menu';
|
||||
import { type LayerContext } from '../layers';
|
||||
import { openSettingsSubMenu } from './settings-panel';
|
||||
|
||||
const labels: Record<Permission, string> = { input: 'Provide input', text: 'Text to foreground window', assistant: 'Text to voice assistant' };
|
||||
const nameSetting = new ConfigSettingString({ id: 'remoteInputNewName', storageKey: 'remoteInput.newName',
|
||||
label: 'Token name', defaultValue: 'My app', normalize: value => (value ?? '').slice(0, 80) });
|
||||
|
||||
function permissionItem(permission: Permission, get: () => Permission[], set: (values: Permission[]) => void): MenuItem {
|
||||
return { label: labels[permission], onSelect: ctx => {
|
||||
const current = get();
|
||||
set(current.includes(permission) ? current.filter(p => p !== permission) : [...current, permission]);
|
||||
ctx.actions.requestRender();
|
||||
}, render: ({ image, x, y, width }) => drawRightValueMenuItem(image, getDefaultSmallFont(), x, y, width,
|
||||
labels[permission], get().includes(permission) ? 'On' : 'Off') };
|
||||
}
|
||||
function showError(ctx: LayerContext, error: unknown): void {
|
||||
ctx.stack.push(new TextViewerLayer(error instanceof Error ? error.message : 'Could not update token.', 'Input tokens'));
|
||||
}
|
||||
function tokenDetails(ctx: LayerContext, id: string): void {
|
||||
const record = remoteTokens.list().find(r => r.id === id);
|
||||
if (!record) return;
|
||||
openSettingsSubMenu(ctx, record.name, [
|
||||
...PERMISSIONS.map(p => permissionItem(p, () => remoteTokens.list().find(r => r.id === id)?.permissions ?? [],
|
||||
values => remoteTokens.permissions(id, values))),
|
||||
{ label: 'Revoke token', onSelect: inner => openSettingsSubMenu(inner, `Revoke ${record.name}?`, [
|
||||
{ label: 'Cancel', onSelect: c => { c.stack.pop(); } },
|
||||
{ label: 'Revoke', onSelect: c => {
|
||||
remoteTokens.revoke(id);
|
||||
c.stack.pop(); c.stack.pop(); c.stack.pop();
|
||||
openTokens(c);
|
||||
} },
|
||||
]) },
|
||||
]);
|
||||
}
|
||||
function createToken(ctx: LayerContext): void {
|
||||
let permissions: Permission[] = ['input'];
|
||||
openSettingsSubMenu(ctx, 'Create input token', [
|
||||
textSettingMenuItem(nameSetting),
|
||||
...PERMISSIONS.map(p => permissionItem(p, () => permissions, values => { permissions = values; })),
|
||||
{ label: 'Generate token', onSelect: inner => {
|
||||
try {
|
||||
const { token } = remoteTokens.create(nameSetting.get(), permissions);
|
||||
inner.stack.pop(); inner.stack.pop();
|
||||
openTokens(inner);
|
||||
// The secret lives only in this temporary menu; it cannot be recovered after closing it.
|
||||
openSettingsSubMenu(inner, 'Save your token now', [
|
||||
{ label: 'Copy token to phone clipboard', onSelect: c => {
|
||||
try { copyRemoteToken(token); c.stack.push(new TextViewerLayer('Token copied. Save it in the calling app or FACECLAW_TOKEN. The secret cannot be shown again after leaving this menu.', 'Copied')); }
|
||||
catch (error) { showError(c, error); }
|
||||
} },
|
||||
{ label: 'Show token (only available now)', onSelect: c => c.stack.push(new TextViewerLayer(token, 'Input token')) },
|
||||
{ label: 'Done', onSelect: c => { c.stack.pop(); } },
|
||||
]);
|
||||
} catch (error) { showError(inner, error); }
|
||||
} },
|
||||
]);
|
||||
}
|
||||
function interfaceMenu(ctx: LayerContext): void {
|
||||
const interfaces = remoteInterfaces().filter(isTunnelInterface);
|
||||
const names = [...new Set(interfaces.map(item => item.name))];
|
||||
const choices = [
|
||||
{ value: 'tailscale', label: 'Localhost + Tailscale (auto)' },
|
||||
{ value: 'localhost', label: 'Localhost / USB only' },
|
||||
...names.map(name => ({ value: `interface:${name}`, label: `${name}: ${interfaces.filter(item => item.name === name).map(item => item.address).join(', ')}` })),
|
||||
];
|
||||
openSettingsSubMenu(ctx, 'Listening interfaces', choices.map(choice => ({
|
||||
label: `${choice.label}${remoteInterfaceSelection() === choice.value ? ' *' : ''}`,
|
||||
onSelect: inner => { selectRemoteInterface(choice.value); inner.stack.pop(); },
|
||||
})));
|
||||
}
|
||||
function openTokens(ctx: LayerContext): void {
|
||||
openSettingsSubMenu(ctx, 'Input tokens', [
|
||||
{ label: 'Create token', onSelect: createToken },
|
||||
{ label: 'Listening interfaces', onSelect: interfaceMenu },
|
||||
{ label: 'Connection information', onSelect: c => c.stack.push(new TextViewerLayer(
|
||||
`${remoteInputStatus()}\n\nAndroid USB: adb forward tcp:8791 tcp:8791\n\niOS USB: iproxy 8791 8791\n\nTailscale: use --host with the displayed tunnel IP. Listening interfaces lets you select a tunnel if auto detection fails. Wi-Fi/LAN addresses are never selected.\n\nUse scripts/faceclaw-input.cjs with FACECLAW_TOKEN set. Tokens grant only the selected permissions. Revoking a token takes effect on the next request. Text is blocked while the glasses are locked.`, 'Input API')) },
|
||||
...remoteTokens.list().map(record => ({ label: record.name, onSelect: (c: LayerContext) => tokenDetails(c, record.id) })),
|
||||
]);
|
||||
}
|
||||
export function remoteInputMenuItem(): MenuItem {
|
||||
return { label: 'Input tokens', description: 'Allow another app to provide ring/watch input, type into the foreground window, or send messages to the voice assistant. Create tokens with individual permissions and revoke them here.', onSelect: openTokens };
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { remoteInputMenuItem } from "./remote-input-menu";
|
||||
import { knownFolders } from "@nativescript/core";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import type { GrayImage } from "../../graphics/image";
|
||||
@@ -144,6 +145,7 @@ function settingsSections(): SettingsSection[] {
|
||||
{
|
||||
label: "API Keys",
|
||||
items: [
|
||||
remoteInputMenuItem(),
|
||||
textSettingMenuItem(elevenLabsApiKeySetting),
|
||||
textSettingMenuItem(openAiApiKeySetting),
|
||||
textSettingMenuItem(sonioxApiKeySetting),
|
||||
|
||||
@@ -137,7 +137,7 @@ export type ShellWindow = {
|
||||
* Deliver a text string to the window (e.g. finalized voice input). Optional:
|
||||
* only windows that consume typed text (the terminal) implement it.
|
||||
*/
|
||||
receiveTextInput?: (text: string) => void;
|
||||
receiveTextInput?: (text: string, options?: { submit?: boolean }) => void;
|
||||
/** Foreground state changed: this window's surface is (not) the visible one. */
|
||||
setForeground?: (foreground: boolean) => void;
|
||||
/**
|
||||
@@ -1105,8 +1105,8 @@ class Shell {
|
||||
}
|
||||
|
||||
/** Deliver a text string to the foreground window (e.g. finalized voice input). */
|
||||
sendTextToForegroundWindow(text: string): void {
|
||||
this.foregroundWindow()?.receiveTextInput?.(text);
|
||||
sendTextToForegroundWindow(text: string, options?: { submit?: boolean }): void {
|
||||
this.foregroundWindow()?.receiveTextInput?.(text, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,7 @@ export type WorkerAppMessage =
|
||||
| { type: "resize-window"; windowId: string; viewport: { width: number; height: number } }
|
||||
| { type: "close-window"; windowId: string }
|
||||
| { type: "input"; windowId: string; event: unknown; frameId: number; focused: boolean }
|
||||
| { type: "text-input"; windowId: string; text: string }
|
||||
| { type: "text-input"; windowId: string; text: string; submit?: boolean }
|
||||
| { type: "render"; windowId: string; focused: boolean }
|
||||
| { type: "foreground"; windowId: string; foreground: boolean; focused: boolean }
|
||||
/**
|
||||
@@ -441,8 +441,8 @@ export class WorkerAppHost {
|
||||
requestRender: () => {
|
||||
this.post({ type: "render", windowId: spec.windowId, focused: shell.isWindowFocused(spec.windowId) });
|
||||
},
|
||||
receiveTextInput: (text) => {
|
||||
this.post({ type: "text-input", windowId: spec.windowId, text });
|
||||
receiveTextInput: (text, options) => {
|
||||
this.post({ type: "text-input", windowId: spec.windowId, text, ...(options?.submit === undefined ? {} : { submit: options.submit }) });
|
||||
},
|
||||
setForeground: (foreground) => {
|
||||
this.options.setSurfaceVisible(surfaceId, foreground);
|
||||
|
||||
Reference in new issue
Block a user