diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 4f3f1712..c1bee7a3 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -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 { 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 { diff --git a/app/phone-ui/main-page.ts b/app/phone-ui/main-page.ts index 5429381e..2e761f31 100644 --- a/app/phone-ui/main-page.ts +++ b/app/phone-ui/main-page.ts @@ -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('logScrollView'), - page.getViewById('logScrollViewLandscape'), - ].filter((scrollView): scrollView is ScrollView => !!scrollView) const settingsTextField = page.getViewById('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) } diff --git a/app/phone-ui/main-page.xml b/app/phone-ui/main-page.xml index 21274065..ec7ffe68 100644 --- a/app/phone-ui/main-page.xml +++ b/app/phone-ui/main-page.xml @@ -1,12 +1,11 @@ - + - @@ -21,7 +20,7 @@ visibility="{{ displayPreviewMessageVisibility }}"> - +