forked from Blendman974/faceclaw
Main-form "Disconnect" option is available if in a reconnection-attempt loop. Remove broken/unused "Show Logs" button.
This commit is contained in:
1 parent
fa241161e4
commit
1a1416c8f0
4 files changed
+28
-122
No files matched your search
@@ -49,7 +49,6 @@ type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging"
|
||||
export type DashboardSnapshot = {
|
||||
phase: ConnectionPhase;
|
||||
status: string;
|
||||
log: string;
|
||||
displayPreview: ImageSource | null;
|
||||
/**
|
||||
* When non-empty, the phone UI shows this instead of the display preview:
|
||||
@@ -148,7 +147,6 @@ function sourceName(eventSource: number): string {
|
||||
class DashboardController {
|
||||
private phase: ConnectionPhase = "disconnected";
|
||||
private status = "Disconnected.";
|
||||
private log = "";
|
||||
private activeTextSettings: ConfigSettingString[] = [];
|
||||
private activeTextEditorTitle = "";
|
||||
private activeTextEditorOnFinish: (() => void) | null = null;
|
||||
@@ -720,7 +718,6 @@ class DashboardController {
|
||||
return {
|
||||
phase: this.phase,
|
||||
status: this.status,
|
||||
log: this.log,
|
||||
displayPreview: this.displayPreview,
|
||||
displayPreviewMessage: this.displayPreviewMessage(),
|
||||
activeTextSettingId: primaryTextSetting?.id ?? null,
|
||||
@@ -839,7 +836,6 @@ class DashboardController {
|
||||
this.appendLog(`error: ${message}`);
|
||||
throw new Error(message);
|
||||
}
|
||||
this.log = "";
|
||||
this.lastInput = "waiting...";
|
||||
this.lastSys = "none yet";
|
||||
this.welcomeSoundArmed = isWelcomeSoundPending();
|
||||
@@ -1147,6 +1143,14 @@ class DashboardController {
|
||||
*/
|
||||
async disconnect(options?: { skipFirmwareCleanup?: boolean }): Promise<void> {
|
||||
suppressAutoReconnect();
|
||||
// The phone menu offers Disconnect during the connecting phase (it is the
|
||||
// only way out of a reconnection-attempt loop), so a call can land while
|
||||
// connect() is still mid-flight; let it finish so the teardown doesn't
|
||||
// race its surface setup. connect() returns once the Java worker thread
|
||||
// owns the retry loop, so this wait is short.
|
||||
while (this.connectRunning) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
}
|
||||
if (this.phase === "disconnected" || this.phase === "disconnecting") return;
|
||||
|
||||
this.setPhase("disconnecting");
|
||||
@@ -1886,10 +1890,7 @@ class DashboardController {
|
||||
}
|
||||
|
||||
private appendLog(line: string): void {
|
||||
const stamped = `[${formatTimestamp(new Date())}] ${line}`;
|
||||
//this.log = this.log ? `${this.log}\n${stamped}` : stamped;
|
||||
console.log(stamped);
|
||||
//this.emit();
|
||||
console.log(`[${formatTimestamp(new Date())}] ${line}`);
|
||||
}
|
||||
|
||||
private setDisplayPreview(preview: ImageSource | null): void {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Application, Color, EventData, isAndroid, Observable, Page, ScrollView, TextField } from '@nativescript/core'
|
||||
import { Application, Color, EventData, isAndroid, Observable, Page, TextField } from '@nativescript/core'
|
||||
import { MainViewModel } from './main-view-model'
|
||||
import { dashboardController } from '../g2/dashboard-controller'
|
||||
|
||||
@@ -13,9 +13,6 @@ export function navigatingTo(args: EventData) {
|
||||
|
||||
type MainPageState = {
|
||||
model: MainViewModel
|
||||
isPinnedToBottom: boolean
|
||||
scrollViews: ScrollView[]
|
||||
scrollHandler: (args: EventData) => void
|
||||
propertyChangeHandler: (args: EventData & { propertyName?: string }) => void
|
||||
orientationHandler: () => void
|
||||
}
|
||||
@@ -34,30 +31,11 @@ function cleanupPage(page: Page): void {
|
||||
setPageState(page, undefined)
|
||||
return
|
||||
}
|
||||
for (const scrollView of state.scrollViews) {
|
||||
scrollView.off(ScrollView.scrollEvent, state.scrollHandler)
|
||||
}
|
||||
state.model.off(Observable.propertyChangeEvent, state.propertyChangeHandler)
|
||||
Application.off(Application.orientationChangedEvent, state.orientationHandler)
|
||||
setPageState(page, undefined)
|
||||
}
|
||||
|
||||
function isAtBottom(scrollView: ScrollView): boolean {
|
||||
return scrollView.scrollableHeight <= 0 || scrollView.verticalOffset >= scrollView.scrollableHeight - 8
|
||||
}
|
||||
|
||||
function scrollToBottom(scrollView: ScrollView): void {
|
||||
setTimeout(() => {
|
||||
scrollView.scrollToVerticalOffset(scrollView.scrollableHeight, false)
|
||||
}, 0)
|
||||
}
|
||||
|
||||
function scrollLogsToBottom(scrollViews: ScrollView[]): void {
|
||||
for (const scrollView of scrollViews) {
|
||||
scrollToBottom(scrollView)
|
||||
}
|
||||
}
|
||||
|
||||
function applySettingsTextFieldContrast(textField: TextField): void {
|
||||
textField.color = SETTINGS_TEXT_COLOR
|
||||
textField.backgroundColor = SETTINGS_BACKGROUND_COLOR
|
||||
@@ -105,64 +83,34 @@ export function loaded(args: EventData) {
|
||||
// Reopen the apps that were open before the last restart (no-op after the
|
||||
// first load).
|
||||
void dashboardController.restoreOpenApps()
|
||||
const scrollViews = [
|
||||
page.getViewById<ScrollView>('logScrollView'),
|
||||
page.getViewById<ScrollView>('logScrollViewLandscape'),
|
||||
].filter((scrollView): scrollView is ScrollView => !!scrollView)
|
||||
const settingsTextField = page.getViewById<TextField>('settingsTextField')
|
||||
model?.refreshLayoutMetrics()
|
||||
if (settingsTextField) {
|
||||
applySettingsTextFieldContrast(settingsTextField)
|
||||
}
|
||||
if (!model || scrollViews.length === 0) {
|
||||
if (!model) {
|
||||
return
|
||||
}
|
||||
|
||||
const state: MainPageState = {
|
||||
model,
|
||||
isPinnedToBottom: true,
|
||||
scrollViews,
|
||||
scrollHandler: (scrollArgs) => {
|
||||
state.isPinnedToBottom = isAtBottom(scrollArgs.object as ScrollView)
|
||||
},
|
||||
orientationHandler: () => {
|
||||
setTimeout(() => {
|
||||
model.refreshLayoutMetrics()
|
||||
if (state.isPinnedToBottom) {
|
||||
scrollLogsToBottom(scrollViews)
|
||||
}
|
||||
}, 0)
|
||||
},
|
||||
propertyChangeHandler: (propertyArgs) => {
|
||||
if (propertyArgs.propertyName === 'showLog') {
|
||||
if (model.showLog) {
|
||||
state.isPinnedToBottom = true
|
||||
scrollLogsToBottom(scrollViews)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (propertyArgs.propertyName === 'activeTextSettingId') {
|
||||
if (model.isTextSettingEditorActive) {
|
||||
focusTextEditor(page)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (propertyArgs.propertyName !== 'log') {
|
||||
return
|
||||
}
|
||||
if (state.isPinnedToBottom) {
|
||||
scrollLogsToBottom(scrollViews)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
for (const scrollView of scrollViews) {
|
||||
scrollView.on(ScrollView.scrollEvent, state.scrollHandler)
|
||||
}
|
||||
model.on(Observable.propertyChangeEvent, state.propertyChangeHandler)
|
||||
Application.on(Application.orientationChangedEvent, state.orientationHandler)
|
||||
setPageState(page, state)
|
||||
scrollLogsToBottom(scrollViews)
|
||||
if (model.isTextSettingEditorActive) {
|
||||
focusTextEditor(page)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" loaded="loaded" unloaded="unloaded">
|
||||
<ActionBar title="Faceclaw">
|
||||
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ connectItemEnabled }}" android.position="popup" />
|
||||
<ActionItem text="Pair glasses" tap="{{ onPairGlassesTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||
<ActionItem text="Configure devices" tap="{{ onConfigureTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||
<ActionItem text="Take screenshot" tap="{{ onTakeScreenshotTap }}" android.position="popup" />
|
||||
<ActionItem text="Record screen" tap="{{ onRecordScreenTap }}" android.position="popup" />
|
||||
<ActionItem text="Uninstall custom firmware" tap="{{ onUninstallFirmwareTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||
<ActionItem text="{{ showLogMenuLabel }}" tap="{{ onToggleLogTap }}" android.position="popup" />
|
||||
</ActionBar>
|
||||
|
||||
<GridLayout>
|
||||
@@ -21,7 +20,7 @@
|
||||
visibility="{{ displayPreviewMessageVisibility }}">
|
||||
<Label text="{{ displayPreviewMessage }}" textWrap="true" horizontalAlignment="center" verticalAlignment="center" />
|
||||
</GridLayout>
|
||||
<GridLayout row="1" rows="auto,auto,auto,*" class="p-20">
|
||||
<GridLayout row="1" rows="auto,auto,auto" class="p-20">
|
||||
<StackLayout row="0" class="m-b-8">
|
||||
<StackLayout visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
@@ -48,9 +47,6 @@
|
||||
<Button text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
||||
</StackLayout>
|
||||
<Label row="2" text="{{ status }}" class="m-t-16" textWrap="true" />
|
||||
<ScrollView id="logScrollView" row="3" class="m-t-16" visibility="{{ showLogVisibility }}">
|
||||
<Label text="{{ log }}" textWrap="true" verticalAlignment="top" />
|
||||
</ScrollView>
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
|
||||
@@ -66,7 +62,7 @@
|
||||
<Button text="Allow unrestricted background usage" tap="{{ onAllowBackgroundUsageTap }}" class="-primary" />
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
<GridLayout row="1" rows="auto,auto,*" columns="*,260">
|
||||
<GridLayout row="1" rows="auto,auto" columns="*,260">
|
||||
<StackLayout row="0" col="0" visibility="{{ displayPreviewVisibility }}" horizontalAlignment="left">
|
||||
<Image
|
||||
src="{{ displayPreview }}"
|
||||
@@ -96,9 +92,6 @@
|
||||
<Button text="Stop recording" tap="{{ onStopRecordingTap }}" visibility="{{ stopRecordingButtonVisibility }}" />
|
||||
</StackLayout>
|
||||
<Label row="1" col="0" colSpan="2" text="{{ status }}" class="m-t-16" textWrap="true" />
|
||||
<ScrollView id="logScrollViewLandscape" row="2" col="0" colSpan="2" class="m-t-16" visibility="{{ showLogVisibility }}">
|
||||
<Label text="{{ log }}" textWrap="true" verticalAlignment="top" />
|
||||
</ScrollView>
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
<StackLayout
|
||||
|
||||
@@ -10,7 +10,6 @@ type LayoutOrientation = "portrait" | "landscape";
|
||||
|
||||
export class MainViewModel extends Observable {
|
||||
private _status = "Disconnected.";
|
||||
private _log = "";
|
||||
private _displayPreview: ImageSource | null = null;
|
||||
private _displayPreviewMessage = "";
|
||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||
@@ -29,14 +28,12 @@ export class MainViewModel extends Observable {
|
||||
private _firmwareWarningVisible = false;
|
||||
private _screenRecordingActive = false;
|
||||
private _batteryOptimizationWarningVisible = false;
|
||||
private _showLog = false;
|
||||
private _phase: "disconnected" | "connecting" | "connected" | "charging" | "disconnecting" = "disconnected";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
dashboardController.subscribe((snapshot) => {
|
||||
this.status = snapshot.status;
|
||||
this.log = snapshot.log;
|
||||
this.displayPreview = snapshot.displayPreview;
|
||||
this.displayPreviewMessage = snapshot.displayPreviewMessage;
|
||||
this.phase = snapshot.phase;
|
||||
@@ -69,17 +66,6 @@ export class MainViewModel extends Observable {
|
||||
}
|
||||
}
|
||||
|
||||
get log(): string {
|
||||
return this._log;
|
||||
}
|
||||
|
||||
set log(value: string) {
|
||||
if (this._log !== value) {
|
||||
this._log = value;
|
||||
this.notifyPropertyChange("log", value);
|
||||
}
|
||||
}
|
||||
|
||||
get displayPreview(): ImageSource | null {
|
||||
return this._displayPreview;
|
||||
}
|
||||
@@ -160,27 +146,6 @@ export class MainViewModel extends Observable {
|
||||
this.notifyPropertyChange("landscapeDisplayPreviewHeight", this.landscapeDisplayPreviewHeight);
|
||||
}
|
||||
|
||||
get showLog(): boolean {
|
||||
return this._showLog;
|
||||
}
|
||||
|
||||
set showLog(value: boolean) {
|
||||
if (this._showLog !== value) {
|
||||
this._showLog = value;
|
||||
this.notifyPropertyChange("showLog", value);
|
||||
this.notifyPropertyChange("showLogVisibility", this.showLogVisibility);
|
||||
this.notifyPropertyChange("showLogMenuLabel", this.showLogMenuLabel);
|
||||
}
|
||||
}
|
||||
|
||||
get showLogVisibility(): "visible" | "collapse" {
|
||||
return this._showLog ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get showLogMenuLabel(): string {
|
||||
return this._showLog ? "Hide Log" : "Show Log";
|
||||
}
|
||||
|
||||
get activeTextSettingId(): string | null {
|
||||
return this._activeTextSettingId;
|
||||
}
|
||||
@@ -447,13 +412,13 @@ export class MainViewModel extends Observable {
|
||||
this.notifyPropertyChange("phase", value);
|
||||
this.notifyPropertyChange("buttonLabel", this.buttonLabel);
|
||||
this.notifyPropertyChange("canRun", this.canRun);
|
||||
this.notifyPropertyChange("connectItemEnabled", this.connectItemEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
get buttonLabel(): string {
|
||||
switch (this.phase) {
|
||||
case "connecting":
|
||||
return "Connecting...";
|
||||
case "connected":
|
||||
case "charging":
|
||||
return "Disconnect";
|
||||
@@ -468,20 +433,28 @@ export class MainViewModel extends Observable {
|
||||
return this.phase !== "connecting" && this.phase !== "disconnecting";
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlike the other canRun-gated menu items, Connect/Disconnect stays live
|
||||
* while connecting: Disconnect is the only way out of a reconnection-attempt
|
||||
* loop short of force-stopping the app.
|
||||
*/
|
||||
get connectItemEnabled(): boolean {
|
||||
return this.phase !== "disconnecting";
|
||||
}
|
||||
|
||||
async onTap(): Promise<void> {
|
||||
if (!this.canRun) return;
|
||||
if (!this.connectItemEnabled) return;
|
||||
|
||||
try {
|
||||
if (this.phase === "connected" || this.phase === "charging") {
|
||||
await dashboardController.disconnect();
|
||||
} else {
|
||||
if (this.phase === "disconnected") {
|
||||
await dashboardController.connect();
|
||||
} else {
|
||||
await dashboardController.disconnect();
|
||||
}
|
||||
} catch (error) {
|
||||
const message = this.formatError(error);
|
||||
if (!this.status.startsWith("Failed:")) {
|
||||
this.status = `Failed: ${message}`;
|
||||
this.appendLog(`error: ${message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -550,10 +523,6 @@ export class MainViewModel extends Observable {
|
||||
});
|
||||
}
|
||||
|
||||
onToggleLogTap(): void {
|
||||
this.showLog = !this.showLog;
|
||||
}
|
||||
|
||||
onTextSettingTextChange(args: { value?: string; object?: { text?: string } }): void {
|
||||
dashboardController.setActiveTextSettingValue(
|
||||
args.object?.text ?? args.value ?? "",
|
||||
@@ -618,11 +587,6 @@ export class MainViewModel extends Observable {
|
||||
await dashboardController.injectSyntheticRingInput("wakeword");
|
||||
}
|
||||
|
||||
private appendLog(line: string): void {
|
||||
const stamp = new Date().toISOString().slice(11, 19);
|
||||
this.log = this.log ? `${this.log}\n[${stamp}] ${line}` : `[${stamp}] ${line}`;
|
||||
}
|
||||
|
||||
private readLayoutOrientation(): LayoutOrientation {
|
||||
const applicationOrientation = Application.orientation();
|
||||
if (applicationOrientation === "landscape" || applicationOrientation === "portrait") {
|
||||
|
||||
Reference in new issue
Block a user