mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
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
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- History icon for the keyboard-input panel's recent-inputs button.
|
||||
Material Design "history" glyph (Apache 2.0); base fill is overridden by
|
||||
tint-color in app.css. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF333333"
|
||||
android:pathData="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Glasses half of the keyboard-input panel's visibility button (dimmed
|
||||
while the dialog is hidden on the glasses): two lens frames, bridge and
|
||||
temple stubs. Base fill is overridden by tint-color in app.css. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF333333"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M4.5 8h3a3 3 0 0 1 3 3v1.5a3 3 0 0 1-3 3h-3a3 3 0 0 1-3-3v-1.5a3 3 0 0 1 3-3zM4.75 9.75h2.5a1.5 1.5 0 0 1 1.5 1.5v1a1.5 1.5 0 0 1-1.5 1.5h-2.5a1.5 1.5 0 0 1-1.5-1.5v-1a1.5 1.5 0 0 1 1.5-1.5zM16.5 8h3a3 3 0 0 1 3 3v1.5a3 3 0 0 1-3 3h-3a3 3 0 0 1-3-3v-1.5a3 3 0 0 1 3-3zM16.75 9.75h2.5a1.5 1.5 0 0 1 1.5 1.5v1a1.5 1.5 0 0 1-1.5 1.5h-2.5a1.5 1.5 0 0 1-1.5-1.5v-1a1.5 1.5 0 0 1 1.5-1.5z" />
|
||||
<path
|
||||
android:fillColor="#FF333333"
|
||||
android:pathData="M10 10.25Q12 8.25 14 10.25V12Q12 10 10 12zM0 8h3v1.75H0zM21 8h3v1.75h-3z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Phone half of the keyboard-input panel's visibility button (dimmed while
|
||||
the dialog is hidden on the phone). Material Design "smartphone" glyph
|
||||
(Apache 2.0); base fill is overridden by tint-color in app.css. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF333333"
|
||||
android:pathData="M17 1.01L7 1c-1.1 0-2 .9-2 2v18c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V3c0-1.1-.9-1.99-2-1.99zM17 19H7V5h10v14z" />
|
||||
</vector>
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"images": [
|
||||
{
|
||||
"idiom": "universal",
|
||||
"filename": "ic_input_history@3x.png",
|
||||
"scale": "3x"
|
||||
}
|
||||
],
|
||||
"info": {
|
||||
"author": "xcode",
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"images": [
|
||||
{
|
||||
"idiom": "universal",
|
||||
"filename": "ic_show_glasses@3x.png",
|
||||
"scale": "3x"
|
||||
}
|
||||
],
|
||||
"info": {
|
||||
"author": "xcode",
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"images": [
|
||||
{
|
||||
"idiom": "universal",
|
||||
"filename": "ic_show_phone@3x.png",
|
||||
"scale": "3x"
|
||||
}
|
||||
],
|
||||
"info": {
|
||||
"author": "xcode",
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 715 B |
@@ -18,6 +18,7 @@
|
||||
* Fix a bug on iOS that would cause corrupted installs of EvenHub apps
|
||||
* EvenHub apps can use the glasses microphone on iOS (such as Chess's voice moves, which said "Mic unavailable")
|
||||
* EvenHub apps on iOS should now be able to use the mic
|
||||
* Fix a bug that caused fade-in on wake to be shown at the wrong depth on iOS
|
||||
|
||||
## 0.8.4 - 2026-10-17
|
||||
|
||||
|
||||
+54
@@ -154,6 +154,60 @@ Button.-primary {
|
||||
color: #222222;
|
||||
}
|
||||
|
||||
/* Keyboard-input panel: tighter than the setting editor, with the text
|
||||
* box's edges in line with the title and the one-strip buttons (the theme's
|
||||
* 16dp TextView side margins doubled the inset). */
|
||||
.system-name-modal.keyboard-input-panel {
|
||||
margin: 8;
|
||||
padding: 8 16 12 16;
|
||||
}
|
||||
|
||||
.keyboard-input-panel TextView {
|
||||
margin: 4 0 0 0;
|
||||
padding: 6;
|
||||
}
|
||||
|
||||
/* Glasses-only: the field stays focused for the IME but is an invisible
|
||||
* sliver; the hint line takes its place. */
|
||||
.keyboard-input-panel TextView.keyboard-input-field-hidden {
|
||||
opacity: 0;
|
||||
height: 1;
|
||||
min-height: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.system-name-modal Label.keyboard-input-hidden-hint,
|
||||
.ns-dark .system-name-modal Label.keyboard-input-hidden-hint {
|
||||
color: #666666;
|
||||
padding: 8 0;
|
||||
}
|
||||
|
||||
.keyboard-input-buttons {
|
||||
margin-top: 8;
|
||||
}
|
||||
|
||||
.keyboard-input-panel Button,
|
||||
.keyboard-input-panel Button.-primary {
|
||||
margin: 0;
|
||||
font-size: 16;
|
||||
}
|
||||
|
||||
.keyboard-input-panel Button.keyboard-input-gap {
|
||||
margin-left: 8;
|
||||
}
|
||||
|
||||
/* Flat icon buttons in the panel's title row (the modal stays light in dark
|
||||
* mode, so one tint). */
|
||||
.panel-icon-button {
|
||||
padding: 6 8;
|
||||
}
|
||||
|
||||
.panel-icon {
|
||||
height: 20;
|
||||
tint-color: #333333;
|
||||
}
|
||||
|
||||
/* Modal behind the action bar's warning triangle: the problem-status warnings
|
||||
* that used to sit inline on the main page, each with its fix-it button.
|
||||
* The width is set from the view model (near-full-width on phones, capped on
|
||||
|
||||
@@ -67,3 +67,15 @@ Page.main-page {
|
||||
.main-landscape .system-name-modal { padding: 6 12; }
|
||||
.main-landscape .system-name-modal .h2 { visibility: collapse; }
|
||||
.main-landscape .system-name-modal Button { padding: 6 8; margin-top: 0; margin-bottom: 0; }
|
||||
|
||||
/* Keyboard-input panel: the one-strip buttons and title-row icons (see app.css). */
|
||||
.main-page .system-name-modal.keyboard-input-panel { padding: 8 16 12 16; }
|
||||
.main-landscape .system-name-modal.keyboard-input-panel { padding: 6 12; }
|
||||
.main-page .keyboard-input-panel TextView { margin: 4 0 0 0; padding: 6; }
|
||||
.main-page .keyboard-input-panel TextView.keyboard-input-field-hidden { opacity: 0; height: 1; min-height: 0; margin: 0; padding: 0; }
|
||||
.main-page .keyboard-input-hidden-hint { color: #666666; padding: 8 0; }
|
||||
.main-page .keyboard-input-buttons { margin-top: 8; }
|
||||
.main-page .keyboard-input-panel Button { margin: 0; }
|
||||
.main-page .keyboard-input-panel Button.keyboard-input-gap { margin-left: 8; }
|
||||
.main-page .panel-icon-button { padding: 6 8; }
|
||||
.main-page .panel-icon { height: 20; tint-color: #333333; }
|
||||
@@ -124,12 +124,10 @@ export type DashboardSnapshot = {
|
||||
activeTextEditorToggleValue: boolean;
|
||||
activeTextEditorToggleVisible: boolean;
|
||||
/**
|
||||
* The keyboard dialog is up on the glasses (opened by the phone's keyboard
|
||||
* button): the phone shows its typing panel, with a send button per
|
||||
* destination in the glasses menu's row order.
|
||||
* The keyboard dialog is open (opened by the phone's keyboard button): the
|
||||
* phone shows its typing panel, driven by keyboardInputSession.
|
||||
*/
|
||||
keyboardInputActive: boolean;
|
||||
keyboardInputTargets: ReadonlyArray<{ id: string; label: string }>;
|
||||
evenAppConflictMessage: string;
|
||||
evenAppConflictWarningVisible: boolean;
|
||||
firmwareWarningMessage: string;
|
||||
@@ -1122,7 +1120,6 @@ class DashboardController {
|
||||
activeTextEditorToggleValue: this.activeTextEditorToggle?.setting.get() ?? false,
|
||||
activeTextEditorToggleVisible: this.activeTextEditorToggle !== null,
|
||||
keyboardInputActive: this.keyboardInput !== null,
|
||||
keyboardInputTargets: this.keyboardInput?.targets ?? [],
|
||||
evenAppConflictMessage: this.evenAppConflictMessage,
|
||||
evenAppConflictWarningVisible: this.evenAppConflictMessage.length > 0,
|
||||
firmwareWarningMessage: this.firmwareWarningMessage,
|
||||
@@ -1321,23 +1318,9 @@ class DashboardController {
|
||||
shell.startKeyboardInput();
|
||||
}
|
||||
|
||||
/** The phone's typing panel changed: mirror the text on the glasses. */
|
||||
setKeyboardInputText(text: string): void {
|
||||
shell.noteUserActivity();
|
||||
this.keyboardInput?.setText(text);
|
||||
}
|
||||
|
||||
/** Send to one destination, or (no id: the IME's send key) the one highlighted on the glasses. */
|
||||
sendKeyboardInput(targetId?: string): void {
|
||||
if (targetId) {
|
||||
this.keyboardInput?.sendTo(targetId);
|
||||
} else {
|
||||
this.keyboardInput?.send();
|
||||
}
|
||||
}
|
||||
|
||||
discardKeyboardInput(): void {
|
||||
this.keyboardInput?.discard();
|
||||
/** The open keyboard dialog, for the phone's typing panel (KeyboardInputViewModel). */
|
||||
get keyboardInputSession(): KeyboardInputSession | null {
|
||||
return this.keyboardInput;
|
||||
}
|
||||
|
||||
setActiveTextEditorToggleValue(value: boolean): void {
|
||||
|
||||
@@ -131,6 +131,8 @@ export class IosPreviewController {
|
||||
private clockMinute = -1
|
||||
private shellRenderInProgress = false
|
||||
private shellRenderQueued = false
|
||||
/** The shell woke; the next shell render unblanks the compositor after submitting. */
|
||||
private unblankAfterShellRender = false
|
||||
private nextFrameId = 1
|
||||
private nextWorkerFrame = 0
|
||||
private inputQueue: Promise<void> = Promise.resolve()
|
||||
@@ -199,6 +201,9 @@ export class IosPreviewController {
|
||||
send: () => { if (this.active && !this.glassesLocked) session.send() },
|
||||
sendTo: id => { if (this.active && !this.glassesLocked) session.sendTo(id) },
|
||||
discard: () => session.discard(),
|
||||
get visibility() { return session.visibility },
|
||||
setVisibility: visibility => { if (this.active && !this.glassesLocked) session.setVisibility(visibility) },
|
||||
get history() { return session.history },
|
||||
} : null),
|
||||
prepareVoiceCapture: () => this.prepareVoiceCapture(),
|
||||
getScreenTimeoutMs: () => null,
|
||||
@@ -211,7 +216,12 @@ export class IosPreviewController {
|
||||
},
|
||||
onScreenStateChanged: on => {
|
||||
if (on) this.glance.dismiss()
|
||||
void this.display?.setScreenBlanked(!on).catch(error => this.fail(error))
|
||||
// A wake unblanks only once the next shell render has staged an awake
|
||||
// scene: unblanking composites the retained one, painted while asleep
|
||||
// with no chrome and depth 0, and that first frame is the one the
|
||||
// brightness fade-in starts on.
|
||||
this.unblankAfterShellRender = on
|
||||
if (!on) void this.display?.setScreenBlanked(true).catch(error => this.fail(error))
|
||||
this.requestShellRender()
|
||||
},
|
||||
})
|
||||
@@ -521,10 +531,19 @@ export class IosPreviewController {
|
||||
await this.displayReady
|
||||
const display = this.display
|
||||
if (!display) return
|
||||
const startedAt = Date.now()
|
||||
const bytes = shell.paintScene()
|
||||
// Taken with the paint, so a render that painted before the wake can't unblank.
|
||||
const unblank = this.unblankAfterShellRender
|
||||
this.unblankAfterShellRender = false
|
||||
const frameId = this.allocateFrameId()
|
||||
await display.submitShellScene(bytes, Date.now() - startedAt, frameId)
|
||||
try {
|
||||
const startedAt = Date.now()
|
||||
const bytes = shell.paintScene()
|
||||
await display.submitShellScene(bytes, Date.now() - startedAt, frameId)
|
||||
} finally {
|
||||
// Even if the render failed, so the screen doesn't stay dark; not if it
|
||||
// went back to sleep meanwhile (that sleep re-blanked).
|
||||
if (unblank && shell.isScreenOn()) await display.setScreenBlanked(false)
|
||||
}
|
||||
// Backpressure: the next shell render waits for this one to reach the
|
||||
// glasses (the preview target resolves immediately; nothing transmits).
|
||||
await display.waitForFrameFinished(frameId, FRAME_TRANSMIT_BACKPRESSURE_TIMEOUT_MS)
|
||||
|
||||
@@ -1,18 +1,40 @@
|
||||
<GridLayout rows="auto,*,auto" maxHeight="280" xmlns="http://schemas.nativescript.org/tns.xsd"
|
||||
class="system-name-modal"
|
||||
class="system-name-modal keyboard-input-panel"
|
||||
visibility="{{ keyboardInputVisibility }}"
|
||||
horizontalAlignment="stretch"
|
||||
verticalAlignment="bottom">
|
||||
<Label row="0" text="Keyboard input" class="h2" />
|
||||
<!-- Title, then the history button (recent sent messages) and the
|
||||
visibility button, which cycles both / phone only / glasses only and
|
||||
dims the half of its phone+glasses pair where the dialog is hidden.
|
||||
rows="auto" on the grids: an implicit star row balloons in here. -->
|
||||
<GridLayout row="0" rows="auto" columns="*,auto,auto">
|
||||
<Label col="0" text="Keyboard input" class="h2" verticalAlignment="center" />
|
||||
<GridLayout col="1" rows="auto" class="panel-icon-button" opacity="{{ keyboardInputHistoryOpacity }}"
|
||||
accessible="true" accessibilityRole="button" accessibilityLabel="Recent inputs"
|
||||
tap="{{ onKeyboardInputHistoryTap }}">
|
||||
<Image src="res://ic_input_history" class="panel-icon" />
|
||||
</GridLayout>
|
||||
<StackLayout col="2" orientation="horizontal" class="panel-icon-button"
|
||||
accessible="true" accessibilityRole="button" accessibilityLabel="{{ keyboardInputVisibilityDescription }}"
|
||||
tap="{{ onKeyboardInputVisibilityTap }}">
|
||||
<Image src="res://ic_show_phone" class="panel-icon" opacity="{{ keyboardInputPhoneIconOpacity }}" />
|
||||
<Image src="res://ic_show_glasses" class="panel-icon" opacity="{{ keyboardInputGlassesIconOpacity }}" />
|
||||
</StackLayout>
|
||||
</GridLayout>
|
||||
<TextView row="1"
|
||||
id="keyboardInputField"
|
||||
class="{{ keyboardInputFieldClass }}"
|
||||
text="{{ keyboardInputText }}"
|
||||
hint="Type a message"
|
||||
textChange="{{ onKeyboardInputTextChange }}" />
|
||||
<!-- Wraps onto a second line when the labels don't fit side by side. -->
|
||||
<FlexboxLayout row="2" flexWrap="wrap" class="m-t-8">
|
||||
<Label row="1" text="Shown on the glasses only. Tap to type." textWrap="true"
|
||||
class="keyboard-input-hidden-hint"
|
||||
visibility="{{ keyboardInputGlassesOnlyVisibility }}"
|
||||
tap="{{ onKeyboardInputGlassesOnlyHintTap }}" />
|
||||
<!-- One strip: at most two destinations (assistant, app) plus Discard. -->
|
||||
<FlexboxLayout row="2" flexWrap="nowrap" class="keyboard-input-buttons">
|
||||
<Button text="{{ keyboardInputPrimaryTargetLabel }}" tap="{{ onKeyboardInputPrimarySendTap }}" visibility="{{ keyboardInputPrimaryTargetVisibility }}" flexGrow="1" class="-primary" />
|
||||
<Button text="{{ keyboardInputSecondaryTargetLabel }}" tap="{{ onKeyboardInputSecondarySendTap }}" visibility="{{ keyboardInputSecondaryTargetVisibility }}" flexGrow="1" />
|
||||
<Button text="Discard" tap="{{ onKeyboardInputDiscardTap }}" flexGrow="1" />
|
||||
<Button text="{{ keyboardInputSecondaryTargetLabel }}" tap="{{ onKeyboardInputSecondarySendTap }}" visibility="{{ keyboardInputSecondaryTargetVisibility }}" flexGrow="1" class="keyboard-input-gap" />
|
||||
<Button text="Discard" tap="{{ onKeyboardInputDiscardTap }}" flexGrow="1" class="keyboard-input-gap" />
|
||||
</FlexboxLayout>
|
||||
</GridLayout>
|
||||
@@ -1,7 +1,32 @@
|
||||
import { Observable } from '@nativescript/core'
|
||||
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
|
||||
import { Dialogs, Observable, type EventData, type TextView, type View } from '@nativescript/core'
|
||||
import type { KeyboardInputSession, KeyboardInputVisibility } from '../ui/shell/keyboard-input'
|
||||
|
||||
/** Phone editor for the shell's keyboard session, using the shared XML panel. */
|
||||
/** The visibility button's cycle: both → phone only → glasses only → both. */
|
||||
const NEXT_VISIBILITY: Record<KeyboardInputVisibility, KeyboardInputVisibility> = { both: 'phone', phone: 'glasses', glasses: 'both' }
|
||||
const VISIBILITY_DESCRIPTIONS: Record<KeyboardInputVisibility, string> = {
|
||||
both: 'Shown on phone and glasses', phone: 'Shown on phone only', glasses: 'Shown on glasses only',
|
||||
}
|
||||
/**
|
||||
* Phone button text for the glasses' send-target labels, short enough for
|
||||
* every button to share one strip. Unlisted labels (the assistant overlay's
|
||||
* "Send") are already short.
|
||||
*/
|
||||
const SHORT_TARGET_LABELS: Record<string, string> = { 'Send to Assistant': 'To Assistant', 'Type Into App': 'To App' }
|
||||
const HISTORY_LABEL_LENGTH = 80
|
||||
const DIMMED_ICON_OPACITY = 0.3
|
||||
|
||||
/** One history entry as a single line, truncated for the picker. */
|
||||
function historyLabel(text: string): string {
|
||||
const line = text.replace(/\s+/g, ' ').trim()
|
||||
return line.length > HISTORY_LABEL_LENGTH ? `${line.slice(0, HISTORY_LABEL_LENGTH - 1)}…` : line
|
||||
}
|
||||
|
||||
/**
|
||||
* Phone editor for the shell's keyboard session: the binding context of the
|
||||
* shared keyboard-input-panel.xml on both platforms (Android's MainViewModel
|
||||
* hands it the session from the dashboard controller, iOS's main page from
|
||||
* the preview controller).
|
||||
*/
|
||||
export class KeyboardInputViewModel extends Observable {
|
||||
private session: KeyboardInputSession | null = null
|
||||
private text = ''
|
||||
@@ -10,17 +35,24 @@ export class KeyboardInputViewModel extends Observable {
|
||||
if (session === this.session) return
|
||||
this.session = session
|
||||
this.text = ''
|
||||
for (const property of ['keyboardInputText', 'keyboardInputVisibility', 'keyboardInputPrimaryTargetLabel',
|
||||
'keyboardInputPrimaryTargetVisibility', 'keyboardInputSecondaryTargetLabel', 'keyboardInputSecondaryTargetVisibility']) {
|
||||
this.notifyPropertyChange(property, this.get(property))
|
||||
}
|
||||
this.notifyPanel(['keyboardInputText', 'keyboardInputVisibility', 'keyboardInputPrimaryTargetLabel',
|
||||
'keyboardInputPrimaryTargetVisibility', 'keyboardInputSecondaryTargetLabel', 'keyboardInputSecondaryTargetVisibility',
|
||||
'keyboardInputHistoryOpacity'])
|
||||
this.notifyVisibilityMode()
|
||||
}
|
||||
private notifyPanel(properties: string[]): void {
|
||||
for (const property of properties) this.notifyPropertyChange(property, this.get(property))
|
||||
}
|
||||
private notifyVisibilityMode(): void {
|
||||
this.notifyPanel(['keyboardInputPhoneIconOpacity', 'keyboardInputGlassesIconOpacity', 'keyboardInputVisibilityDescription',
|
||||
'keyboardInputFieldClass', 'keyboardInputGlassesOnlyVisibility'])
|
||||
}
|
||||
get keyboardInputVisibility(): 'visible' | 'collapse' { return this.session ? 'visible' : 'collapse' }
|
||||
get keyboardInputText(): string { return this.text }
|
||||
set keyboardInputText(text: string) { this.text = text; this.session?.setText(text) }
|
||||
private targetLabel(index: number): string {
|
||||
const target = this.session?.targets[index]
|
||||
return target?.id === 'assistant' ? 'Send to Agent' : target?.id === 'app' ? 'Type into App' : target?.label ?? ''
|
||||
const label = this.session?.targets[index]?.label ?? ''
|
||||
return SHORT_TARGET_LABELS[label] ?? label
|
||||
}
|
||||
get keyboardInputPrimaryTargetLabel(): string { return this.targetLabel(0) }
|
||||
get keyboardInputSecondaryTargetLabel(): string { return this.targetLabel(1) }
|
||||
@@ -38,4 +70,61 @@ export class KeyboardInputViewModel extends Observable {
|
||||
this.session.sendTo(target.id)
|
||||
}
|
||||
onKeyboardInputDiscardTap(): void { this.session?.discard() }
|
||||
|
||||
// ---- visibility button: where the dialog shows ----
|
||||
//
|
||||
// Glasses-only keeps the text field focused (so the IME keeps typing into
|
||||
// it) but shrinks it to an invisible sliver; a hint line stands in for it
|
||||
// and refocuses it if the IME was dismissed.
|
||||
|
||||
private get visibilityMode(): KeyboardInputVisibility { return this.session?.visibility ?? 'both' }
|
||||
get keyboardInputPhoneIconOpacity(): number { return this.visibilityMode === 'glasses' ? DIMMED_ICON_OPACITY : 1 }
|
||||
get keyboardInputGlassesIconOpacity(): number { return this.visibilityMode === 'phone' ? DIMMED_ICON_OPACITY : 1 }
|
||||
get keyboardInputVisibilityDescription(): string { return VISIBILITY_DESCRIPTIONS[this.visibilityMode] }
|
||||
get keyboardInputFieldClass(): string { return this.visibilityMode === 'glasses' ? 'keyboard-input-field-hidden' : '' }
|
||||
get keyboardInputGlassesOnlyVisibility(): 'visible' | 'collapse' { return this.visibilityMode === 'glasses' ? 'visible' : 'collapse' }
|
||||
onKeyboardInputVisibilityTap(): void {
|
||||
if (!this.session) return
|
||||
this.session.setVisibility(NEXT_VISIBILITY[this.visibilityMode])
|
||||
this.notifyVisibilityMode()
|
||||
}
|
||||
onKeyboardInputGlassesOnlyHintTap(args: EventData): void {
|
||||
focusField(args.object as View)
|
||||
}
|
||||
|
||||
// ---- history button: recent sent messages (in memory, newest first) ----
|
||||
|
||||
get keyboardInputHistoryOpacity(): number { return this.session?.history.length ? 1 : DIMMED_ICON_OPACITY }
|
||||
async onKeyboardInputHistoryTap(args: EventData): Promise<void> {
|
||||
const session = this.session
|
||||
if (!session?.history.length) return
|
||||
const entries = new Map<string, string>()
|
||||
for (const entry of session.history) {
|
||||
const label = historyLabel(entry)
|
||||
if (!entries.has(label)) entries.set(label, entry)
|
||||
}
|
||||
const choice = await Dialogs.action({ title: 'Recent inputs', cancelButtonText: 'Cancel', actions: [...entries.keys()] })
|
||||
const text = entries.get(choice)
|
||||
if (text === undefined || session !== this.session) return
|
||||
const field = fieldNear(args.object as View)
|
||||
this.keyboardInputText = text
|
||||
// Through the view, not a property change: its textChange handler then
|
||||
// syncs the model and session the same way typing does.
|
||||
if (field) field.text = text
|
||||
focusField(args.object as View, text.length)
|
||||
}
|
||||
}
|
||||
|
||||
function fieldNear(view: View): TextView | undefined {
|
||||
return view.page?.getViewById<TextView>('keyboardInputField')
|
||||
}
|
||||
|
||||
/** Focus the panel's field (bringing the IME back), optionally placing the caret. */
|
||||
function focusField(view: View, caret?: number): void {
|
||||
setTimeout(() => {
|
||||
const field = fieldNear(view)
|
||||
if (!field) return
|
||||
field.focus()
|
||||
if (caret !== undefined) field.setSelection(caret)
|
||||
}, 0)
|
||||
}
|
||||
@@ -182,7 +182,8 @@
|
||||
the phone's end of the keyboard dialog on the glasses
|
||||
(ui/shell/keyboard-input.ts). Same placement and collapsing rules
|
||||
as the setting editor above. Enter inserts a newline; the send
|
||||
buttons pick a destination directly. -->
|
||||
<rc:keyboard-input-panel />
|
||||
buttons pick a destination directly. Bound to its own model
|
||||
(KeyboardInputViewModel, shared with iOS). -->
|
||||
<rc:keyboard-input-panel bindingContext="{{ keyboardInputModel }}" />
|
||||
</GridLayout>
|
||||
</Page>
|
||||
@@ -1,4 +1,5 @@
|
||||
import { RemoteControlsViewModel } from './remote-controls-view-model';
|
||||
import { KeyboardInputViewModel } from './keyboard-input-view-model';
|
||||
import { BleBandwidthMeter } from "./ble-bandwidth-meter";
|
||||
import {
|
||||
Application,
|
||||
@@ -52,8 +53,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
private _activeTextEditorToggleValue = false;
|
||||
private _activeTextEditorToggleVisible = false;
|
||||
private _keyboardInputActive = false;
|
||||
private _keyboardInputTargets: ReadonlyArray<{ id: string; label: string }> = [];
|
||||
private _keyboardInputText = "";
|
||||
private _evenAppConflictMessage = "";
|
||||
private _evenAppConflictWarningVisible = false;
|
||||
private _firmwareWarningMessage = "";
|
||||
@@ -103,8 +102,8 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.activeTextEditorToggleLabel = snapshot.activeTextEditorToggleLabel;
|
||||
this.activeTextEditorToggleValue = snapshot.activeTextEditorToggleValue;
|
||||
this.activeTextEditorToggleVisible = snapshot.activeTextEditorToggleVisible;
|
||||
// Targets before active: the panel's buttons are labelled when it appears.
|
||||
this.keyboardInputTargets = snapshot.keyboardInputTargets;
|
||||
// Session before active: the panel is filled in when it appears.
|
||||
this.keyboardInputModel.setSession(dashboardController.keyboardInputSession);
|
||||
this.keyboardInputActive = snapshot.keyboardInputActive;
|
||||
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
|
||||
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
||||
@@ -494,11 +493,13 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
|
||||
// ---- keyboard-input panel (the keyboard button beside the mic button) ----
|
||||
//
|
||||
// The dialog lives on the glasses (ui/shell/keyboard-input.ts); this panel
|
||||
// is the phone's end of it: the text field the IME types into and a send
|
||||
// button per destination. The field's text is the panel's own state, never
|
||||
// echoed back from the controller (see setActiveTextSettingValue for why);
|
||||
// it is cleared whenever a dialog opens or closes.
|
||||
// The dialog lives on the glasses (ui/shell/keyboard-input.ts); the panel
|
||||
// is the phone's end of it, bound to keyboardInputModel (shared with iOS).
|
||||
// Its text is the panel's own state, never echoed back from the controller
|
||||
// (see setActiveTextSettingValue for why); it is cleared whenever a dialog
|
||||
// opens or closes.
|
||||
|
||||
readonly keyboardInputModel = new KeyboardInputViewModel();
|
||||
|
||||
get keyboardInputActive(): boolean {
|
||||
return this._keyboardInputActive;
|
||||
@@ -507,78 +508,14 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
set keyboardInputActive(value: boolean) {
|
||||
if (this._keyboardInputActive === value) return;
|
||||
this._keyboardInputActive = value;
|
||||
this.keyboardInputText = "";
|
||||
this.notifyPropertyChange("keyboardInputActive", value);
|
||||
this.notifyPropertyChange("keyboardInputVisibility", this.keyboardInputVisibility);
|
||||
this.notifyPropertyChange("controlsVisibility", this.controlsVisibility);
|
||||
}
|
||||
|
||||
get keyboardInputVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputActive ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get keyboardInputText(): string {
|
||||
return this._keyboardInputText;
|
||||
}
|
||||
|
||||
set keyboardInputText(value: string) {
|
||||
if (this._keyboardInputText === value) return;
|
||||
this._keyboardInputText = value;
|
||||
this.notifyPropertyChange("keyboardInputText", value);
|
||||
}
|
||||
|
||||
set keyboardInputTargets(value: ReadonlyArray<{ id: string; label: string }>) {
|
||||
this._keyboardInputTargets = value;
|
||||
this.notifyPropertyChange("keyboardInputPrimaryTargetLabel", this.keyboardInputPrimaryTargetLabel);
|
||||
this.notifyPropertyChange("keyboardInputPrimaryTargetVisibility", this.keyboardInputPrimaryTargetVisibility);
|
||||
this.notifyPropertyChange("keyboardInputSecondaryTargetLabel", this.keyboardInputSecondaryTargetLabel);
|
||||
this.notifyPropertyChange("keyboardInputSecondaryTargetVisibility", this.keyboardInputSecondaryTargetVisibility);
|
||||
}
|
||||
|
||||
// The glasses menu has at most two destinations (assistant, app), so the
|
||||
// panel has a fixed pair of buttons rather than a repeater.
|
||||
get keyboardInputPrimaryTargetLabel(): string {
|
||||
return this._keyboardInputTargets[0]?.label ?? "";
|
||||
}
|
||||
|
||||
get keyboardInputPrimaryTargetVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputTargets[0] ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get keyboardInputSecondaryTargetLabel(): string {
|
||||
return this._keyboardInputTargets[1]?.label ?? "";
|
||||
}
|
||||
|
||||
get keyboardInputSecondaryTargetVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputTargets[1] ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
onKeyboardTap(): void {
|
||||
dashboardController.startKeyboardInput();
|
||||
}
|
||||
|
||||
onKeyboardInputTextChange(args: { value?: string; object?: { text?: string } }): void {
|
||||
const text = args.object?.text ?? args.value ?? "";
|
||||
// Track the draft so closing the dialog emits a clear even when the
|
||||
// binding hasn't updated the model. Avoid echoing edits into the IME.
|
||||
this._keyboardInputText = text;
|
||||
dashboardController.setKeyboardInputText(text);
|
||||
}
|
||||
|
||||
onKeyboardInputPrimarySendTap(): void {
|
||||
const target = this._keyboardInputTargets[0];
|
||||
if (target) dashboardController.sendKeyboardInput(target.id);
|
||||
}
|
||||
|
||||
onKeyboardInputSecondarySendTap(): void {
|
||||
const target = this._keyboardInputTargets[1];
|
||||
if (target) dashboardController.sendKeyboardInput(target.id);
|
||||
}
|
||||
|
||||
onKeyboardInputDiscardTap(): void {
|
||||
dashboardController.discardKeyboardInput();
|
||||
}
|
||||
|
||||
get evenAppConflictMessage(): string {
|
||||
return this._evenAppConflictMessage;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
function fixture() {
|
||||
function fixture({ choose } = {}) {
|
||||
class Observable { get(key) { return this[key]; } notifyPropertyChange() {} }
|
||||
const { KeyboardInputViewModel } = loader({}, { '@nativescript/core': { Observable } })('app/phone-ui/keyboard-input-view-model.ts');
|
||||
const model = new KeyboardInputViewModel(), sent = [], text = [];
|
||||
const dialogs = [];
|
||||
const Dialogs = { action: async options => { dialogs.push(options); return choose ? choose(options.actions) : options.cancelButtonText; } };
|
||||
const { KeyboardInputViewModel } = loader({ setTimeout: callback => callback() },
|
||||
{ '@nativescript/core': { Observable, Dialogs } })('app/phone-ui/keyboard-input-view-model.ts');
|
||||
const model = new KeyboardInputViewModel(), sent = [], text = [], visibilities = [];
|
||||
const session = { targets: [{ id: 'assistant', label: 'Send to Assistant' }, { id: 'app', label: 'Type Into App' }],
|
||||
setText: value => text.push(value), sendTo: id => sent.push(id), discard: () => model.setSession(null) };
|
||||
setText: value => text.push(value), sendTo: id => sent.push(id), discard: () => model.setSession(null),
|
||||
visibility: 'both', setVisibility(value) { visibilities.push(value); this.visibility = value; },
|
||||
history: [] };
|
||||
model.setSession(session);
|
||||
return { model, session, sent, text };
|
||||
const field = { text: '', focused: 0, selection: null, focus() { this.focused++; }, setSelection(start) { this.selection = start; } };
|
||||
const button = { page: { getViewById: id => id === 'keyboardInputField' ? field : undefined } };
|
||||
return { model, session, sent, text, visibilities, dialogs, field, button };
|
||||
}
|
||||
test('multiline keyboard editor routes Agent and App buttons to distinct shell destinations', () => {
|
||||
test('multiline keyboard editor routes Assistant and App buttons to distinct shell destinations', () => {
|
||||
const h = fixture();
|
||||
assert.equal(h.model.keyboardInputPrimaryTargetLabel, 'Send to Agent');
|
||||
assert.equal(h.model.keyboardInputSecondaryTargetLabel, 'Type into App');
|
||||
assert.equal(h.model.keyboardInputPrimaryTargetLabel, 'To Assistant');
|
||||
assert.equal(h.model.keyboardInputSecondaryTargetLabel, 'To App');
|
||||
h.model.onKeyboardInputTextChange({ object: { text: 'First line\nSecond line' } });
|
||||
h.model.onKeyboardInputPrimarySendTap();
|
||||
h.model.onKeyboardInputSecondarySendTap();
|
||||
@@ -26,7 +33,96 @@ test('discard and shell-side closure reset the editor; unsupported destinations
|
||||
assert.equal(h.model.keyboardInputText, '');
|
||||
assert.equal(h.model.keyboardInputVisibility, 'collapse');
|
||||
h.model.setSession({ ...h.session, targets: [{ id: 'assistant', label: 'Send' }] });
|
||||
assert.equal(h.model.keyboardInputPrimaryTargetLabel, 'Send to Agent');
|
||||
assert.equal(h.model.keyboardInputPrimaryTargetLabel, 'Send');
|
||||
assert.equal(h.model.keyboardInputSecondaryTargetVisibility, 'collapse');
|
||||
h.model.onKeyboardInputSecondarySendTap(); assert.deepEqual(h.sent, []);
|
||||
});
|
||||
test('visibility button cycles both, phone only, glasses only; glasses-only hides the field but keeps it', () => {
|
||||
const h = fixture();
|
||||
const state = () => [h.model.keyboardInputPhoneIconOpacity, h.model.keyboardInputGlassesIconOpacity,
|
||||
h.model.keyboardInputFieldClass, h.model.keyboardInputGlassesOnlyVisibility];
|
||||
assert.deepEqual(state(), [1, 1, '', 'collapse']);
|
||||
h.model.onKeyboardInputVisibilityTap();
|
||||
assert.deepEqual(state(), [1, 0.3, '', 'collapse']);
|
||||
h.model.onKeyboardInputVisibilityTap();
|
||||
assert.deepEqual(state(), [0.3, 1, 'keyboard-input-field-hidden', 'visible']);
|
||||
h.model.onKeyboardInputGlassesOnlyHintTap({ object: h.button });
|
||||
assert.equal(h.field.focused, 1);
|
||||
h.model.onKeyboardInputVisibilityTap();
|
||||
assert.deepEqual(h.visibilities, ['phone', 'glasses', 'both']);
|
||||
assert.equal(h.model.keyboardInputVisibilityDescription, 'Shown on phone and glasses');
|
||||
});
|
||||
test('history button lists recent inputs on one line each and puts the pick in the field', async () => {
|
||||
const long = 'x'.repeat(100);
|
||||
const h = fixture({ choose: actions => actions[1] });
|
||||
assert.equal(h.model.keyboardInputHistoryOpacity, 0.3);
|
||||
await h.model.onKeyboardInputHistoryTap({ object: h.button });
|
||||
assert.equal(h.dialogs.length, 0);
|
||||
h.session.history = ['first line\n second', long];
|
||||
h.model.setSession(null); h.model.setSession(h.session);
|
||||
assert.equal(h.model.keyboardInputHistoryOpacity, 1);
|
||||
await h.model.onKeyboardInputHistoryTap({ object: h.button });
|
||||
assert.deepEqual([...h.dialogs[0].actions], ['first line second', `${'x'.repeat(79)}…`]);
|
||||
assert.equal(h.model.keyboardInputText, long);
|
||||
assert.equal(h.text.at(-1), long);
|
||||
assert.equal(h.field.text, long);
|
||||
assert.equal(h.field.selection, 100);
|
||||
});
|
||||
|
||||
function layerFixture(visibility = 'both', history = []) {
|
||||
const menu = { items: [], setItems(items) { this.items = items; }, get selectedItem() { return this.items[0]; } };
|
||||
const { KeyboardInputLayer } = loader({}, {
|
||||
'./input-dialog': { createInputDialogMenu: () => menu, paintInputDialog() {} },
|
||||
})('app/ui/shell/keyboard-input.ts');
|
||||
const stack = new Set(), events = [];
|
||||
const layer = new KeyboardInputLayer({
|
||||
actions: { requestRender() {} },
|
||||
onClosed: () => events.push('closed'),
|
||||
dismiss: () => { if (stack.delete(layer)) layer.onRemoved(); },
|
||||
setShownOnGlasses: shown => { if (shown) stack.add(layer); else if (stack.delete(layer)) layer.onRemoved(); },
|
||||
visibility, onVisibilityChanged: value => events.push(`visibility:${value}`), history,
|
||||
sendTargets: [{ id: 'app', label: 'Type Into App', onSend: text => events.push(`sent:${text}`) }],
|
||||
});
|
||||
if (layer.shownOnGlasses) stack.add(layer);
|
||||
// The shell's sleep path: the stack is cleared and each layer told.
|
||||
const clearStack = () => { for (const removed of [...stack]) { stack.delete(removed); removed.onRemoved(); } };
|
||||
return { layer, stack, events, history, clearStack };
|
||||
}
|
||||
test('phone-only takes the dialog off the glasses without ending the session', () => {
|
||||
const f = layerFixture();
|
||||
f.layer.setVisibility('phone');
|
||||
assert.equal(f.stack.size, 0);
|
||||
assert.deepEqual(f.events, ['visibility:phone']);
|
||||
f.clearStack();
|
||||
f.layer.setText('typed while hidden'); f.layer.sendTo('app');
|
||||
assert.deepEqual(f.events, ['visibility:phone', 'closed', 'sent:typed while hidden']);
|
||||
f.layer.setVisibility('both');
|
||||
assert.equal(f.stack.size, 0);
|
||||
});
|
||||
test('shown again on the glasses, the dialog closes with the stack as before', () => {
|
||||
const f = layerFixture('phone');
|
||||
assert.equal(f.stack.size, 0);
|
||||
f.layer.setVisibility('glasses');
|
||||
assert.equal(f.stack.size, 1);
|
||||
f.layer.setVisibility('both');
|
||||
assert.deepEqual(f.events, ['visibility:glasses', 'visibility:both']);
|
||||
f.clearStack();
|
||||
assert.deepEqual(f.events.at(-1), 'closed');
|
||||
const discarded = layerFixture('phone');
|
||||
discarded.layer.discard();
|
||||
assert.deepEqual(discarded.events, ['closed']);
|
||||
});
|
||||
test('sent messages go into the shared history newest first, without duplicates or blanks', () => {
|
||||
const history = [];
|
||||
for (const text of ['one', ' ', 'two', 'one ']) {
|
||||
const f = layerFixture('both', history);
|
||||
f.layer.setText(text); f.layer.sendTo('app');
|
||||
}
|
||||
assert.deepEqual(history, ['one', 'two']);
|
||||
for (let i = 0; i < 25; i++) {
|
||||
const f = layerFixture('phone', history);
|
||||
f.layer.setText(`message ${i}`); f.layer.sendTo('app');
|
||||
}
|
||||
assert.equal(history.length, 20);
|
||||
assert.equal(history[0], 'message 24');
|
||||
});
|
||||
Reference in new issue
Block a user