forked from Blendman974/faceclaw
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
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user