mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Phone UI: Settings are a page instead of a tab, watch vs ring style input is a setting rather than a tab, EvenHub webview is a button with the main buttons rather than in the top bar
This commit is contained in:
1 parent
a02b849200
commit
cd61fefb21
35 files changed
+848
-429
No files matched your search
@@ -62,7 +62,7 @@ class PreviewBitmapUtil private constructor() {
|
||||
/**
|
||||
* A white-on-transparent bitmap of an 8bpp glasses icon (gray becomes
|
||||
* alpha; black, which the glasses show as unlit, is transparent), for
|
||||
* showing glasses artwork on the phone's dark action bar.
|
||||
* showing glasses artwork in the phone UI, which tints it to suit.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun whiteIconFromGray(gray: ByteBuffer?, width: Int, height: Int): Bitmap {
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Keyboard icon for the main page's tab-bar keyboard-dialog button (beside
|
||||
the mic button). Material Design "keyboard" glyph (Apache 2.0); base fill
|
||||
is overridden by tint-color in app.css. -->
|
||||
<!-- Keyboard icon for the main page's keyboard-dialog button (beside the mic
|
||||
button). Material Design "keyboard" glyph (Apache 2.0); base fill is
|
||||
overridden by tint-color in remote-controls.css. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Microphone icon for the main page's tab-bar wakeword button.
|
||||
<!-- Microphone icon for the main page's voice-input (wakeword) button.
|
||||
Converted from ~/Downloads/noun-microphone-1368757.svg (Noun Project
|
||||
icon #1368757); base fill is overridden by tint-color in app.css. -->
|
||||
icon #1368757); base fill is overridden by tint-color in remote-controls.css. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Gear icon for the main page's Settings button (beside the mic and keyboard
|
||||
buttons). Material Design "settings" glyph (Apache 2.0); base fill is
|
||||
overridden by tint-color in remote-controls.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="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z" />
|
||||
</vector>
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"images": [
|
||||
{
|
||||
"idiom": "universal",
|
||||
"filename": "ic_tab_keyboard@3x.png",
|
||||
"filename": "ic_control_keyboard@3x.png",
|
||||
"scale": "3x"
|
||||
}
|
||||
],
|
||||
File renamed without changes.
|
Before Width: | Height: | Size: 590 B After Width: | Height: | Size: 590 B |
+1
-1
@@ -2,7 +2,7 @@
|
||||
"images": [
|
||||
{
|
||||
"idiom": "universal",
|
||||
"filename": "ic_tab_mic@3x.png",
|
||||
"filename": "ic_control_mic@3x.png",
|
||||
"scale": "3x"
|
||||
}
|
||||
],
|
||||
File renamed without changes.
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"images": [
|
||||
{
|
||||
"idiom": "universal",
|
||||
"filename": "ic_control_settings@3x.png",
|
||||
"scale": "3x"
|
||||
}
|
||||
],
|
||||
"info": {
|
||||
"author": "xcode",
|
||||
"version": 1
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
+3
-13
@@ -1,6 +1,7 @@
|
||||
@import '@nativescript/theme/css/core.css';
|
||||
@import '@nativescript/theme/css/default.css';
|
||||
@import './phone-ui/remote-controls.css';
|
||||
@import './phone-ui/settings-page.css';
|
||||
@import './phone-ui/pairing.css';
|
||||
|
||||
Page {
|
||||
@@ -17,9 +18,8 @@ ActionItem {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
/* The main page's custom titleView: title left; the EvenHub app icon,
|
||||
* connection status and the warning triangle right-aligned beside the
|
||||
* overflow menu. */
|
||||
/* The main page's custom titleView: title left; connection status and the
|
||||
* warning triangle right-aligned beside the overflow menu. */
|
||||
.action-bar-title {
|
||||
color: #ffffff;
|
||||
font-size: 18;
|
||||
@@ -34,16 +34,6 @@ ActionItem {
|
||||
vertical-align: center;
|
||||
}
|
||||
|
||||
/* The foreground EvenHub app's icon (opens its phone UI); the padding widens
|
||||
* the tap target. */
|
||||
.action-bar-app-icon {
|
||||
width: 32;
|
||||
height: 32;
|
||||
padding: 5.5;
|
||||
margin-right: 8;
|
||||
vertical-align: center;
|
||||
}
|
||||
|
||||
/* The emoji brings its own yellow; the padding widens the tap target. */
|
||||
.action-bar-warning {
|
||||
font-size: 18;
|
||||
|
||||
+1
-5
@@ -1,5 +1,6 @@
|
||||
@import '@nativescript/theme/css/core.css';
|
||||
@import './phone-ui/remote-controls.css';
|
||||
@import './phone-ui/settings-page.css';
|
||||
@import './phone-ui/pairing.css';
|
||||
|
||||
.body-text { font-size: 18; }
|
||||
@@ -36,8 +37,6 @@ Page.main-page {
|
||||
.main-page .action-bar-title { font-size: 18; font-weight: bold; color: #ffffff; }
|
||||
.main-page .action-bar-status { font-size: 14; color: #ffffff; margin-right: 12; }
|
||||
.main-page .action-bar-warning { font-size: 18; padding: 4 6; }
|
||||
/* Matches Android's 32x32 padded icon; the Image inside is 21x21. */
|
||||
.main-page .action-bar-app-icon { width: 32; height: 32; margin-right: 8; }
|
||||
.main-page .overflow-button {
|
||||
background-color: transparent;
|
||||
color: #ffffff;
|
||||
@@ -47,9 +46,6 @@ Page.main-page {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
/* Match Android's button layout boxes, including the inset around each tile. */
|
||||
.main-page Button.tab-button { height: 48; margin-top: 6; margin-bottom: 6; }
|
||||
.main-page .mode-button { background-color: #e2e2e2; color: #333333; border-radius: 6; }
|
||||
.main-page .ble-bandwidth-indicator { color: #777777; font-size: 12; padding: 2 8; }
|
||||
|
||||
.main-page .system-name-modal {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
*
|
||||
* Glasses-first: launching does NOT take over the phone screen. The phone
|
||||
* stays on the Faceclaw dashboard; an app's phone UI is shown on demand
|
||||
* (window menu -> "Show phone UI", or the app-icon button in the phone's
|
||||
* action bar while the app is foreground on the glasses), overlaying the
|
||||
* (window menu -> "Show phone UI", or the app-icon button in the bar under the
|
||||
* phone's mirror while the app is foreground on the glasses), overlaying the
|
||||
* dashboard, and the Back button or the overlay's close button returns to it.
|
||||
* Apps are kept alive until explicitly closed (no memory eviction yet).
|
||||
*/
|
||||
@@ -40,14 +40,14 @@ type RunningApp = {
|
||||
packageId: string;
|
||||
session: EvenHubSession;
|
||||
webView: EvenHubWebView;
|
||||
/** The app's icon for the phone action bar, rendered on first use. */
|
||||
/** The app's icon for the phone's button bar, rendered on first use. */
|
||||
phoneIcon?: ImageSource | null;
|
||||
};
|
||||
|
||||
/** The phone action bar's button for opening the foreground app's phone UI. */
|
||||
/** The button under the phone's mirror that opens the foreground app's phone UI. */
|
||||
export type PhoneUiButton = { windowId: string; title: string; icon: ImageSource | null };
|
||||
|
||||
/** Pixel size the action-bar icon is rendered at (~21dp at xxhdpi). */
|
||||
/** Pixel size the button's icon is rendered at (~21dp at xxhdpi; shown at 20dp). */
|
||||
const PHONE_ICON_SIZE = 63;
|
||||
|
||||
const running = new Map<string, RunningApp>();
|
||||
@@ -244,7 +244,7 @@ export function hidePhone(): void {
|
||||
|
||||
/**
|
||||
* The foreground glasses window, when it is an EvenHub app whose phone UI
|
||||
* isn't showing: the phone action bar then offers a button to show it.
|
||||
* isn't showing: the bar under the phone's mirror then offers a button to show it.
|
||||
*/
|
||||
export function phoneUiButton(): PhoneUiButton | null {
|
||||
const window = shell.foregroundWindow();
|
||||
@@ -252,7 +252,7 @@ export function phoneUiButton(): PhoneUiButton | null {
|
||||
if (!window || !app || phoneShownWindowId === app.windowId) return null;
|
||||
if (app.phoneIcon === undefined) {
|
||||
// The same artwork as the glasses sidebar (installed icon, else the
|
||||
// generic package icon), drawn white.
|
||||
// generic package icon), drawn white; the button's stylesheet tints it.
|
||||
const image = new GrayImage(PHONE_ICON_SIZE, PHONE_ICON_SIZE, 0);
|
||||
window.drawIcon(image, 0, 0, PHONE_ICON_SIZE);
|
||||
app.phoneIcon = grayImageToWhiteIconSource(image);
|
||||
|
||||
@@ -111,8 +111,6 @@ type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging"
|
||||
|
||||
export type DashboardSnapshot = {
|
||||
phase: ConnectionPhase;
|
||||
/** Last-known battery levels: the glasses, their charging case, the R1 ring and a Wear OS watch. */
|
||||
batteries: ReturnType<typeof shell.getBatteryLevels>;
|
||||
status: string;
|
||||
displayPreview: ImageSource | null;
|
||||
/**
|
||||
@@ -155,7 +153,7 @@ export type DashboardSnapshot = {
|
||||
previewMode: boolean;
|
||||
/**
|
||||
* The foreground glasses window's EvenHub phone UI, when it can be opened
|
||||
* (the action bar's app-icon button); null otherwise.
|
||||
* (the app-icon button under the mirror); null otherwise.
|
||||
*/
|
||||
evenHubPhoneUi: PhoneUiButton | null;
|
||||
};
|
||||
@@ -428,7 +426,7 @@ class DashboardController {
|
||||
launchApp: (appId) => this.launchApp(appId),
|
||||
requestShellRender: () => this.requestShellRender(),
|
||||
});
|
||||
// The action bar's EvenHub phone-UI button hides while that UI is showing.
|
||||
// The main page's EvenHub phone-UI button hides while that UI is showing.
|
||||
onPhoneShownChanged(() => this.emit());
|
||||
shell.configure({
|
||||
actions: {
|
||||
@@ -1222,11 +1220,10 @@ class DashboardController {
|
||||
alarmReliabilityMessage: this.alarmReliabilityMessage,
|
||||
previewMode: this.isPreviewDisplayActive(),
|
||||
evenHubPhoneUi: phoneUiButton(),
|
||||
batteries: shell.getBatteryLevels(),
|
||||
};
|
||||
}
|
||||
|
||||
/** Overlay an EvenHub app's phone UI (the action bar's app-icon button). */
|
||||
/** Overlay an EvenHub app's phone UI (the app-icon button under the mirror). */
|
||||
showEvenHubPhoneUi(windowId: string): void {
|
||||
showEvenHubPhoneUi(windowId);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export type BatteryLevels = {
|
||||
};
|
||||
|
||||
/**
|
||||
* The phone Settings tab's battery row: each device whose level is known,
|
||||
* The phone settings page's battery row: each device whose level is known,
|
||||
* e.g. "G2 100% · Case 98% ⚡ · R1 72%" (⚡ = charging), or "" when none
|
||||
* is. Levels are the last known ones (the case only reports while the glasses
|
||||
* are docked), so ⚡ appears only while it is live: the glasses and Case only
|
||||
|
||||
@@ -360,7 +360,7 @@ export class IosPreviewController {
|
||||
this.logBluetooth(`Phone background; glasses ${this.state.phase}`)
|
||||
this.flushBluetoothLog()
|
||||
}
|
||||
/** Overlay an EvenHub app's phone UI (the header's app-icon button). */
|
||||
/** Overlay an EvenHub app's phone UI (the app-icon button under the mirror). */
|
||||
showEvenHubPhoneUi(windowId: string): void {
|
||||
showOnPhone(windowId)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
|
||||
|
||||
/**
|
||||
* A glasses icon as a white-on-transparent phone image (gray becomes alpha),
|
||||
* for the dark header.
|
||||
* which the phone UI tints to suit its background.
|
||||
*/
|
||||
export function grayImageToWhiteIconSource(image: GrayImage): ImageSource | null {
|
||||
const baked = image.withDrawsBaked()
|
||||
|
||||
@@ -30,7 +30,7 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
|
||||
|
||||
/**
|
||||
* A glasses icon as a white-on-transparent phone image (gray becomes alpha),
|
||||
* for the dark action bar.
|
||||
* which the phone UI tints to suit its background.
|
||||
*/
|
||||
export function grayImageToWhiteIconSource(image: GrayImage): ImageSource | null {
|
||||
if (!global.isAndroid) {
|
||||
|
||||
+16
-7
@@ -1,10 +1,17 @@
|
||||
# Main-screen UI
|
||||
|
||||
Android and iOS share `remote-controls.xml`, `remote-controls.css`, and
|
||||
`RemoteControlsViewModel`: tab order and selection, screen-size choices,
|
||||
brightness/Auto settings, watch labels, ring markings, and microphone/keyboard
|
||||
buttons. Import the stylesheet at the top of each platform's application CSS
|
||||
(before any rules), so the NativeScript CSS pipeline includes it.
|
||||
`RemoteControlsViewModel`: the bar of icon buttons under the mirror (the
|
||||
foreground EvenHub app's phone UI, microphone, keyboard, settings) and the
|
||||
touchpad below it, which is the simulated watch face or the ring pad according
|
||||
to the Phone input style setting. The settings button opens `settings-page.xml`
|
||||
(`SettingsViewModel`, `settings-page.css`), also shared: display mode,
|
||||
brightness/Auto, Phone input style and battery levels. That page needs no host:
|
||||
it reads the settings store, the shell's battery levels and
|
||||
`g2/glasses-presence`, which both platforms' controllers feed. Import the
|
||||
stylesheets at the top of each platform's application CSS (before any rules),
|
||||
so the NativeScript CSS pipeline includes them; iOS also has to register each
|
||||
shared page in `onboarding-register.ios.ts`.
|
||||
|
||||
Android's `MainViewModel` extends that shared model and connects it to
|
||||
`dashboardController`. iOS loads the same XML with `Builder.load` and connects
|
||||
@@ -28,6 +35,8 @@ audio input in preview mode. The phone path requires both Speech Recognition
|
||||
and Microphone permissions and stops when Faceclaw leaves the foreground;
|
||||
connected-glasses capture retains its existing background behavior.
|
||||
|
||||
The iOS microphone and keyboard image assets are 3x rasterizations of the
|
||||
Android vector drawables with the same names; regenerate them from those
|
||||
vectors if the icon designs change.
|
||||
The iOS microphone, keyboard and settings image assets (`ic_control_*`) are 3x
|
||||
rasterizations of the Android vector drawables with the same names; regenerate
|
||||
them from those vectors if the icon designs change. The EvenHub button's icon
|
||||
is the app's own, rendered white on transparent; `.control-icon` tints all four
|
||||
alike.
|
||||
@@ -7,11 +7,9 @@ import { IosPreviewController } from '../g2/ios-preview-controller'
|
||||
import { PhoneGestureRecognizer } from './phone-gestures'
|
||||
import { BleBandwidthMeter } from './ble-bandwidth-meter'
|
||||
import { sampleBleTraffic } from '../native/ble-traffic'
|
||||
import { glassesModelName, onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
|
||||
import { onAnySettingChanged, mirrorTouchSetting, showBleBandwidthSetting } from '../ui/dashboard-settings'
|
||||
import { loadDeviceAddresses } from '../g2/device-addresses'
|
||||
import { deviceAddressError } from '../g2/ios-peripheral-identity'
|
||||
import { formatBatteryLine } from '../g2/glasses-display-state'
|
||||
import { shell } from '../ui/shell/shell'
|
||||
|
||||
export function createMainPage(): Page {
|
||||
const page = new Page()
|
||||
@@ -22,37 +20,26 @@ export function createMainPage(): Page {
|
||||
root.rows = 'auto,*'
|
||||
page.content = root
|
||||
const header = new GridLayout()
|
||||
header.columns = '*,auto,auto,auto,auto'; header.className = 'main-header'
|
||||
header.columns = '*,auto,auto,auto'; header.className = 'main-header'
|
||||
const title = new Label()
|
||||
title.text = 'Faceclaw'; title.className = 'action-bar-title'
|
||||
header.addChild(title)
|
||||
// The foreground EvenHub app's icon, which opens its phone UI. UIImageView
|
||||
// ignores padding, so a wrapper supplies Android's wider tap target.
|
||||
const appIconButton = new GridLayout()
|
||||
appIconButton.className = 'action-bar-app-icon'; appIconButton.verticalAlignment = 'middle'
|
||||
appIconButton.visibility = 'collapse'; appIconButton.accessible = true
|
||||
const appIcon = new Image()
|
||||
appIcon.width = 21; appIcon.height = 21
|
||||
appIconButton.addChild(appIcon)
|
||||
let phoneUiWindowId: string | null = null
|
||||
appIconButton.on('tap', () => { if (phoneUiWindowId) controller.showEvenHubPhoneUi(phoneUiWindowId) })
|
||||
GridLayout.setColumn(appIconButton, 1); header.addChild(appIconButton)
|
||||
const state = new Label()
|
||||
state.text = 'Preview'; state.className = 'action-bar-status'
|
||||
state.verticalAlignment = 'middle'
|
||||
state.on('tap', () => { void openDevices() })
|
||||
GridLayout.setColumn(state, 2); header.addChild(state)
|
||||
GridLayout.setColumn(state, 1); header.addChild(state)
|
||||
// Android's warning triangle: shown while the glasses report firmware Faceclaw can't run.
|
||||
const warning = new Label()
|
||||
warning.text = '\u26A0\uFE0F'; warning.className = 'action-bar-warning'
|
||||
warning.accessibilityLabel = 'Attention needed'; warning.verticalAlignment = 'middle'
|
||||
warning.visibility = 'collapse'
|
||||
warning.on('tap', () => { void showFirmwareWarning() })
|
||||
GridLayout.setColumn(warning, 3); header.addChild(warning)
|
||||
GridLayout.setColumn(warning, 2); header.addChild(warning)
|
||||
const overflow = new Button()
|
||||
overflow.text = '⋮'; overflow.accessibilityLabel = 'More options'; overflow.className = 'overflow-button'
|
||||
overflow.on('tap', () => openMenu())
|
||||
GridLayout.setColumn(overflow, 4); header.addChild(overflow); root.addChild(header)
|
||||
GridLayout.setColumn(overflow, 3); header.addChild(overflow); root.addChild(header)
|
||||
const body = new GridLayout()
|
||||
GridLayout.setRow(body, 1); root.addChild(body)
|
||||
const mirror = new Image()
|
||||
@@ -72,10 +59,6 @@ export function createMainPage(): Page {
|
||||
keyboardPanel.bindingContext = keyboardModel
|
||||
GridLayout.setRow(keyboardPanel, 1); root.addChild(keyboardPanel)
|
||||
let focusTimer: ReturnType<typeof setTimeout> | null = null
|
||||
// The Settings tab's battery row. iOS reports charging sessions as
|
||||
// connected, so "connected" is the whole live-link condition here.
|
||||
let glassesLinked = false
|
||||
const refreshBatteryLine = () => { model.batteryLine = formatBatteryLine(shell.getBatteryLevels(), glassesLinked, glassesModelName()) }
|
||||
const keyboardField = () => keyboardPanel.getViewById<TextView>('keyboardInputField')
|
||||
const controller = new IosPreviewController((image, label) => {
|
||||
mirror.imageSource = image; model.set('padFocusLine', label)
|
||||
@@ -85,7 +68,6 @@ export function createMainPage(): Page {
|
||||
state.text = ({ connected: 'Connected', disconnected: 'Preview', connecting: 'Connecting',
|
||||
retrying: 'Reconnecting', disconnecting: 'Disconnecting', error: 'Failed' })[connection.phase]
|
||||
warning.visibility = connection.firmwareWarning ? 'visible' : 'collapse'
|
||||
glassesLinked = connection.phase === 'connected'; refreshBatteryLine()
|
||||
}, session => {
|
||||
keyboardModel.setSession(session)
|
||||
controls.visibility = session ? 'collapse' : 'visible'
|
||||
@@ -95,11 +77,10 @@ export function createMainPage(): Page {
|
||||
focusTimer = setTimeout(() => { focusTimer = null; keyboardField()?.focus() }, 0)
|
||||
} else keyboardField()?.dismissSoftInput()
|
||||
}, button => {
|
||||
phoneUiWindowId = button?.icon ? button.windowId : null
|
||||
appIcon.imageSource = button?.icon ?? null
|
||||
appIconButton.visibility = phoneUiWindowId ? 'visible' : 'collapse'
|
||||
appIconButton.accessibilityLabel = button ? `Open ${button.title} on phone` : ''
|
||||
// The foreground EvenHub app's button in the bar under the mirror.
|
||||
model.evenHubPhoneUi = button
|
||||
})
|
||||
model.showEvenHubPhoneUi = windowId => controller.showEvenHubPhoneUi(windowId)
|
||||
async function navigateDevicePage(moduleName: string, context?: object): Promise<void> {
|
||||
suppressAutoReconnect()
|
||||
await controller.disconnect()
|
||||
@@ -190,7 +171,8 @@ export function createMainPage(): Page {
|
||||
mirror.on('touch', touch(mirrorInput))
|
||||
const cancelGestures = () => { watchInput.cancel(); ringInput.cancel(); mirrorInput.cancel() }
|
||||
model.on('propertyChange', (args: PropertyChangeData) => {
|
||||
if (args.propertyName === 'watchTabVisibility') cancelGestures()
|
||||
// The other pad took this one's place (Settings > Phone input style).
|
||||
if (args.propertyName === 'watchPadVisibility') cancelGestures()
|
||||
})
|
||||
let controlsLayoutTimer: ReturnType<typeof setTimeout> | null = null
|
||||
model.set('onControlsContentLayoutChanged', (args: { object: View }) => {
|
||||
@@ -263,7 +245,6 @@ export function createMainPage(): Page {
|
||||
const resume = () => { foreground = true; controller.resume(); syncBandwidth() }
|
||||
let keyboardObserver: any = null
|
||||
let offSettings: (() => void) | null = null
|
||||
let offBattery: (() => void) | null = null
|
||||
page.on('loaded', () => {
|
||||
if (!keyboardObserver) keyboardObserver = NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(
|
||||
UIKeyboardWillChangeFrameNotification, null, NSOperationQueue.mainQueue, notification => {
|
||||
@@ -273,16 +254,15 @@ export function createMainPage(): Page {
|
||||
root.paddingBottom = Math.max(0, view.bounds.size.height - local.origin.y - view.safeAreaInsets.bottom)
|
||||
})
|
||||
Application.on(Application.suspendEvent, pause); Application.on(Application.resumeEvent, resume)
|
||||
offSettings?.(); offSettings = onAnySettingChanged(() => { model.refreshDisplayControls(); syncBandwidth() })
|
||||
offBattery?.(); offBattery = shell.onBatteryLevelsChanged(refreshBatteryLine)
|
||||
model.refreshDisplayControls(); refreshBatteryLine(); resume()
|
||||
offSettings?.(); offSettings = onAnySettingChanged(() => { model.refreshInputStyle(); syncBandwidth() })
|
||||
model.refreshInputStyle(); resume()
|
||||
if (!isPreviewOnlyMode() && !isAutoReconnectSuppressed() && !deviceAddressError(loadDeviceAddresses())) void controller.connect()
|
||||
})
|
||||
page.on('unloaded', () => {
|
||||
if (keyboardObserver) NSNotificationCenter.defaultCenter.removeObserver(keyboardObserver)
|
||||
keyboardObserver = null
|
||||
root.paddingBottom = 0
|
||||
pause(); offSettings?.(); offSettings = null; offBattery?.(); offBattery = null
|
||||
pause(); offSettings?.(); offSettings = null
|
||||
Application.off(Application.suspendEvent, pause); Application.off(Application.resumeEvent, resume)
|
||||
})
|
||||
return page
|
||||
|
||||
+11
-12
@@ -1,13 +1,12 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:rc="phone-ui" navigatingTo="navigatingTo" loaded="loaded" unloaded="unloaded">
|
||||
<ActionBar>
|
||||
<!-- Custom titleView: app title on the left; the foreground EvenHub
|
||||
app's phone-UI button, connection status and the warning-triangle
|
||||
indicator right-aligned beside the overflow menu. -->
|
||||
<GridLayout columns="auto,*,auto,auto,auto" width="100%" verticalAlignment="center">
|
||||
<!-- Custom titleView: app title on the left; connection status and
|
||||
the warning-triangle indicator right-aligned beside the overflow
|
||||
menu. -->
|
||||
<GridLayout columns="auto,*,auto,auto" width="100%" verticalAlignment="center">
|
||||
<Label col="0" text="Faceclaw" class="action-bar-title" />
|
||||
<Image col="2" src="{{ evenHubPhoneUiIcon }}" tap="{{ onEvenHubPhoneUiTap }}" visibility="{{ evenHubPhoneUiVisibility }}" class="action-bar-app-icon" />
|
||||
<Label col="3" text="{{ connectionStatusLabel }}" tap="{{ onConnectionStatusTap }}" class="action-bar-status" />
|
||||
<Label col="4" text="⚠️" tap="{{ onWarningIconTap }}" visibility="{{ warningIconVisibility }}" class="action-bar-warning" />
|
||||
<Label col="2" text="{{ connectionStatusLabel }}" tap="{{ onConnectionStatusTap }}" class="action-bar-status" />
|
||||
<Label col="3" text="⚠️" tap="{{ onWarningIconTap }}" visibility="{{ warningIconVisibility }}" class="action-bar-warning" />
|
||||
</GridLayout>
|
||||
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ connectItemEnabled }}" visibility="{{ glassesMenuItemsVisibility }}" android.position="popup" />
|
||||
<ActionItem text="Pair glasses" tap="{{ onPairGlassesTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||
@@ -32,8 +31,8 @@
|
||||
visibility="{{ displayPreviewMessageVisibility }}">
|
||||
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
<!-- The controls get the whole star row so the active tab's
|
||||
content can center in the leftover height. -->
|
||||
<!-- The controls get the whole star row so the touchpad can
|
||||
center in the leftover height. -->
|
||||
<GridLayout row="1" rows="*,auto" class="p-20">
|
||||
<rc:remote-controls row="0" visibility="{{ controlsVisibility }}" />
|
||||
<Button row="1" text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
||||
@@ -68,7 +67,7 @@
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
<!-- Developer BLE-bandwidth indicator: overlays the bottom edge of the
|
||||
page in both orientations, on every tab. -->
|
||||
page in both orientations. -->
|
||||
<Label
|
||||
text="{{ bleBandwidthLabel }}"
|
||||
visibility="{{ bleBandwidthVisibility }}"
|
||||
@@ -109,7 +108,7 @@
|
||||
<!-- Keyboard-input mode: anchored to the bottom of the (keyboard-
|
||||
shrunk) page, so it sits in the space below the mirror and only
|
||||
overlaps the mirror when the open keyboard leaves too little
|
||||
room. The tabbed controls are collapsed while it is up.
|
||||
room. The controls are collapsed while it is up.
|
||||
|
||||
NativeScript has no maxHeight, so the transparent outer grid's
|
||||
fixed height is the cap: it shrinks to the page when the keyboard
|
||||
@@ -179,7 +178,7 @@
|
||||
</ScrollView>
|
||||
</DockLayout>
|
||||
</GridLayout>
|
||||
<!-- Keyboard-input panel (the keyboard button beside the mic button):
|
||||
<!-- Keyboard-input panel (the keyboard button under the mirror):
|
||||
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
|
||||
|
||||
@@ -15,9 +15,7 @@ import {
|
||||
type View,
|
||||
} from "@nativescript/core";
|
||||
import { dashboardController, type MirrorTouchKind } from "../g2/dashboard-controller";
|
||||
import { formatBatteryLine } from "../g2/glasses-display-state";
|
||||
import {
|
||||
glassesModelName,
|
||||
mirrorTouchSetting,
|
||||
onAnySettingChanged,
|
||||
showBleBandwidthSetting,
|
||||
@@ -28,7 +26,6 @@ import { isAutoReconnectSuppressed, resumeAutoReconnect } from "../g2/reconnect-
|
||||
import { isPreviewOnlyMode } from "./onboarding-state";
|
||||
import { formatErrorMessage } from "../util/format-error";
|
||||
import { screenHeight, screenWidth } from "../ui/shell/geometry";
|
||||
import { type PhoneUiButton } from "../apps/evenhub/manager";
|
||||
|
||||
/** The paired glasses' screen aspect (4:3 on the G2, 27:11 on the RayNeo iO). */
|
||||
function lensAspectRatio(): number {
|
||||
@@ -68,7 +65,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
private _alarmReliabilityMessage = "";
|
||||
private _warningsModalVisible = false;
|
||||
private _previewMode = false;
|
||||
private _evenHubPhoneUi: PhoneUiButton | null = null;
|
||||
private _phase: "disconnected" | "connecting" | "connected" | "charging" | "disconnecting" = "disconnected";
|
||||
|
||||
// A new view model is built on every navigation to the main page; these
|
||||
@@ -78,6 +74,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.showEvenHubPhoneUi = (windowId) => dashboardController.showEvenHubPhoneUi(windowId);
|
||||
this.attach();
|
||||
}
|
||||
|
||||
@@ -95,11 +92,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.displayPreview = snapshot.displayPreview;
|
||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||
this.phase = snapshot.phase;
|
||||
this.batteryLine = formatBatteryLine(
|
||||
snapshot.batteries,
|
||||
snapshot.phase === "connected" || snapshot.phase === "charging",
|
||||
glassesModelName(),
|
||||
);
|
||||
this.activeTextSettingId = snapshot.activeTextSettingId;
|
||||
this.activeTextEditorTitle = snapshot.activeTextEditorTitle;
|
||||
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
|
||||
@@ -126,9 +118,11 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.evenHubPhoneUi = snapshot.evenHubPhoneUi;
|
||||
this.refreshPadFocusLine();
|
||||
}));
|
||||
// Brightness / display mode can change from the glasses' Settings app too.
|
||||
// The input style can change from the glasses' Settings app too, and the
|
||||
// subscription delivers no snapshot of its own: catch up on a re-attach.
|
||||
this.refreshInputStyle();
|
||||
this.unsubscribers.push(onAnySettingChanged(() => {
|
||||
this.refreshDisplayControls();
|
||||
this.refreshInputStyle();
|
||||
this.syncBleBandwidthPolling();
|
||||
}));
|
||||
this.syncBleBandwidthPolling();
|
||||
@@ -330,7 +324,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.notifyPropertyChange("activeTextSettingId", value);
|
||||
this.notifyPropertyChange("textSettingEditorVisibility", this.textSettingEditorVisibility);
|
||||
this.notifyPropertyChange("isTextSettingEditorActive", this.isTextSettingEditorActive);
|
||||
// Keyboard-input mode: the tabbed controls make way for the editor.
|
||||
// Keyboard-input mode: the controls make way for the editor.
|
||||
this.notifyPropertyChange("controlsVisibility", this.controlsVisibility);
|
||||
}
|
||||
}
|
||||
@@ -501,7 +495,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
return this.isTextSettingEditorActive ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
// ---- keyboard-input panel (the keyboard button beside the mic button) ----
|
||||
// ---- keyboard-input panel (the keyboard button under the mirror) ----
|
||||
//
|
||||
// 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).
|
||||
@@ -731,28 +725,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
return this._warningsModalVisible ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
set evenHubPhoneUi(value: PhoneUiButton | null) {
|
||||
const current = this._evenHubPhoneUi;
|
||||
if (current?.windowId === value?.windowId && current?.icon === value?.icon) return;
|
||||
this._evenHubPhoneUi = value;
|
||||
this.notifyPropertyChange("evenHubPhoneUiIcon", this.evenHubPhoneUiIcon);
|
||||
this.notifyPropertyChange("evenHubPhoneUiVisibility", this.evenHubPhoneUiVisibility);
|
||||
}
|
||||
|
||||
/** The foreground EvenHub app's icon, which opens its phone UI when tapped. */
|
||||
get evenHubPhoneUiIcon(): ImageSource | null {
|
||||
return this._evenHubPhoneUi?.icon ?? null;
|
||||
}
|
||||
|
||||
get evenHubPhoneUiVisibility(): "visible" | "collapse" {
|
||||
return this._evenHubPhoneUi?.icon ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
onEvenHubPhoneUiTap(): void {
|
||||
const windowId = this._evenHubPhoneUi?.windowId;
|
||||
if (windowId) dashboardController.showEvenHubPhoneUi(windowId);
|
||||
}
|
||||
|
||||
onWarningIconTap(): void {
|
||||
this.setWarningsModalVisible(true);
|
||||
}
|
||||
@@ -1069,7 +1041,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
// ---- the phone's own controller: touchpad, d-pad, mirror touch ----
|
||||
//
|
||||
// Everything here is the watch scheme (origin "watch"): spatial swipes,
|
||||
// tap = select, double-tap / two fingers = back, hold = menu. The ring row
|
||||
// tap = select, double-tap / two fingers = back, hold = menu. The ring pad
|
||||
// above stays on the ring's own scheme.
|
||||
|
||||
private padTwoFingerDown = false;
|
||||
@@ -1200,11 +1172,11 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
return this.mirrorGesture(swipeKind(args.direction), args);
|
||||
}
|
||||
|
||||
// ---- the tabbed controls area below the mirror ----
|
||||
// ---- the controls area below the mirror ----
|
||||
//
|
||||
// Three tabs: Settings (screen size + brightness), Watch (the simulated
|
||||
// watch face), Ring (simulated R1 inputs). The whole area collapses while a
|
||||
// text setting is being edited so the editor gets the space instead.
|
||||
// The button bar and the touchpad (remote-controls.xml). The whole area
|
||||
// collapses while a text setting is being edited or the keyboard dialog is
|
||||
// up, so the editor gets the space instead.
|
||||
|
||||
get controlsVisibility(): "visible" | "collapse" {
|
||||
return this.isTextSettingEditorActive || this._keyboardInputActive ? "collapse" : "visible";
|
||||
@@ -1213,7 +1185,7 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
// ---- BLE bandwidth indicator (Settings > Developer > Show BLE bandwidth usage) ----
|
||||
//
|
||||
// A running total of outbound BLE messages/bytes, overlaid at the bottom of
|
||||
// the page on every tab. Polled from the Java-side counters while enabled.
|
||||
// the page. Polled from the Java-side counters while enabled.
|
||||
|
||||
private _bleBandwidthLabel = "";
|
||||
private bleBandwidthTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
@@ -20,4 +20,6 @@ global.registerModule('phone-ui/document-page', () => require('./document-page')
|
||||
global.registerModule('phone-ui/document-page.xml', () => require('./document-page.xml'));
|
||||
global.registerModule('phone-ui/main-page', () => require('./main-page.ios'));
|
||||
global.registerModule('phone-ui/remote-controls.xml', () => require('./remote-controls.xml'));
|
||||
global.registerModule('phone-ui/settings-page', () => require('./settings-page'));
|
||||
global.registerModule('phone-ui/settings-page.xml', () => require('./settings-page.xml'));
|
||||
global.registerModule('phone-ui/keyboard-input-panel.xml', () => require('./keyboard-input-panel.xml'));
|
||||
@@ -1,37 +1,31 @@
|
||||
import { Dialogs, Observable } from '@nativescript/core';
|
||||
import { brightnessSetting, displayLayoutSetting, type BrightnessSetting } from '../ui/dashboard-settings';
|
||||
|
||||
type ControlsTab = 'settings' | 'watch' | 'ring';
|
||||
// Remember the tab across navigation on both platforms, without persisting it.
|
||||
let lastControlsTab: ControlsTab = 'watch';
|
||||
import { Frame, Observable, type ImageSource } from '@nativescript/core';
|
||||
import { phoneInputStyleSetting, type PhoneInputStyle } from '../ui/dashboard-settings';
|
||||
import type { PhoneUiButton } from '../apps/evenhub/manager';
|
||||
|
||||
/** Shared state and actions for remote-controls.xml; transport stays in the host. */
|
||||
export class RemoteControlsViewModel extends Observable {
|
||||
private _controlsTab: ControlsTab = lastControlsTab;
|
||||
private _batteryLine = "";
|
||||
// The pad on screen. Cached so a settings-store change only notifies (and the
|
||||
// host only cancels gestures in flight) when the style really changed.
|
||||
private _inputStyle: PhoneInputStyle = phoneInputStyleSetting.get();
|
||||
private _evenHubPhoneUi: PhoneUiButton | null = null;
|
||||
|
||||
get settingsTabVisibility(): "visible" | "collapse" {
|
||||
return this._controlsTab === "settings" ? "visible" : "collapse";
|
||||
// ---- which touchpad is showing (Settings > Phone input style) ----
|
||||
|
||||
get watchPadVisibility(): "visible" | "collapse" {
|
||||
return this._inputStyle === "watch" ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get watchTabVisibility(): "visible" | "collapse" {
|
||||
return this._controlsTab === "watch" ? "visible" : "collapse";
|
||||
get ringPadVisibility(): "visible" | "collapse" {
|
||||
return this._inputStyle === "ring" ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get ringTabVisibility(): "visible" | "collapse" {
|
||||
return this._controlsTab === "ring" ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get settingsTabClass(): string {
|
||||
return this._controlsTab === "settings" ? "tab-button tab-button-selected" : "tab-button";
|
||||
}
|
||||
|
||||
get watchTabClass(): string {
|
||||
return this._controlsTab === "watch" ? "tab-button tab-button-selected" : "tab-button";
|
||||
}
|
||||
|
||||
get ringTabClass(): string {
|
||||
return this._controlsTab === "ring" ? "tab-button tab-button-selected" : "tab-button";
|
||||
/** Re-read the input style; the host calls this when any setting changes (it can change from the glasses too). */
|
||||
public refreshInputStyle(): void {
|
||||
const style = phoneInputStyleSetting.get();
|
||||
if (style === this._inputStyle) return;
|
||||
this._inputStyle = style;
|
||||
this.notifyPropertyChange("watchPadVisibility", this.watchPadVisibility);
|
||||
this.notifyPropertyChange("ringPadVisibility", this.ringPadVisibility);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,114 +58,54 @@ export class RemoteControlsViewModel extends Observable {
|
||||
return this.padDetailLine ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
onSettingsTabTap(): void {
|
||||
this.setControlsTab("settings");
|
||||
// ---- the button bar: EvenHub phone UI, voice, keyboard, settings ----
|
||||
//
|
||||
// The mic and keyboard buttons (onSyntheticMicTap, onKeyboardTap) are the
|
||||
// host's: they go straight to its transport.
|
||||
|
||||
/** Host hook: overlay this EvenHub app's phone UI over the main page. */
|
||||
showEvenHubPhoneUi: (windowId: string) => void = () => {};
|
||||
|
||||
/**
|
||||
* The foreground glasses window's phone-UI button (phoneUiButton), or null
|
||||
* when it isn't an EvenHub app or its phone UI is already showing; set by
|
||||
* the host.
|
||||
*/
|
||||
get evenHubPhoneUi(): PhoneUiButton | null {
|
||||
return this._evenHubPhoneUi;
|
||||
}
|
||||
|
||||
onWatchTabTap(): void {
|
||||
this.setControlsTab("watch");
|
||||
set evenHubPhoneUi(value: PhoneUiButton | null) {
|
||||
const current = this._evenHubPhoneUi;
|
||||
if (current?.windowId === value?.windowId && current?.icon === value?.icon && current?.title === value?.title) return;
|
||||
this._evenHubPhoneUi = value;
|
||||
this.notifyPropertyChange("evenHubPhoneUiIcon", this.evenHubPhoneUiIcon);
|
||||
this.notifyPropertyChange("evenHubPhoneUiVisibility", this.evenHubPhoneUiVisibility);
|
||||
this.notifyPropertyChange("evenHubPhoneUiLabel", this.evenHubPhoneUiLabel);
|
||||
}
|
||||
|
||||
onRingTabTap(): void {
|
||||
this.setControlsTab("ring");
|
||||
/** The app's own icon (white on transparent; the stylesheet tints it like the other buttons'). */
|
||||
get evenHubPhoneUiIcon(): ImageSource | null {
|
||||
return this._evenHubPhoneUi?.icon ?? null;
|
||||
}
|
||||
|
||||
protected setControlsTab(tab: ControlsTab): void {
|
||||
if (this._controlsTab === tab) return;
|
||||
this._controlsTab = tab;
|
||||
// Remembered across navigations (module-level) so the page comes back on
|
||||
// the tab it left on; deliberately not persisted to disk.
|
||||
lastControlsTab = tab;
|
||||
this.notifyPropertyChange("settingsTabVisibility", this.settingsTabVisibility);
|
||||
this.notifyPropertyChange("watchTabVisibility", this.watchTabVisibility);
|
||||
this.notifyPropertyChange("ringTabVisibility", this.ringTabVisibility);
|
||||
this.notifyPropertyChange("settingsTabClass", this.settingsTabClass);
|
||||
this.notifyPropertyChange("watchTabClass", this.watchTabClass);
|
||||
this.notifyPropertyChange("ringTabClass", this.ringTabClass);
|
||||
get evenHubPhoneUiVisibility(): "visible" | "collapse" {
|
||||
return this._evenHubPhoneUi?.icon ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
// ---- display mode, brightness and battery levels, on the Settings tab ----
|
||||
|
||||
/** The Settings tab's battery row (formatBatteryLine), or "" to hide it; set by the host. */
|
||||
get batteryLine(): string {
|
||||
return this._batteryLine;
|
||||
/** The button's accessibility label. */
|
||||
get evenHubPhoneUiLabel(): string {
|
||||
return this._evenHubPhoneUi ? `Open ${this._evenHubPhoneUi.title} on phone` : "";
|
||||
}
|
||||
|
||||
set batteryLine(value: string) {
|
||||
if (this._batteryLine === value) return;
|
||||
this._batteryLine = value;
|
||||
this.notifyPropertyChange("batteryLine", value);
|
||||
this.notifyPropertyChange("batteryLineVisibility", this.batteryLineVisibility);
|
||||
onEvenHubPhoneUiTap(): void {
|
||||
// Gated on the icon like the button's visibility, so a hidden button does nothing.
|
||||
const button = this._evenHubPhoneUi;
|
||||
if (button?.icon) this.showEvenHubPhoneUi(button.windowId);
|
||||
}
|
||||
|
||||
get batteryLineVisibility(): "visible" | "collapse" {
|
||||
return this._batteryLine ? "visible" : "collapse";
|
||||
/** The gear button: display mode, brightness, battery levels and the input style. */
|
||||
onSettingsTap(): void {
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/settings-page" });
|
||||
}
|
||||
|
||||
get displayModeLabel(): string {
|
||||
return displayLayoutSetting.displayValue() + " ▾";
|
||||
}
|
||||
|
||||
async onDisplayModeTap(): Promise<void> {
|
||||
const current = displayLayoutSetting.get();
|
||||
// Full Screen is offered only with a bottom or popup app switcher.
|
||||
const values = displayLayoutSetting.values.filter((value) => !displayLayoutSetting.isDisabled(value));
|
||||
const options = values.map((value) => displayLayoutSetting.displayValue(value) + (value === current ? " ✓" : ""));
|
||||
const picked = await Dialogs.action({ title: "Display mode", cancelButtonText: "Cancel", actions: options });
|
||||
const index = options.indexOf(picked);
|
||||
if (index < 0) return;
|
||||
const value = values[index]!;
|
||||
if (value !== current) displayLayoutSetting.set(value);
|
||||
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
|
||||
}
|
||||
|
||||
get brightnessAuto(): boolean {
|
||||
return brightnessSetting.get() === "auto";
|
||||
}
|
||||
|
||||
get brightnessSliderEnabled(): boolean {
|
||||
return !this.brightnessAuto;
|
||||
}
|
||||
|
||||
/** The slider's position; while Auto, the last manual level (or 50). */
|
||||
get brightnessPercent(): number {
|
||||
const value = brightnessSetting.get();
|
||||
if (value === "auto") return this.lastManualBrightness;
|
||||
const numeric = parseInt(value, 10);
|
||||
return Number.isFinite(numeric) ? numeric : 50;
|
||||
}
|
||||
|
||||
private lastManualBrightness = 50;
|
||||
|
||||
onBrightnessChange(args: { value?: number; object?: { value?: number } }): void {
|
||||
if (this.brightnessAuto) return;
|
||||
const raw = typeof args.value === "number" ? args.value : Number(args.object?.value ?? NaN);
|
||||
if (!Number.isFinite(raw)) return;
|
||||
// The setting only has every tenth level; snap to the nearest.
|
||||
const level = Math.min(100, Math.max(2, Math.round(raw / 10) * 10));
|
||||
this.lastManualBrightness = level;
|
||||
const value = String(level) as BrightnessSetting;
|
||||
if (brightnessSetting.get() !== value) brightnessSetting.set(value);
|
||||
}
|
||||
|
||||
onBrightnessAutoChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
|
||||
const on = typeof args.value === "boolean" ? args.value : Boolean(args.object?.checked);
|
||||
if (on) {
|
||||
if (brightnessSetting.get() !== "auto") {
|
||||
this.lastManualBrightness = this.brightnessPercent;
|
||||
brightnessSetting.set("auto");
|
||||
}
|
||||
} else if (brightnessSetting.get() === "auto") {
|
||||
brightnessSetting.set(String(this.lastManualBrightness) as BrightnessSetting);
|
||||
}
|
||||
this.refreshDisplayControls();
|
||||
}
|
||||
|
||||
public refreshDisplayControls(): void {
|
||||
this.notifyPropertyChange("brightnessAuto", this.brightnessAuto);
|
||||
this.notifyPropertyChange("brightnessSliderEnabled", this.brightnessSliderEnabled);
|
||||
this.notifyPropertyChange("brightnessPercent", this.brightnessPercent);
|
||||
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,97 +2,56 @@
|
||||
.remote-controls {
|
||||
margin: 0 8 0 8;
|
||||
}
|
||||
/* The Settings / Watch / Ring tab bar above the controls. */
|
||||
.controls-tab-bar {
|
||||
/* The bar of icon buttons above the touchpad: the foreground EvenHub app's
|
||||
* phone UI (when there is one), voice input, the keyboard dialog, Settings.
|
||||
* The XML gives the bar the watch face's width, so the buttons line up with
|
||||
* that pad's right edge. */
|
||||
.control-bar {
|
||||
margin-bottom: 8;
|
||||
}
|
||||
.tab-button {
|
||||
font-size: 14;
|
||||
padding: 8 0;
|
||||
margin: 0 2;
|
||||
border-radius: 6;
|
||||
background-color: #e2e2e2;
|
||||
color: #333333;
|
||||
}
|
||||
.tab-button-selected {
|
||||
background-color: #424242;
|
||||
color: #ffffff;
|
||||
}
|
||||
/* The wakeword and keyboard buttons at the tab bar's right edge: icon-only,
|
||||
* narrower than the tabs, and never in the selected state (they aren't tabs).
|
||||
* Each is a button-styled GridLayout (Buttons can't hold images), so it
|
||||
* borrows the .tab-button look and adds the elevation MaterialButtons get for
|
||||
* free. */
|
||||
.tab-icon-button {
|
||||
/* Each is a button-styled GridLayout (Buttons can't hold images), with the
|
||||
* elevation MaterialButtons get for free. */
|
||||
.control-button {
|
||||
width: 56;
|
||||
/* The real MaterialButtons render 48dp tall inside a 60dp layout box (6dp
|
||||
/* A real MaterialButton renders 48dp tall inside a 60dp layout box (6dp
|
||||
* insets top and bottom); the margins and explicit height reproduce that.
|
||||
* The height also bounds the tile's measure, without which its star row
|
||||
* would collapse to content and pin the icon to the top. */
|
||||
height: 48;
|
||||
margin: 6 2;
|
||||
border-radius: 6;
|
||||
background-color: #e2e2e2;
|
||||
android-elevation: 2;
|
||||
}
|
||||
.tab-icon {
|
||||
/* Flush with the pad's right edge. */
|
||||
.control-button-last {
|
||||
margin-right: 0;
|
||||
}
|
||||
/* Also recolours the EvenHub app's icon, which arrives white on transparent. */
|
||||
.control-icon {
|
||||
height: 20;
|
||||
tint-color: #333333;
|
||||
}
|
||||
/* Landscape uses the full page height and a shared left edge for tabs/pad. */
|
||||
/* Landscape uses the full page height and a narrower column. */
|
||||
.landscape-layout .remote-controls {
|
||||
margin: 0;
|
||||
}
|
||||
.landscape-layout .controls-tab-bar {
|
||||
.landscape-layout .control-bar {
|
||||
margin-bottom: 2;
|
||||
}
|
||||
.landscape-layout .tab-button {
|
||||
.landscape-layout .control-button {
|
||||
width: 48;
|
||||
margin-left: 1;
|
||||
margin-right: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.landscape-layout .tab-button[col="0"] {
|
||||
margin-left: 0;
|
||||
}
|
||||
.landscape-layout .tab-icon-button {
|
||||
width: 48;
|
||||
}
|
||||
.landscape-layout .tab-icon-button[col="4"] {
|
||||
.landscape-layout .control-button-last {
|
||||
margin-right: 0;
|
||||
}
|
||||
.ns-dark .tab-icon {
|
||||
tint-color: #cccccc;
|
||||
}
|
||||
.ns-dark .tab-button {
|
||||
.ns-dark .control-button {
|
||||
background-color: #333333;
|
||||
color: #cccccc;
|
||||
}
|
||||
.ns-dark .tab-button-selected {
|
||||
background-color: #e2e2e2;
|
||||
color: #222222;
|
||||
}
|
||||
/* Settings tab rows. */
|
||||
.settings-row {
|
||||
margin-bottom: 8;
|
||||
}
|
||||
.settings-row-label {
|
||||
font-size: 14;
|
||||
margin-right: 10;
|
||||
}
|
||||
.mode-button {
|
||||
font-size: 13;
|
||||
padding: 6 10;
|
||||
margin-right: 6;
|
||||
}
|
||||
.brightness-icon {
|
||||
font-size: 16;
|
||||
margin: 0 4 0 4;
|
||||
color: #444444;
|
||||
}
|
||||
.auto-toggle Label {
|
||||
font-size: 13;
|
||||
margin-right: 2;
|
||||
}
|
||||
.settings-battery-line {
|
||||
font-size: 14;
|
||||
.ns-dark .control-icon {
|
||||
tint-color: #cccccc;
|
||||
}
|
||||
.touchpad {
|
||||
height: 230;
|
||||
@@ -129,7 +88,7 @@
|
||||
margin: 2;
|
||||
font-size: 14;
|
||||
}
|
||||
/* Ring tab: the same touchpad, but portrait like the ring's own pad. */
|
||||
/* Ring input style: the same touchpad, but portrait like the ring's own pad. */
|
||||
.ring-touchpad {
|
||||
width: 150;
|
||||
height: 250;
|
||||
|
||||
@@ -1,80 +1,70 @@
|
||||
<!--
|
||||
The phone's controller for the glasses, as a three-tab area below the mirror:
|
||||
Settings (display mode, brightness and battery levels), Watch (the
|
||||
simulated watch face: same scheme as the watch pad - tap = select,
|
||||
double-tap or two fingers = back, hold = menu, swipes navigate), and Ring
|
||||
(a touchpad on the ring's own scheme: vertical swipes scroll,
|
||||
tap/double-tap/hold = click/double-click/long-press). Tap-then-hold on either pad is the G2 system-menu gesture. The
|
||||
narrow mic and keyboard buttons at the tab bar's right edge fire the
|
||||
wakeword / open the keyboard dialog without changing the selected tab. Used
|
||||
by main-page.xml in both orientations; binds to the page's MainViewModel,
|
||||
which collapses the whole area while a text setting is being edited or the
|
||||
keyboard dialog is up (keyboard-input mode).
|
||||
The phone's controller for the glasses, below the mirror: a bar of icon
|
||||
buttons over a touchpad.
|
||||
|
||||
The root is a rows="auto,*" grid so the active section can use the leftover
|
||||
height (the Watch face centers in it); the three sections share the star
|
||||
cell, only one visible at a time.
|
||||
The buttons are right-aligned: the foreground EvenHub app's phone UI (shown
|
||||
only while such an app is in front; leftmost, so its coming and going moves
|
||||
none of the others), voice input (fires the wakeword), the keyboard dialog,
|
||||
and Settings (the phone's settings page: display mode, brightness, battery
|
||||
levels, input style).
|
||||
|
||||
The touchpad imitates the device picked by Settings > Phone input style.
|
||||
Watch is the simulated watch face, on the watch pad's scheme: tap = select,
|
||||
double-tap or two fingers = back, hold = menu, swipes navigate. Ring is a
|
||||
touchpad on the ring's own scheme: vertical swipes scroll, tap/double-tap/
|
||||
hold = click/double-click/long-press. Tap-then-hold on either pad is the G2
|
||||
system-menu gesture.
|
||||
|
||||
Used by main-page.xml in both orientations on Android and loaded by
|
||||
main-page.ios.ts; binds to a RemoteControlsViewModel (Android's
|
||||
MainViewModel extends it). The host collapses the whole area while a text
|
||||
setting is being edited or the keyboard dialog is up (keyboard-input mode).
|
||||
|
||||
The root is a rows="auto,*" grid so the pad can use the leftover height (it
|
||||
centers in it); the two pads share the star cell, only one visible at a time.
|
||||
-->
|
||||
<GridLayout xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:android="http://schemas.nativescript.org/tns.xsd" rows="auto,*" class="remote-controls">
|
||||
<!-- rows="auto" everywhere below: a rows-less GridLayout's implicit row
|
||||
acts as star, and this component sits in a bounded (star-row) parent,
|
||||
where that would balloon the first grid to fill all remaining height. -->
|
||||
<GridLayout row="0" rows="auto" columns="*,*,*,auto,auto" class="controls-tab-bar">
|
||||
<Button col="0" text="Settings" textWrap="false" tap="{{ onSettingsTabTap }}" class="{{ settingsTabClass }}" />
|
||||
<Button col="1" text="Watch" textWrap="false" tap="{{ onWatchTabTap }}" class="{{ watchTabClass }}" />
|
||||
<Button col="2" text="Ring" textWrap="false" tap="{{ onRingTabTap }}" class="{{ ringTabClass }}" />
|
||||
<!-- rows="auto": a rows-less GridLayout's implicit row acts as star, and
|
||||
this component sits in a bounded (star-row) parent, where that would
|
||||
balloon the bar to fill all remaining height. The star column takes the
|
||||
slack, so the buttons hug the right edge: the watch face's, since the
|
||||
bar is as wide as that pad and centered like it. -->
|
||||
<GridLayout row="0" rows="auto" columns="*,auto,auto,auto,auto" width="{{ watchFaceWidth }}" horizontalAlignment="center" class="control-bar">
|
||||
<!-- A Button can't hold an image, so these are button-styled tiles. The
|
||||
explicit star row makes the cell fill the tile's height so the icon's
|
||||
center alignment has room to work in. -->
|
||||
<GridLayout col="3" rows="*" accessible="true" accessibilityRole="button" accessibilityLabel="Voice input" tap="{{ onSyntheticMicTap }}" class="tab-button tab-icon-button">
|
||||
<Image src="res://ic_tab_mic" class="tab-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
<GridLayout col="1" rows="*" accessible="true" accessibilityRole="button" accessibilityLabel="{{ evenHubPhoneUiLabel }}" tap="{{ onEvenHubPhoneUiTap }}" visibility="{{ evenHubPhoneUiVisibility }}" class="control-button">
|
||||
<Image src="{{ evenHubPhoneUiIcon }}" class="control-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
</GridLayout>
|
||||
<GridLayout col="4" rows="*" accessible="true" accessibilityRole="button" accessibilityLabel="Keyboard input" tap="{{ onKeyboardTap }}" class="tab-button tab-icon-button">
|
||||
<Image src="res://ic_tab_keyboard" class="tab-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
<GridLayout col="2" rows="*" accessible="true" accessibilityRole="button" accessibilityLabel="Voice input" tap="{{ onSyntheticMicTap }}" class="control-button">
|
||||
<Image src="res://ic_control_mic" class="control-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
</GridLayout>
|
||||
<GridLayout col="3" rows="*" accessible="true" accessibilityRole="button" accessibilityLabel="Keyboard input" tap="{{ onKeyboardTap }}" class="control-button">
|
||||
<Image src="res://ic_control_keyboard" class="control-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
</GridLayout>
|
||||
<GridLayout col="4" rows="*" accessible="true" accessibilityRole="button" accessibilityLabel="Settings" tap="{{ onSettingsTap }}" class="control-button control-button-last">
|
||||
<Image src="res://ic_control_settings" class="control-icon" verticalAlignment="center" horizontalAlignment="center" />
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
|
||||
<GridLayout row="1" layoutChanged="{{ onControlsContentLayoutChanged }}">
|
||||
<!-- Settings tab -->
|
||||
<StackLayout visibility="{{ settingsTabVisibility }}">
|
||||
<GridLayout rows="auto" columns="auto,*" class="settings-row">
|
||||
<Label col="0" text="Display mode" class="settings-row-label" verticalAlignment="center" />
|
||||
<Button col="1" text="{{ displayModeLabel }}" tap="{{ onDisplayModeTap }}" class="mode-button" horizontalAlignment="left" />
|
||||
</GridLayout>
|
||||
<GridLayout rows="auto" columns="auto,*,auto" class="settings-row">
|
||||
<Label col="0" text="☀" class="brightness-icon" verticalAlignment="center" />
|
||||
<Slider col="1" width="100%" minValue="2" maxValue="100" value="{{ brightnessPercent }}" valueChange="{{ onBrightnessChange }}" isEnabled="{{ brightnessSliderEnabled }}" />
|
||||
<StackLayout col="2" orientation="horizontal" verticalAlignment="center" class="auto-toggle">
|
||||
<Label text="Auto" verticalAlignment="center" />
|
||||
<Switch checked="{{ brightnessAuto }}" checkedChange="{{ onBrightnessAutoChange }}" />
|
||||
</StackLayout>
|
||||
</GridLayout>
|
||||
<!-- Last-known levels of the glasses, their charging case and the R1;
|
||||
collapsed until one is known. Last so its appearing doesn't move
|
||||
the controls above. -->
|
||||
<GridLayout rows="auto" columns="auto,*" class="settings-row" visibility="{{ batteryLineVisibility }}">
|
||||
<Label col="0" text="Battery" class="settings-row-label" verticalAlignment="center" />
|
||||
<Label col="1" text="{{ batteryLine }}" textWrap="true" class="settings-battery-line" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
</StackLayout>
|
||||
|
||||
<!-- Watch tab: centered in the leftover height, capped at the 1.5:1 face
|
||||
<!-- Watch: centered in the leftover height, capped at the 1.5:1 face
|
||||
aspect (watchFaceWidth = min(available, 1.5 x face height). The star
|
||||
rows center the status line, plus the wake hint under it while the
|
||||
display is off (a double-tap is the only gesture that wakes it), or
|
||||
the charging case's level while the glasses charge in it. -->
|
||||
<GridLayout visibility="{{ watchTabVisibility }}" width="{{ watchFaceWidth }}" height="{{ watchFaceHeight }}" rows="*,auto,auto,auto,*" horizontalAlignment="center" verticalAlignment="center" class="touchpad" android:tap="{{ onPadTap }}" android:doubleTap="{{ onPadDoubleTap }}" android:longPress="{{ onPadLongPress }}" android:swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}">
|
||||
<GridLayout visibility="{{ watchPadVisibility }}" width="{{ watchFaceWidth }}" height="{{ watchFaceHeight }}" rows="*,auto,auto,auto,*" horizontalAlignment="center" verticalAlignment="center" class="touchpad" android:tap="{{ onPadTap }}" android:doubleTap="{{ onPadDoubleTap }}" android:longPress="{{ onPadLongPress }}" android:swipe="{{ onPadSwipe }}" touch="{{ onPadTouch }}">
|
||||
<Label row="1" isUserInteractionEnabled="false" text="{{ padFocusLine }}" class="{{ padFocusClass }}" horizontalAlignment="center" />
|
||||
<Label row="2" isUserInteractionEnabled="false" text="●● wake" visibility="{{ padWakeHintVisibility }}" class="pad-wake-hint" horizontalAlignment="center" />
|
||||
<Label row="3" isUserInteractionEnabled="false" text="{{ padDetailLine }}" visibility="{{ padDetailVisibility }}" class="pad-detail" horizontalAlignment="center" />
|
||||
</GridLayout>
|
||||
|
||||
<!-- Ring tab: a touchpad on the ring's own scheme. Vertical swipes only
|
||||
(the ring has no horizontal axis) and no focus/status line; portrait
|
||||
like the ring's pad itself. The auto rows hold the cosmetic markings the
|
||||
<!-- Ring: a touchpad on the ring's own scheme. Vertical swipes only (the
|
||||
ring has no horizontal axis) and no focus/status line; portrait like
|
||||
the ring's pad itself. The auto rows hold the cosmetic markings the
|
||||
physical ring has on its touch strip (they don't take touches); the star
|
||||
rows are the seven equal gaps around them, edges included. -->
|
||||
<GridLayout visibility="{{ ringTabVisibility }}" height="{{ ringTouchpadHeight }}" class="touchpad ring-touchpad"
|
||||
<GridLayout visibility="{{ ringPadVisibility }}" height="{{ ringTouchpadHeight }}" class="touchpad ring-touchpad"
|
||||
rows="*,auto,*,auto,*,auto,*,auto,*,auto,*,auto,*"
|
||||
horizontalAlignment="center" verticalAlignment="center"
|
||||
android:tap="{{ onRingPadTap }}" android:doubleTap="{{ onRingPadDoubleTap }}"
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* The phone's settings page (phone-ui/settings-page.xml), opened by the gear
|
||||
* button under the main page's mirror. Imported by both app.css and
|
||||
* app.ios.css (iOS loads the latter instead of the former), so every Button
|
||||
* here sets its whole look rather than leaning on either platform's default.
|
||||
*
|
||||
* The controls' rules are scoped under .settings-form on purpose: the theme
|
||||
* gives Buttons, Switches and Sliders wide per-platform margins with
|
||||
* selectors like `.ns-android Button`, which outrank a lone class.
|
||||
*/
|
||||
.settings-form {
|
||||
padding: 4 16 16 16;
|
||||
}
|
||||
.settings-form-row {
|
||||
padding: 12 0;
|
||||
border-bottom-width: 1;
|
||||
border-bottom-color: #e0e0e0;
|
||||
}
|
||||
.settings-form-label {
|
||||
font-size: 16;
|
||||
}
|
||||
.settings-form-value {
|
||||
font-size: 15;
|
||||
color: #555555;
|
||||
}
|
||||
.settings-form-switch-label {
|
||||
margin-right: 8;
|
||||
}
|
||||
.settings-form .settings-form-switch {
|
||||
margin: 0;
|
||||
}
|
||||
.settings-form .settings-form-slider {
|
||||
margin: 10 0 2 0;
|
||||
}
|
||||
/* Explanatory text under a row's control, and the page's closing note. */
|
||||
.settings-form-hint {
|
||||
font-size: 13;
|
||||
color: #666666;
|
||||
margin-top: 8;
|
||||
}
|
||||
.settings-form-footer {
|
||||
margin-top: 16;
|
||||
}
|
||||
.brightness-icon {
|
||||
font-size: 16;
|
||||
margin: 0 4 0 0;
|
||||
color: #444444;
|
||||
}
|
||||
/* Right-aligned beside its label; long lines (three devices) wrap. */
|
||||
.settings-battery-line {
|
||||
text-align: right;
|
||||
margin-left: 12;
|
||||
}
|
||||
/* A value that opens a list of choices when tapped. The theme makes every
|
||||
* Button 52 tall; these sit in a row beside a label. */
|
||||
.settings-form .settings-picker-button {
|
||||
font-size: 14;
|
||||
height: 40;
|
||||
padding: 0 12;
|
||||
margin: 0;
|
||||
border-radius: 6;
|
||||
background-color: #e2e2e2;
|
||||
color: #333333;
|
||||
}
|
||||
/* A two-way choice as a pair of buttons, the chosen one filled in. */
|
||||
.settings-form .segment-button {
|
||||
font-size: 14;
|
||||
height: 40;
|
||||
padding: 0 14;
|
||||
margin: 0 0 0 6;
|
||||
border-radius: 6;
|
||||
background-color: #e2e2e2;
|
||||
color: #333333;
|
||||
}
|
||||
.settings-form .segment-button-selected {
|
||||
background-color: #424242;
|
||||
color: #ffffff;
|
||||
}
|
||||
.ns-dark .settings-form-row {
|
||||
border-bottom-color: #3a3a3a;
|
||||
}
|
||||
.ns-dark .settings-form-value {
|
||||
color: #b8b8b8;
|
||||
}
|
||||
.ns-dark .settings-form-hint {
|
||||
color: #a0a0a0;
|
||||
}
|
||||
.ns-dark .brightness-icon {
|
||||
color: #cccccc;
|
||||
}
|
||||
.ns-dark .settings-form .settings-picker-button,
|
||||
.ns-dark .settings-form .segment-button {
|
||||
background-color: #444444;
|
||||
color: #dddddd;
|
||||
}
|
||||
.ns-dark .settings-form .segment-button-selected {
|
||||
background-color: #e2e2e2;
|
||||
color: #222222;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { EventData, NavigatedData, Page } from "@nativescript/core";
|
||||
|
||||
import { SettingsViewModel } from "./settings-view-model";
|
||||
|
||||
/**
|
||||
* The phone's settings page, opened by the gear button under the main page's
|
||||
* mirror. Shared by Android and iOS (registered in onboarding-register.ios.ts).
|
||||
*/
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
if (!page.bindingContext) page.bindingContext = new SettingsViewModel();
|
||||
}
|
||||
|
||||
// loaded/unloaded also bracket an app suspend, so the model's subscriptions
|
||||
// only live while the page is actually on screen.
|
||||
export function loaded(args: EventData): void {
|
||||
((args.object as Page).bindingContext as SettingsViewModel | undefined)?.attach();
|
||||
}
|
||||
|
||||
export function unloaded(args: EventData): void {
|
||||
((args.object as Page).bindingContext as SettingsViewModel | undefined)?.detach();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<!--
|
||||
The phone's settings page: the glasses' display mode and brightness, the
|
||||
main page's input style (which touchpad it shows) and battery levels.
|
||||
Opened by the gear button under the mirror; binds to a SettingsViewModel on
|
||||
both platforms. Styles are in settings-page.css.
|
||||
-->
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" loaded="loaded" unloaded="unloaded" class="settings-page">
|
||||
<ActionBar title="Settings">
|
||||
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ onBackTap }}" />
|
||||
</ActionBar>
|
||||
|
||||
<ScrollView>
|
||||
<!-- rows="auto" on every grid: a rows-less GridLayout's implicit row
|
||||
acts as star and would stretch in the ScrollView's StackLayout. -->
|
||||
<StackLayout class="settings-form">
|
||||
<GridLayout rows="auto" columns="*,auto" class="settings-form-row">
|
||||
<Label col="0" text="Display mode" class="settings-form-label" verticalAlignment="center" />
|
||||
<Button col="1" text="{{ displayModeLabel }}" textWrap="false" tap="{{ onDisplayModeTap }}" class="settings-picker-button" />
|
||||
</GridLayout>
|
||||
|
||||
<StackLayout class="settings-form-row">
|
||||
<GridLayout rows="auto" columns="*,auto,auto">
|
||||
<Label col="0" text="Brightness" class="settings-form-label" verticalAlignment="center" />
|
||||
<Label col="1" text="Auto" class="settings-form-value settings-form-switch-label" verticalAlignment="center" />
|
||||
<Switch col="2" checked="{{ brightnessAuto }}" checkedChange="{{ onBrightnessAutoChange }}" verticalAlignment="center" class="settings-form-switch" />
|
||||
</GridLayout>
|
||||
<GridLayout rows="auto" columns="auto,*">
|
||||
<Label col="0" text="☀" class="brightness-icon" verticalAlignment="center" />
|
||||
<Slider col="1" width="100%" minValue="2" maxValue="100" value="{{ brightnessPercent }}" valueChange="{{ onBrightnessChange }}" isEnabled="{{ brightnessSliderEnabled }}" class="settings-form-slider" />
|
||||
</GridLayout>
|
||||
</StackLayout>
|
||||
|
||||
<!-- Which touchpad the main page shows under the mirror. -->
|
||||
<StackLayout class="settings-form-row">
|
||||
<GridLayout rows="auto" columns="*,auto,auto">
|
||||
<Label col="0" text="Phone input style" class="settings-form-label" verticalAlignment="center" />
|
||||
<Button col="1" text="Watch" textWrap="false" tap="{{ onWatchStyleTap }}" class="{{ watchStyleClass }}" />
|
||||
<Button col="2" text="Ring" textWrap="false" tap="{{ onRingStyleTap }}" class="{{ ringStyleClass }}" />
|
||||
</GridLayout>
|
||||
<Label text="{{ phoneInputStyleHint }}" textWrap="true" class="settings-form-hint" />
|
||||
</StackLayout>
|
||||
|
||||
<!-- Last-known levels of the glasses, their charging case and the
|
||||
R1; collapsed until one is known. Last so its appearing
|
||||
doesn't move the controls above. -->
|
||||
<GridLayout rows="auto" columns="auto,*" class="settings-form-row" visibility="{{ batteryLineVisibility }}">
|
||||
<Label col="0" text="Battery" class="settings-form-label" verticalAlignment="center" />
|
||||
<Label col="1" text="{{ batteryLine }}" textWrap="true" class="settings-form-value settings-battery-line" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
|
||||
<Label text="More settings are in the Settings app on the glasses." textWrap="true" class="settings-form-hint settings-form-footer" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</Page>
|
||||
@@ -0,0 +1,189 @@
|
||||
import { Dialogs, Frame, Observable } from '@nativescript/core';
|
||||
import {
|
||||
brightnessSetting,
|
||||
displayLayoutSetting,
|
||||
glassesModelName,
|
||||
onAnySettingChanged,
|
||||
phoneInputStyleSetting,
|
||||
type BrightnessSetting,
|
||||
type PhoneInputStyle,
|
||||
} from '../ui/dashboard-settings';
|
||||
import { formatBatteryLine } from '../g2/glasses-display-state';
|
||||
import { getGlassesPresence, onGlassesPresenceChanged } from '../g2/glasses-presence';
|
||||
import { shell } from '../ui/shell/shell';
|
||||
|
||||
/** What each input style's touchpad does, under the Phone input style row. */
|
||||
const INPUT_STYLE_HINTS: Record<PhoneInputStyle, string> = {
|
||||
watch: "Like the watch remote: swipes navigate, tap selects, double-tap or two fingers goes back, a hold opens the menu.",
|
||||
ring: "Like the R1's touch strip: vertical swipes scroll; tap, double-tap and hold are click, double-click and long-press.",
|
||||
};
|
||||
|
||||
/**
|
||||
* The phone's settings page (settings-page.xml), opened by the gear button
|
||||
* under the mirror: display mode, brightness, the main page's input style and
|
||||
* battery levels. Shared by Android and iOS: everything it shows comes from
|
||||
* the settings store, the shell's battery levels and the glasses-presence
|
||||
* module, which both platforms' controllers feed, so it needs no host.
|
||||
*/
|
||||
export class SettingsViewModel extends Observable {
|
||||
private readonly unsubscribers: Array<() => void> = [];
|
||||
private _batteryLine = "";
|
||||
private lastManualBrightness = 50;
|
||||
|
||||
/**
|
||||
* Subscribe while the page is on screen (its `loaded`) and catch up on
|
||||
* whatever changed while it wasn't. Idempotent.
|
||||
*/
|
||||
attach(): void {
|
||||
if (this.unsubscribers.length > 0) return;
|
||||
this.unsubscribers.push(
|
||||
// Every row can also change from the glasses' Settings app.
|
||||
onAnySettingChanged(() => this.refreshSettings()),
|
||||
shell.onBatteryLevelsChanged(() => this.refreshBatteryLine()),
|
||||
onGlassesPresenceChanged(() => this.refreshBatteryLine()),
|
||||
);
|
||||
this.refreshSettings();
|
||||
this.refreshBatteryLine();
|
||||
}
|
||||
|
||||
/** The page's `unloaded`. */
|
||||
detach(): void {
|
||||
for (const unsubscribe of this.unsubscribers.splice(0)) unsubscribe();
|
||||
}
|
||||
|
||||
onBackTap(): void {
|
||||
Frame.topmost()?.goBack();
|
||||
}
|
||||
|
||||
private refreshSettings(): void {
|
||||
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
|
||||
this.notifyPropertyChange("brightnessAuto", this.brightnessAuto);
|
||||
this.notifyPropertyChange("brightnessSliderEnabled", this.brightnessSliderEnabled);
|
||||
this.notifyPropertyChange("brightnessPercent", this.brightnessPercent);
|
||||
this.notifyPropertyChange("watchStyleClass", this.watchStyleClass);
|
||||
this.notifyPropertyChange("ringStyleClass", this.ringStyleClass);
|
||||
this.notifyPropertyChange("phoneInputStyleHint", this.phoneInputStyleHint);
|
||||
}
|
||||
|
||||
// ---- display mode ----
|
||||
|
||||
get displayModeLabel(): string {
|
||||
return displayLayoutSetting.displayValue() + " ▾";
|
||||
}
|
||||
|
||||
async onDisplayModeTap(): Promise<void> {
|
||||
const current = displayLayoutSetting.get();
|
||||
// Full Screen is offered only with a bottom or popup app switcher.
|
||||
const values = displayLayoutSetting.values.filter((value) => !displayLayoutSetting.isDisabled(value));
|
||||
const options = values.map((value) => displayLayoutSetting.displayValue(value) + (value === current ? " ✓" : ""));
|
||||
const picked = await Dialogs.action({ title: "Display mode", cancelButtonText: "Cancel", actions: options });
|
||||
const index = options.indexOf(picked);
|
||||
if (index < 0) return;
|
||||
const value = values[index]!;
|
||||
if (value !== current) displayLayoutSetting.set(value);
|
||||
this.notifyPropertyChange("displayModeLabel", this.displayModeLabel);
|
||||
}
|
||||
|
||||
// ---- brightness ----
|
||||
|
||||
get brightnessAuto(): boolean {
|
||||
return brightnessSetting.get() === "auto";
|
||||
}
|
||||
|
||||
get brightnessSliderEnabled(): boolean {
|
||||
return !this.brightnessAuto;
|
||||
}
|
||||
|
||||
/** The slider's position; while Auto, the last manual level (or 50). */
|
||||
get brightnessPercent(): number {
|
||||
const value = brightnessSetting.get();
|
||||
if (value === "auto") return this.lastManualBrightness;
|
||||
const numeric = parseInt(value, 10);
|
||||
return Number.isFinite(numeric) ? numeric : 50;
|
||||
}
|
||||
|
||||
onBrightnessChange(args: { value?: number; object?: { value?: number } }): void {
|
||||
if (this.brightnessAuto) return;
|
||||
const raw = typeof args.value === "number" ? args.value : Number(args.object?.value ?? NaN);
|
||||
if (!Number.isFinite(raw)) return;
|
||||
// The setting only has every tenth level; snap to the nearest.
|
||||
const level = Math.min(100, Math.max(2, Math.round(raw / 10) * 10));
|
||||
this.lastManualBrightness = level;
|
||||
const value = String(level) as BrightnessSetting;
|
||||
if (brightnessSetting.get() !== value) brightnessSetting.set(value);
|
||||
}
|
||||
|
||||
onBrightnessAutoChange(args: { value?: boolean; object?: { checked?: boolean } }): void {
|
||||
const on = typeof args.value === "boolean" ? args.value : Boolean(args.object?.checked);
|
||||
if (on) {
|
||||
if (brightnessSetting.get() !== "auto") {
|
||||
this.lastManualBrightness = this.brightnessPercent;
|
||||
brightnessSetting.set("auto");
|
||||
}
|
||||
} else if (brightnessSetting.get() === "auto") {
|
||||
brightnessSetting.set(String(this.lastManualBrightness) as BrightnessSetting);
|
||||
}
|
||||
this.notifyPropertyChange("brightnessAuto", this.brightnessAuto);
|
||||
this.notifyPropertyChange("brightnessSliderEnabled", this.brightnessSliderEnabled);
|
||||
this.notifyPropertyChange("brightnessPercent", this.brightnessPercent);
|
||||
}
|
||||
|
||||
// ---- phone input style: which touchpad the main page shows ----
|
||||
|
||||
get watchStyleClass(): string {
|
||||
return segmentClass(phoneInputStyleSetting.get() === "watch");
|
||||
}
|
||||
|
||||
get ringStyleClass(): string {
|
||||
return segmentClass(phoneInputStyleSetting.get() === "ring");
|
||||
}
|
||||
|
||||
get phoneInputStyleHint(): string {
|
||||
return INPUT_STYLE_HINTS[phoneInputStyleSetting.get()];
|
||||
}
|
||||
|
||||
onWatchStyleTap(): void {
|
||||
this.setPhoneInputStyle("watch");
|
||||
}
|
||||
|
||||
onRingStyleTap(): void {
|
||||
this.setPhoneInputStyle("ring");
|
||||
}
|
||||
|
||||
private setPhoneInputStyle(style: PhoneInputStyle): void {
|
||||
if (phoneInputStyleSetting.get() === style) return;
|
||||
phoneInputStyleSetting.set(style);
|
||||
// The store's own change notification arrives a tick later; don't leave
|
||||
// the buttons showing the old choice until then.
|
||||
this.notifyPropertyChange("watchStyleClass", this.watchStyleClass);
|
||||
this.notifyPropertyChange("ringStyleClass", this.ringStyleClass);
|
||||
this.notifyPropertyChange("phoneInputStyleHint", this.phoneInputStyleHint);
|
||||
}
|
||||
|
||||
// ---- battery levels ----
|
||||
|
||||
/**
|
||||
* Last-known levels of the glasses, their charging case and the R1
|
||||
* (formatBatteryLine), or "" (the row is then hidden) while none is known.
|
||||
*/
|
||||
get batteryLine(): string {
|
||||
return this._batteryLine;
|
||||
}
|
||||
|
||||
get batteryLineVisibility(): "visible" | "collapse" {
|
||||
return this._batteryLine ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
private refreshBatteryLine(): void {
|
||||
// "connected" covers a charging session too, on both platforms.
|
||||
const line = formatBatteryLine(shell.getBatteryLevels(), getGlassesPresence().connected, glassesModelName());
|
||||
if (line === this._batteryLine) return;
|
||||
this._batteryLine = line;
|
||||
this.notifyPropertyChange("batteryLine", line);
|
||||
this.notifyPropertyChange("batteryLineVisibility", this.batteryLineVisibility);
|
||||
}
|
||||
}
|
||||
|
||||
function segmentClass(selected: boolean): string {
|
||||
return selected ? "segment-button segment-button-selected" : "segment-button";
|
||||
}
|
||||
@@ -768,6 +768,21 @@ export const mirrorTouchSetting = new ConfigSettingBoolean({
|
||||
"Let touches on the phone's mirror act on the glasses UI: tap selects what it lands on, double-tap goes back, a hold opens the menu, swipes navigate.",
|
||||
});
|
||||
|
||||
/** Which input device the touchpad on the phone's main screen imitates. */
|
||||
export type PhoneInputStyle = "watch" | "ring";
|
||||
|
||||
export const phoneInputStyleSetting = new ConfigSettingEnum<PhoneInputStyle>({
|
||||
id: "phone-input-style",
|
||||
label: "Phone input style",
|
||||
storageKey: "phone.inputStyle",
|
||||
defaultValue: "watch",
|
||||
values: ["watch", "ring"],
|
||||
formatValue: (value) => (value === "ring" ? "Ring" : "Watch"),
|
||||
description:
|
||||
"Which device the touchpad on the phone's main screen imitates. Watch: swipes navigate, tap selects, double-tap or two fingers goes back, a hold opens the menu. " +
|
||||
"Ring: vertical swipes scroll; tap, double-tap and hold are the ring's click, double-click and long-press.",
|
||||
});
|
||||
|
||||
// Watch remote (app/g2/wear-remote.ts, wear/, apple-watch/). All three are read on
|
||||
// every watch message, so a change applies immediately.
|
||||
export const watchRemoteEnabledSetting = new ConfigSettingBoolean({
|
||||
|
||||
@@ -65,6 +65,7 @@ import {
|
||||
openAiApiKeySetting,
|
||||
previewColorSetting,
|
||||
previewScalingSetting,
|
||||
phoneInputStyleSetting,
|
||||
phoneRotationSetting,
|
||||
ringConnectionModeSetting,
|
||||
glassesTypeSetting,
|
||||
@@ -222,6 +223,8 @@ function settingsSections(): SettingsSection[] {
|
||||
enumSettingMenuItem(previewColorSetting),
|
||||
enumSettingMenuItem(previewScalingSetting),
|
||||
toggleSettingMenuItem(mirrorTouchSetting),
|
||||
// Watch or Ring: which touchpad the main page shows under the mirror.
|
||||
enumSettingMenuItem(phoneInputStyleSetting),
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -212,15 +212,12 @@ test('iOS bandwidth footer toggles live, polls only in foreground and resets its
|
||||
'./phone-gestures': { PhoneGestureRecognizer: class { cancel() {} } },
|
||||
'./ble-bandwidth-meter': require('../.test-build/app/phone-ui/ble-bandwidth-meter.js'),
|
||||
'../native/ble-traffic': { sampleBleTraffic: () => totals },
|
||||
'../ui/dashboard-settings': { brightnessSetting: { get: () => 'auto' }, displayLayoutSetting: { displayValue: () => 'Tall' }, showBleBandwidthSetting: { get: () => enabled }, glassesModelName: () => 'G2',
|
||||
'../ui/dashboard-settings': { phoneInputStyleSetting: { get: () => 'watch' }, showBleBandwidthSetting: { get: () => enabled },
|
||||
onAnySettingChanged: fn => { settingListeners.add(fn); return () => settingListeners.delete(fn); } },
|
||||
'../g2/device-addresses': { loadDeviceAddresses: () => ({}) },
|
||||
'../g2/ios-peripheral-identity': { deviceAddressError: () => 'no test devices' },
|
||||
'./onboarding-state': { isPreviewOnlyMode: () => false },
|
||||
'../g2/reconnect-policy': { isAutoReconnectSuppressed: () => false },
|
||||
'../g2/glasses-display-state': require('../.test-build/app/g2/glasses-display-state.js'),
|
||||
'../ui/shell/shell': { shell: { onBatteryLevelsChanged: () => () => {}, getBatteryLevels: () => ({
|
||||
headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null }) } },
|
||||
};
|
||||
modules['./keyboard-input-view-model'] = load('app/phone-ui/keyboard-input-view-model.ts', { require: id => modules[id] });
|
||||
modules['./remote-controls-view-model'] = load('app/phone-ui/remote-controls-view-model.ts', { require: id => modules[id] });
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
const NO_LEVELS = { headset: null, headsetCharging: null, case: null, caseCharging: null, ring: null, ringCharging: null };
|
||||
|
||||
function fixture() {
|
||||
let brightness = '40', mode = 'small', style = 'watch', picked, levels = { ...NO_LEVELS };
|
||||
const changes = [], writes = [], back = [];
|
||||
const settingListeners = new Set(), batteryListeners = new Set();
|
||||
const subscribe = listeners => fn => { listeners.add(fn); return () => listeners.delete(fn); };
|
||||
class Observable {
|
||||
notifyPropertyChange(name, value) { changes.push([name, value]); }
|
||||
}
|
||||
const settings = {
|
||||
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
|
||||
displayLayoutSetting: { get: () => mode, set: value => { mode = value; }, values: ['small', 'large', 'huge'],
|
||||
isDisabled: value => value === 'huge', displayValue(value = mode) { return value[0].toUpperCase() + value.slice(1); } },
|
||||
phoneInputStyleSetting: { get: () => style, set: value => { style = value; } },
|
||||
glassesModelName: () => 'G2',
|
||||
onAnySettingChanged: subscribe(settingListeners),
|
||||
};
|
||||
// glasses-display-state and glasses-presence are pure, so the real ones load.
|
||||
const load = loader({}, {
|
||||
'@nativescript/core': { Observable, Dialogs: { action: async () => picked }, Frame: { topmost: () => ({ goBack: () => back.push(true) }) } },
|
||||
'../ui/dashboard-settings': settings,
|
||||
'../ui/shell/shell': { shell: { getBatteryLevels: () => levels, onBatteryLevelsChanged: subscribe(batteryListeners) } },
|
||||
});
|
||||
const { SettingsViewModel } = load('app/phone-ui/settings-view-model.ts');
|
||||
const presence = load('app/g2/glasses-presence.ts');
|
||||
return { model: new SettingsViewModel(), changes, writes, back, presence, settingListeners, batteryListeners,
|
||||
brightness: () => brightness, mode: () => mode, style: () => style, pick: value => { picked = value; },
|
||||
setLevels: next => { levels = { ...NO_LEVELS, ...next }; for (const fn of batteryListeners) fn(); },
|
||||
changeElsewhere: fn => { fn({ setBrightness: value => { brightness = value; }, setStyle: value => { style = value; } });
|
||||
for (const listener of settingListeners) listener(); } };
|
||||
}
|
||||
|
||||
test('brightness controls snap manual levels and restore the manual value after Auto', () => {
|
||||
const h = fixture();
|
||||
h.model.onBrightnessChange({ value: 76 });
|
||||
assert.equal(h.brightness(), '80');
|
||||
h.model.onBrightnessAutoChange({ value: true });
|
||||
assert.equal(h.brightness(), 'auto');
|
||||
assert.equal(h.model.brightnessSliderEnabled, false);
|
||||
h.model.onBrightnessChange({ value: 10 });
|
||||
assert.equal(h.brightness(), 'auto');
|
||||
h.model.onBrightnessAutoChange({ value: false });
|
||||
assert.equal(h.brightness(), '80');
|
||||
h.model.onBrightnessChange({ value: -10 });
|
||||
assert.equal(h.brightness(), '2');
|
||||
h.model.onBrightnessChange({ value: NaN });
|
||||
assert.equal(h.brightness(), '2');
|
||||
});
|
||||
|
||||
test('display-mode picker preserves cancellation and applies the selected mode', async () => {
|
||||
const h = fixture();
|
||||
h.pick('Cancel'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'small');
|
||||
// Unavailable modes (Full Screen beside a side strip) are not offered.
|
||||
h.pick('Huge'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'small');
|
||||
h.pick('Large'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'large');
|
||||
assert.equal(h.model.displayModeLabel, 'Large ▾');
|
||||
});
|
||||
|
||||
test('Phone input style picks the pad, marks the chosen button and explains it', () => {
|
||||
const h = fixture();
|
||||
assert.match(h.model.watchStyleClass, /segment-button-selected/);
|
||||
assert.doesNotMatch(h.model.ringStyleClass, /selected/);
|
||||
const watchHint = h.model.phoneInputStyleHint;
|
||||
h.model.onWatchStyleTap();
|
||||
assert.deepEqual(h.changes, [], 'picking the current style changes nothing');
|
||||
h.model.onRingStyleTap();
|
||||
assert.equal(h.style(), 'ring');
|
||||
assert.match(h.model.ringStyleClass, /segment-button-selected/);
|
||||
assert.doesNotMatch(h.model.watchStyleClass, /selected/);
|
||||
assert.notEqual(h.model.phoneInputStyleHint, watchHint);
|
||||
// Updated at once, without waiting for the store's own (next-tick) notification.
|
||||
assert.deepEqual(h.changes.map(change => change[0]), ['watchStyleClass', 'ringStyleClass', 'phoneInputStyleHint']);
|
||||
});
|
||||
|
||||
test('the page follows changes made on the glasses only while it is on screen', () => {
|
||||
const h = fixture();
|
||||
assert.equal(h.settingListeners.size, 0, 'nothing is subscribed before the page loads');
|
||||
h.model.attach(); h.model.attach();
|
||||
assert.equal(h.settingListeners.size, 1); assert.equal(h.batteryListeners.size, 1);
|
||||
h.changes.length = 0;
|
||||
h.changeElsewhere(remote => { remote.setBrightness('auto'); remote.setStyle('ring'); });
|
||||
const changed = Object.fromEntries(h.changes);
|
||||
assert.equal(changed.brightnessAuto, true);
|
||||
assert.equal(changed.brightnessSliderEnabled, false);
|
||||
assert.match(changed.ringStyleClass, /segment-button-selected/);
|
||||
assert.ok('displayModeLabel' in changed);
|
||||
h.model.detach();
|
||||
assert.equal(h.settingListeners.size, 0); assert.equal(h.batteryListeners.size, 0);
|
||||
// Coming back (an app resume, or returning to the page) catches up.
|
||||
h.changeElsewhere(remote => remote.setBrightness('60'));
|
||||
h.changes.length = 0; h.model.attach();
|
||||
assert.equal(Object.fromEntries(h.changes).brightnessPercent, 60);
|
||||
h.model.detach();
|
||||
});
|
||||
|
||||
test('the battery row hides until a level is known and marks charging only over a live link', () => {
|
||||
const h = fixture();
|
||||
h.model.attach();
|
||||
assert.equal(h.model.batteryLineVisibility, 'collapse');
|
||||
h.setLevels({ headset: 90, headsetCharging: true, ring: 72 });
|
||||
assert.equal(h.model.batteryLine, 'G2 90% · R1 72%');
|
||||
assert.equal(h.model.batteryLineVisibility, 'visible');
|
||||
h.changes.length = 0;
|
||||
h.presence.updateGlassesPresence({ connected: true });
|
||||
assert.equal(h.model.batteryLine, 'G2 90% ⚡ · R1 72%');
|
||||
assert.deepEqual(h.changes.map(change => change[0]), ['batteryLine', 'batteryLineVisibility']);
|
||||
h.model.detach();
|
||||
h.presence.updateGlassesPresence({ connected: false });
|
||||
assert.equal(h.model.batteryLine, 'G2 90% ⚡ · R1 72%', 'a detached page is not updated');
|
||||
h.model.attach();
|
||||
assert.equal(h.model.batteryLine, 'G2 90% · R1 72%');
|
||||
h.model.detach();
|
||||
});
|
||||
|
||||
test('the back arrow pops the settings page', () => {
|
||||
const h = fixture();
|
||||
h.model.onBackTap();
|
||||
assert.deepEqual(h.back, [true]);
|
||||
});
|
||||
|
||||
test('the settings page binds every row the view model serves and is registered for iOS', () => {
|
||||
const fs = require('node:fs'), path = require('node:path');
|
||||
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
||||
const xml = read('app/phone-ui/settings-page.xml');
|
||||
for (const binding of ['displayModeLabel', 'onDisplayModeTap', 'brightnessAuto', 'onBrightnessAutoChange', 'brightnessPercent',
|
||||
'onBrightnessChange', 'brightnessSliderEnabled', 'watchStyleClass', 'ringStyleClass', 'onWatchStyleTap', 'onRingStyleTap',
|
||||
'phoneInputStyleHint', 'batteryLine', 'batteryLineVisibility', 'onBackTap']) {
|
||||
assert.ok(xml.includes(`{{ ${binding} }}`), `settings-page.xml binds ${binding}`);
|
||||
}
|
||||
// iOS skips webpack's automatic page discovery, and loads app.ios.css instead of app.css.
|
||||
const register = read('app/phone-ui/onboarding-register.ios.ts');
|
||||
assert.match(register, /registerModule\('phone-ui\/settings-page', /);
|
||||
assert.match(register, /registerModule\('phone-ui\/settings-page\.xml', /);
|
||||
for (const css of ['app/app.css', 'app/app.ios.css']) assert.match(read(css), /@import '\.\/phone-ui\/settings-page\.css';/);
|
||||
});
|
||||
|
||||
test('Phone input style is a stored setting, Watch by default, also offered in the glasses Settings app', () => {
|
||||
const fs = require('node:fs'), path = require('node:path'), vm = require('node:vm'), ts = require('typescript');
|
||||
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
||||
// The real setting object, over an in-memory settings store.
|
||||
const store = new Map(), sandbox = { exports: {}, global: { isIOS: false }, setTimeout: fn => fn(),
|
||||
require: id => id.includes('settings-store') ? { onSettingsStoreChanged() {},
|
||||
getStringSetting: (key, fallback) => store.get(key) ?? fallback, setStringSetting: (key, value) => store.set(key, value),
|
||||
getBooleanSetting: (key, fallback) => store.get(key) ?? fallback, setBooleanSetting: (key, value) => store.set(key, value) }
|
||||
: { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] } };
|
||||
vm.runInNewContext(ts.transpileModule(read('app/ui/dashboard-settings.ts'),
|
||||
{ compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 } }).outputText, sandbox);
|
||||
const setting = sandbox.exports.phoneInputStyleSetting;
|
||||
assert.equal(setting.label, 'Phone input style');
|
||||
assert.equal(setting.get(), 'watch');
|
||||
assert.deepEqual([...setting.values].map(value => setting.displayValue(value)), ['Watch', 'Ring']);
|
||||
setting.set('ring');
|
||||
assert.equal(store.get('phone.inputStyle'), 'ring');
|
||||
assert.equal(setting.get(), 'ring');
|
||||
store.set('phone.inputStyle', 'settings');
|
||||
assert.equal(setting.get(), 'watch', 'an unknown stored value reads as the default');
|
||||
|
||||
// The on-glasses Settings app lists it with the other phone-screen settings.
|
||||
const menus = read('app/ui/dashboard/settings-menus.ts');
|
||||
const section = menus.slice(menus.indexOf('label: "Phone display"'), menus.indexOf('label: "Watch"'));
|
||||
assert.match(section, /enumSettingMenuItem\(phoneInputStyleSetting\)/);
|
||||
});
|
||||
@@ -3,62 +3,78 @@ const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
function fixture() {
|
||||
let brightness = '40', mode = 'small', picked;
|
||||
const changes = [], writes = [];
|
||||
let style = 'watch';
|
||||
const changes = [], navigations = [];
|
||||
class Observable {
|
||||
notifyPropertyChange(name, value) { changes.push([name, value]); }
|
||||
}
|
||||
const settings = {
|
||||
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
|
||||
displayLayoutSetting: { get: () => mode, set: value => { mode = value; }, values: ['small', 'large', 'huge'],
|
||||
isDisabled: value => value === 'huge', displayValue(value = mode) { return value[0].toUpperCase() + value.slice(1); } },
|
||||
};
|
||||
const { RemoteControlsViewModel } = loader({}, {
|
||||
'@nativescript/core': { Observable, Dialogs: { action: async () => picked } },
|
||||
'../ui/dashboard-settings': settings,
|
||||
'@nativescript/core': { Observable, Frame: { topmost: () => ({ navigate: entry => navigations.push(entry) }) } },
|
||||
'../ui/dashboard-settings': { phoneInputStyleSetting: { get: () => style } },
|
||||
})('app/phone-ui/remote-controls-view-model.ts');
|
||||
return { model: new RemoteControlsViewModel(), create: () => new RemoteControlsViewModel(), changes, writes,
|
||||
brightness: () => brightness, mode: () => mode, pick: value => { picked = value; } };
|
||||
return { model: new RemoteControlsViewModel(), create: () => new RemoteControlsViewModel(), changes, navigations,
|
||||
setStyle: value => { style = value; } };
|
||||
}
|
||||
|
||||
test('shared controls preserve the selected tab across page visits and update all tab bindings', () => {
|
||||
test('the touchpad follows the Phone input style setting and only notifies when it changes', () => {
|
||||
const h = fixture();
|
||||
assert.equal(h.model.watchTabVisibility, 'visible');
|
||||
h.model.onRingTabTap();
|
||||
assert.equal(h.model.watchTabVisibility, 'collapse');
|
||||
assert.equal(h.model.ringTabVisibility, 'visible');
|
||||
assert.match(h.model.ringTabClass, /tab-button-selected/);
|
||||
assert.equal(h.changes.length, 6);
|
||||
assert.equal(h.create().ringTabVisibility, 'visible');
|
||||
h.model.onSettingsTabTap();
|
||||
assert.equal(h.model.settingsTabVisibility, 'visible');
|
||||
assert.equal(h.model.watchPadVisibility, 'visible');
|
||||
assert.equal(h.model.ringPadVisibility, 'collapse');
|
||||
// Some other setting changed: nothing to redraw, no gesture to cancel.
|
||||
h.model.refreshInputStyle();
|
||||
assert.deepEqual(h.changes, []);
|
||||
h.setStyle('ring'); h.model.refreshInputStyle();
|
||||
assert.equal(h.model.watchPadVisibility, 'collapse');
|
||||
assert.equal(h.model.ringPadVisibility, 'visible');
|
||||
assert.deepEqual(h.changes, [['watchPadVisibility', 'collapse'], ['ringPadVisibility', 'visible']]);
|
||||
// A page built later starts on the stored style.
|
||||
assert.equal(h.create().ringPadVisibility, 'visible');
|
||||
});
|
||||
|
||||
test('shared brightness controls snap manual levels and restore the manual value after Auto', () => {
|
||||
const h = fixture();
|
||||
h.model.onBrightnessChange({ value: 76 });
|
||||
assert.equal(h.brightness(), '80');
|
||||
h.model.onBrightnessAutoChange({ value: true });
|
||||
assert.equal(h.brightness(), 'auto');
|
||||
assert.equal(h.model.brightnessSliderEnabled, false);
|
||||
h.model.onBrightnessChange({ value: 10 });
|
||||
assert.equal(h.brightness(), 'auto');
|
||||
h.model.onBrightnessAutoChange({ value: false });
|
||||
assert.equal(h.brightness(), '80');
|
||||
h.model.onBrightnessChange({ value: -10 });
|
||||
assert.equal(h.brightness(), '2');
|
||||
h.model.onBrightnessChange({ value: NaN });
|
||||
assert.equal(h.brightness(), '2');
|
||||
test('the EvenHub phone-UI button shows only with an icon and opens that app through the host', () => {
|
||||
const h = fixture(), opened = [], icon = { id: 'icon' };
|
||||
h.model.showEvenHubPhoneUi = windowId => opened.push(windowId);
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon: null };
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
assert.deepEqual(opened, [], 'a hidden button opens nothing');
|
||||
|
||||
h.changes.length = 0;
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon };
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'visible');
|
||||
assert.equal(h.model.evenHubPhoneUiIcon, icon);
|
||||
assert.equal(h.model.evenHubPhoneUiLabel, 'Open Chess on phone');
|
||||
assert.deepEqual(h.changes.map(change => change[0]), ['evenHubPhoneUiIcon', 'evenHubPhoneUiVisibility', 'evenHubPhoneUiLabel']);
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
assert.deepEqual(opened, ['w1']);
|
||||
|
||||
// The host pushes a fresh object on every snapshot; an equal one is not a change.
|
||||
h.changes.length = 0;
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon };
|
||||
assert.deepEqual(h.changes, []);
|
||||
h.model.evenHubPhoneUi = null;
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
assert.equal(h.model.evenHubPhoneUiLabel, '');
|
||||
});
|
||||
|
||||
test('shared display-mode picker preserves cancellation and applies the selected mode', async () => {
|
||||
test('the gear button opens the settings page', () => {
|
||||
const h = fixture();
|
||||
h.pick('Cancel'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'small');
|
||||
// Unavailable modes (Full Screen beside a side strip) are not offered.
|
||||
h.pick('Huge'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'small');
|
||||
h.pick('Large'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'large');
|
||||
assert.equal(h.model.displayModeLabel, 'Large ▾');
|
||||
h.model.onSettingsTap();
|
||||
// The entry is built in the module's own realm, so compare its field.
|
||||
assert.deepEqual(h.navigations.map(entry => entry.moduleName), ['phone-ui/settings-page']);
|
||||
});
|
||||
|
||||
test('the control bar keeps the EvenHub button leftmost and the pads bound to the input style', () => {
|
||||
const xml = require('node:fs').readFileSync(require('node:path').join(__dirname, '../app/phone-ui/remote-controls.xml'), 'utf8');
|
||||
const bar = xml.slice(xml.indexOf('class="control-bar"'), xml.indexOf('onControlsContentLayoutChanged'));
|
||||
const order = ['onEvenHubPhoneUiTap', 'onSyntheticMicTap', 'onKeyboardTap', 'onSettingsTap'].map(name => bar.indexOf(name));
|
||||
assert.ok(order.every(index => index >= 0), 'all four buttons are in the bar');
|
||||
assert.deepEqual(order, [...order].sort((a, b) => a - b));
|
||||
// A leading star column takes the slack, so the app button's coming and going moves no other button.
|
||||
assert.match(xml, /columns="\*,auto,auto,auto,auto"[^>]*class="control-bar"/);
|
||||
assert.match(xml, /visibility="\{\{ watchPadVisibility \}\}"/);
|
||||
assert.match(xml, /visibility="\{\{ ringPadVisibility \}\}"/);
|
||||
assert.doesNotMatch(xml, /TabVisibility|TabClass|TabTap/);
|
||||
});
|
||||
Reference in new issue
Block a user