forked from Blendman974/faceclaw
Fix an iOS issue where depth would be incorrect on first frame of fade-in on wake; also refine the keyboard input dialog
This commit is contained in:
1 parent
22f869d31c
commit
361b514f9a
21 files changed
+546
-138
No files matched your search
@@ -8,6 +8,16 @@ import { type VoiceSendTarget } from "./voice-input";
|
||||
/** A menu row: a send target, or Discard (no target). */
|
||||
type KeyboardMenuRow = InputDialogRow & { target?: VoiceSendTarget };
|
||||
|
||||
/**
|
||||
* Where the keyboard dialog shows: on both ends, only the phone's typing panel
|
||||
* (the glasses carry on as if no dialog were open), or only the glasses (the
|
||||
* phone hides its copy of the text but keeps the IME typing into it).
|
||||
*/
|
||||
export type KeyboardInputVisibility = "both" | "phone" | "glasses";
|
||||
|
||||
/** Sent messages kept for the phone's history button. */
|
||||
const MAX_HISTORY = 20;
|
||||
|
||||
/**
|
||||
* The phone side's handle on an open keyboard-input dialog: the phone types
|
||||
* into it and picks where the text goes. The layer itself implements this;
|
||||
@@ -25,6 +35,10 @@ export type KeyboardInputSession = {
|
||||
send(): void;
|
||||
sendTo(targetId: string): void;
|
||||
discard(): void;
|
||||
readonly visibility: KeyboardInputVisibility;
|
||||
setVisibility(visibility: KeyboardInputVisibility): void;
|
||||
/** Messages sent from keyboard dialogs since the app started, newest first. */
|
||||
readonly history: ReadonlyArray<string>;
|
||||
};
|
||||
|
||||
export type KeyboardInputLayerOptions = {
|
||||
@@ -33,6 +47,16 @@ export type KeyboardInputLayerOptions = {
|
||||
onClosed: () => void;
|
||||
/** Pop this layer off the shell stack. */
|
||||
dismiss: () => void;
|
||||
/**
|
||||
* Put the layer back on the shell stack, or take it off without ending the
|
||||
* session (phone-only visibility; onRemoved is ignored while hiding).
|
||||
*/
|
||||
setShownOnGlasses: (shown: boolean) => void;
|
||||
/** Starting visibility; the shell pushes the layer only if it isn't "phone". */
|
||||
visibility: KeyboardInputVisibility;
|
||||
onVisibilityChanged: (visibility: KeyboardInputVisibility) => void;
|
||||
/** Shared, newest-first list this layer adds its sent message to. */
|
||||
history: string[];
|
||||
/** Ordered send destinations shown as the first menu rows. */
|
||||
sendTargets: VoiceSendTarget[];
|
||||
/** Which send target is highlighted by default (entry-point dependent). */
|
||||
@@ -52,10 +76,16 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
|
||||
private text = "";
|
||||
private readonly menu: Menu<KeyboardMenuRow>;
|
||||
private closed = false;
|
||||
private currentVisibility: KeyboardInputVisibility;
|
||||
// Set while the shell takes the layer off the stack for phone-only typing.
|
||||
private hiding = false;
|
||||
|
||||
private readonly actions: LayerActions;
|
||||
private readonly onClosed: () => void;
|
||||
private readonly dismiss: () => void;
|
||||
private readonly setShownOnGlasses: (shown: boolean) => void;
|
||||
private readonly onVisibilityChanged: (visibility: KeyboardInputVisibility) => void;
|
||||
private readonly sentHistory: string[];
|
||||
private readonly sendTargets: VoiceSendTarget[];
|
||||
private readonly defaultTargetIndex: number;
|
||||
|
||||
@@ -63,6 +93,10 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
|
||||
this.actions = options.actions;
|
||||
this.onClosed = options.onClosed;
|
||||
this.dismiss = options.dismiss;
|
||||
this.setShownOnGlasses = options.setShownOnGlasses;
|
||||
this.currentVisibility = options.visibility;
|
||||
this.onVisibilityChanged = options.onVisibilityChanged;
|
||||
this.sentHistory = options.history;
|
||||
this.sendTargets = options.sendTargets;
|
||||
const defaultIndex = options.defaultTargetIndex ?? 0;
|
||||
this.defaultTargetIndex = Math.min(Math.max(0, defaultIndex), Math.max(0, this.sendTargets.length - 1));
|
||||
@@ -73,6 +107,33 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
|
||||
return this.sendTargets.map((target) => ({ id: target.id, label: target.label }));
|
||||
}
|
||||
|
||||
get visibility(): KeyboardInputVisibility {
|
||||
return this.currentVisibility;
|
||||
}
|
||||
|
||||
get history(): ReadonlyArray<string> {
|
||||
return this.sentHistory;
|
||||
}
|
||||
|
||||
/** Whether the dialog is on the glasses (the shell stack) rather than phone-only. */
|
||||
get shownOnGlasses(): boolean {
|
||||
return this.currentVisibility !== "phone";
|
||||
}
|
||||
|
||||
setVisibility(visibility: KeyboardInputVisibility): void {
|
||||
if (this.closed || visibility === this.currentVisibility) return;
|
||||
const wasShown = this.shownOnGlasses;
|
||||
this.currentVisibility = visibility;
|
||||
this.onVisibilityChanged(visibility);
|
||||
if (this.shownOnGlasses === wasShown) return;
|
||||
this.hiding = !this.shownOnGlasses;
|
||||
try {
|
||||
this.setShownOnGlasses(this.shownOnGlasses);
|
||||
} finally {
|
||||
this.hiding = false;
|
||||
}
|
||||
}
|
||||
|
||||
setText(text: string): void {
|
||||
if (this.closed || this.text === text) return;
|
||||
this.text = text;
|
||||
@@ -90,7 +151,23 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
|
||||
}
|
||||
|
||||
discard(): void {
|
||||
if (!this.closed) this.dismiss();
|
||||
this.close();
|
||||
}
|
||||
|
||||
private close(): void {
|
||||
if (this.closed) return;
|
||||
// Phone-only, there is no stack entry to pop; end the session directly.
|
||||
if (this.shownOnGlasses) {
|
||||
this.dismiss();
|
||||
} else {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
|
||||
private finish(): void {
|
||||
if (this.closed) return;
|
||||
this.closed = true;
|
||||
this.onClosed();
|
||||
}
|
||||
|
||||
private sendToTarget(target: VoiceSendTarget): void {
|
||||
@@ -99,7 +176,11 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
|
||||
// An empty message has nothing to deliver; the dialog stays up for the
|
||||
// phone to keep typing (the glasses row is drawn dim for the same reason).
|
||||
if (!text) return;
|
||||
this.dismiss();
|
||||
const previous = this.sentHistory.indexOf(text);
|
||||
if (previous >= 0) this.sentHistory.splice(previous, 1);
|
||||
this.sentHistory.unshift(text);
|
||||
this.sentHistory.length = Math.min(this.sentHistory.length, MAX_HISTORY);
|
||||
this.close();
|
||||
target.onSend(text);
|
||||
}
|
||||
|
||||
@@ -140,12 +221,12 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
|
||||
if (row.target) {
|
||||
this.sendToTarget(row.target);
|
||||
} else {
|
||||
this.dismiss();
|
||||
this.close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
case "double-click":
|
||||
this.dismiss();
|
||||
this.close();
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
@@ -153,7 +234,8 @@ export class KeyboardInputLayer implements Layer, KeyboardInputSession {
|
||||
}
|
||||
|
||||
onRemoved(): void {
|
||||
this.closed = true;
|
||||
this.onClosed();
|
||||
// Taken off the glasses for phone-only typing: the session carries on.
|
||||
if (this.hiding) return;
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
+37
-7
@@ -20,7 +20,7 @@ import {
|
||||
import { Layer, LayerActions, LayerContext, LayerStack, noopLayerActions } from "../layers";
|
||||
import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem } from "../menu";
|
||||
import { VoiceInputLayer, type VoiceSendTarget } from "./voice-input";
|
||||
import { KeyboardInputLayer, type KeyboardInputSession } from "./keyboard-input";
|
||||
import { KeyboardInputLayer, type KeyboardInputSession, type KeyboardInputVisibility } from "./keyboard-input";
|
||||
import { voiceActivity } from "./voice-activity";
|
||||
import { AssistantLayer } from "./assistant";
|
||||
import { AssistantSession, type AssistantBackendConfig } from "../../assistant/session";
|
||||
@@ -310,6 +310,9 @@ const noopActions: LayerActions = noopLayerActions;
|
||||
*/
|
||||
const LONG_PRESS_ESCAPE_MENU_MS = 4000;
|
||||
|
||||
/** Settings-store key for the keyboard dialog's last-chosen KeyboardInputVisibility. */
|
||||
const KEYBOARD_INPUT_VISIBILITY_KEY = "keyboardInput.visibility";
|
||||
|
||||
/** Shell-surface overlay menu (the system menu); closing it returns focus to the sidebar. */
|
||||
class ShellOverlayMenuLayer extends MenuLayer {
|
||||
/**
|
||||
@@ -455,6 +458,8 @@ class Shell {
|
||||
private readonly trayIcons = new Map<string, { icon: GrayImage; widget?: TrayWidget }>();
|
||||
private activeVoiceLayer: VoiceInputLayer | null = null;
|
||||
private activeKeyboardLayer: KeyboardInputLayer | null = null;
|
||||
// Messages sent from keyboard dialogs, newest first; in memory only.
|
||||
private readonly keyboardInputHistory: string[] = [];
|
||||
// App-posted notifications that are open or queued, by key.
|
||||
private readonly appNotifications = new Map<string, AppNotification>();
|
||||
private readonly notificationModals = new NotificationModalQueue<NotificationPopup>({
|
||||
@@ -1194,7 +1199,7 @@ class Shell {
|
||||
const foreground = this.foregroundWindow()?.windowId ?? "none";
|
||||
if (!this.screenOn) return `fg=${foreground} target=screen-off`;
|
||||
if (this.activeVoiceLayer) return `fg=${foreground} target=voice`;
|
||||
if (this.activeKeyboardLayer) return `fg=${foreground} target=keyboard`;
|
||||
if (this.activeKeyboardLayer?.shownOnGlasses) return `fg=${foreground} target=keyboard`;
|
||||
if (!this.stack.isAtBase()) return `fg=${foreground} target=shell-overlay`;
|
||||
return `fg=${foreground} target=${this.focus}`;
|
||||
}
|
||||
@@ -1583,12 +1588,16 @@ class Shell {
|
||||
* continues that conversation; otherwise it goes to the usual destinations
|
||||
* with Send to Assistant highlighted. Returns the session the phone types
|
||||
* into (the already-open one if there is one), or null while a voice
|
||||
* dialog is up.
|
||||
* dialog is up. The phone can keep the dialog off the glasses (see
|
||||
* KeyboardInputVisibility); that choice persists across dialogs.
|
||||
*/
|
||||
startKeyboardInput(): KeyboardInputSession | null {
|
||||
if (this.activeKeyboardLayer) return this.activeKeyboardLayer;
|
||||
if (this.activeVoiceLayer || this.foregroundWindow()?.isVoiceCapturing?.()) return null;
|
||||
if (!this.screenOn) this.wake("sidebar");
|
||||
const storedVisibility = getStringSetting(KEYBOARD_INPUT_VISIBILITY_KEY, "both");
|
||||
const visibility: KeyboardInputVisibility =
|
||||
storedVisibility === "phone" || storedVisibility === "glasses" ? storedVisibility : "both";
|
||||
if (visibility !== "phone" && !this.screenOn) this.wake("sidebar");
|
||||
const assistantLayer = this.assistantLayer;
|
||||
const assistantSession = this.assistantSession;
|
||||
let targets: VoiceSendTarget[];
|
||||
@@ -1598,7 +1607,15 @@ class Shell {
|
||||
{
|
||||
id: "assistant",
|
||||
label: "Send",
|
||||
onSend: (text) => this.runAssistantTurn(assistantSession, assistantLayer, text),
|
||||
// Phone-only, the overlay can close while the dialog is open; the
|
||||
// text then starts a fresh overlay on the same conversation.
|
||||
onSend: (text) => {
|
||||
if (this.assistantLayer === assistantLayer) {
|
||||
this.runAssistantTurn(assistantSession, assistantLayer, text);
|
||||
} else {
|
||||
this.sendToAssistant(text);
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
} else {
|
||||
@@ -1616,16 +1633,29 @@ class Shell {
|
||||
}
|
||||
},
|
||||
dismiss: () => {
|
||||
this.stack.popIfTop((top) => top === layer);
|
||||
// Wherever it sits: a menu opened over the dialog stays open.
|
||||
this.stack.remove(layer);
|
||||
// A send or discard from the phone side arrives outside the input
|
||||
// path, so nothing else asks for the repaint.
|
||||
this.config.requestShellRender();
|
||||
},
|
||||
setShownOnGlasses: (shown) => {
|
||||
if (shown) {
|
||||
if (!this.screenOn) this.wake("sidebar");
|
||||
this.stack.push(layer);
|
||||
} else {
|
||||
this.stack.remove(layer);
|
||||
}
|
||||
this.config.requestShellRender();
|
||||
},
|
||||
visibility,
|
||||
onVisibilityChanged: (value) => setStringSetting(KEYBOARD_INPUT_VISIBILITY_KEY, value),
|
||||
history: this.keyboardInputHistory,
|
||||
sendTargets: targets,
|
||||
defaultTargetIndex: defaultIndex,
|
||||
});
|
||||
this.activeKeyboardLayer = layer;
|
||||
this.stack.push(layer);
|
||||
if (layer.shownOnGlasses) this.stack.push(layer);
|
||||
this.config.onKeyboardInputChanged?.(layer);
|
||||
this.config.requestShellRender();
|
||||
return layer;
|
||||
|
||||
Reference in new issue
Block a user