diff --git a/CHANGELOG.md b/CHANGELOG.md index 922cfb99..64898646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Fixed + +- **The socket "Connection timeout" setting is now used.** It had a field, validation and persistence, but the main process always waited a fixed 2 s; `socket:connect` now carries the configured value. + ## [5.19.0] - 2026-09-06 ### Added diff --git a/README.md b/README.md index ca26e33f..00c3c096 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ ninjaterm/ ├── firmware-test-apps/ # Contains firmware test applications (Arduino sketches and a Zephyr RTT test app) used for exercising NinjaTerm against real hardware. ├── docs/ # Contains Docusaurus website which contains the homepage, installation guide and manual. Self-contained node project. ├── src/ # Contains the Electron application code. -├── tests/ # Contains the end-to-end tests using Playwright. +├── e2e-tests/ # Contains the end-to-end tests using Playwright. ├── web/ # Contains the web-based version of NinjaTerm. Self-contained node project. ``` @@ -91,7 +91,7 @@ npx vitest run ### E2E Tests -End-to-end (E2E) (a.k.a. integration tests) are performed using [Playwright](https://playwright.dev/). The Playwright tests are located in the `tests/` directory, and the Playwright config is at `playwright.config.ts`. +End-to-end (E2E) (a.k.a. integration tests) are performed using [Playwright](https://playwright.dev/). The Playwright tests are located in the `e2e-tests/` directory, and the Playwright config is at `playwright.config.ts`. To run just the E2E tests from command line: diff --git a/TODO.md b/TODO.md index bce4592f..2e92f0a6 100644 --- a/TODO.md +++ b/TODO.md @@ -51,7 +51,7 @@ Follow-on work identified while doing it: commented out. Worth confirming they can go.
-Original analysis (kept for context) +Original analysis (kept for context; its checkboxes are historical, see the status above) ## 1. Terminal data model — the throughput ceiling [perf] @@ -184,14 +184,15 @@ the observability and the undo/subtree-replacement case. Found on the way: -- [ ] **`socketConnTimeoutMs` is a dead setting.** It has a UI field, validation - and persistence, and nothing reads it — the socket connect never passes a - timeout. Either wire it into `socket:connect` or remove it (needs a - migration + UI change, so not done here). -- [ ] **`RxSettingsView` reaches `displaySettings` via - `rxSettings.profileManager.app.settings.displaySettings`** (5 sites) to get - tooltip config. It has `app` in scope; use it. `profileManager` was kept - public on the settings classes only so this didn't break. +- [x] **`socketConnTimeoutMs` was a dead setting.** (done 2026-09-07) It had a + UI field, validation and persistence, and nothing read it; `socket:connect` + now takes `connTimeoutMs` and the main process uses it instead of a fixed + 2 s. +- [x] **`RxSettingsView` reached `displaySettings` via + `rxSettings.profileManager.app.settings.displaySettings`** (done 2026-09-07) + — it and `TxSettingsView` now take `displaySettings` as a prop, and the + `profileManager` getters that existed only for this are gone from the + settings classes. - [x] Seven direct writes to `rxSettings.ansiEscapeCodeParsingEnabled` in `FakePortsController` bypassed the setter and never persisted. Caught by the getter-based façade at compile time; fixed. @@ -204,7 +205,7 @@ Found on the way: equivalent is the natural follow-up.
-Original analysis (kept for context) +Original analysis (kept for context; its checkboxes are historical, see the status above) ## 3. Six settings classes hand-rolling identical load/save plumbing [arch] diff --git a/src/main/socketService.ts b/src/main/socketService.ts index a2f9bcf1..b2661ec0 100644 --- a/src/main/socketService.ts +++ b/src/main/socketService.ts @@ -6,7 +6,11 @@ const RX_DATA_BATCH_TIMEOUT_MS = 50; /** * How long to wait for a socket to connect before timing out. */ -const SOCKET_CONNECT_TIMEOUT_MS = 2 * 1000; +/** + * Connect timeout used when the renderer does not send one. The renderer + * always does (it is the "Connection timeout" setting); this is a fallback. + */ +const DEFAULT_SOCKET_CONNECT_TIMEOUT_MS = 2 * 1000; /** * Stores a mapping of socket connection identifier to the socket object for all currently open socket connections. @@ -39,9 +43,10 @@ function sendBatchedData(connectionId: string, mainWindow: BrowserWindow | null) * @param mainWindow The main window of the application. */ export function initializeSocketHandlers(mainWindow: BrowserWindow) { - ipcMain.handle('socket:connect', async (event, options: { host: string; port: number }) => { + ipcMain.handle('socket:connect', async (event, options: { host: string; port: number; connTimeoutMs?: number }) => { console.log('socket:connect called. options: ', options); const connectionId = `${options.host}:${options.port}`; + const connTimeoutMs = options.connTimeoutMs ?? DEFAULT_SOCKET_CONNECT_TIMEOUT_MS; let socket: net.Socket | undefined; try { @@ -50,7 +55,7 @@ export function initializeSocketHandlers(mainWindow: BrowserWindow) { } socket = new net.Socket(); - socket.setTimeout(SOCKET_CONNECT_TIMEOUT_MS); + socket.setTimeout(connTimeoutMs); // One problem with sockets is that if you just pull out the ethernet cable after the connection is established, // nothing will detect it is broken. @@ -84,9 +89,9 @@ export function initializeSocketHandlers(mainWindow: BrowserWindow) { if (!socketRef.destroyed) { socketRef.destroy(); } - reject(new Error(`Timeout while connecting to socket ${connectionId}. Waited for ${SOCKET_CONNECT_TIMEOUT_MS / 1000} s.`)); + reject(new Error(`Timeout while connecting to socket ${connectionId}. Waited for ${connTimeoutMs / 1000} s.`)); } - }, SOCKET_CONNECT_TIMEOUT_MS); + }, connTimeoutMs); socketRef.on('connect', () => { if (!settled) { diff --git a/src/preload/index.ts b/src/preload/index.ts index ff6dff0f..90398284 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -147,7 +147,7 @@ contextBridge.exposeInMainWorld('electronAPI', { // Socket operations socket: { - connect: (options: { host: string; port: number }) => ipcRenderer.invoke('socket:connect', options), + connect: (options: { host: string; port: number; connTimeoutMs?: number }) => ipcRenderer.invoke('socket:connect', options), disconnect: (connectionId: string) => ipcRenderer.invoke('socket:disconnect', connectionId), writeData: (connectionId: string, data: Uint8Array) => ipcRenderer.invoke('socket:write-data', connectionId, data), @@ -278,7 +278,7 @@ export interface ElectronAPI { isOpen(): Promise<{ success: boolean; isOpen?: boolean; error?: string }>; }; socket: { - connect(options: { host: string; port: number }): Promise<{ success: boolean; connectionId?: string; error?: string }>; + connect(options: { host: string; port: number; connTimeoutMs?: number }): Promise<{ success: boolean; connectionId?: string; error?: string }>; disconnect(connectionId: string): Promise<{ success: boolean; error?: string }>; writeData(connectionId: string, data: Uint8Array): Promise<{ success: boolean; error?: string }>; onDataReceived(callback: (connectionId: string, data: Buffer) => void): Disposer; diff --git a/src/renderer/src/model/ConnController/ConnController.characterisation.spec.ts b/src/renderer/src/model/ConnController/ConnController.characterisation.spec.ts index fe0b8f61..6ab962db 100644 --- a/src/renderer/src/model/ConnController/ConnController.characterisation.spec.ts +++ b/src/renderer/src/model/ConnController/ConnController.characterisation.spec.ts @@ -222,6 +222,7 @@ describe('ConnController connection lifecycle', () => { expect(window.electronAPI.socket.connect).toHaveBeenCalledWith({ host: '192.168.1.5', port: 1234, + connTimeoutMs: 2000, }); expect(conn.connState).toBe(ConnState.OPENED); }); diff --git a/src/renderer/src/model/ConnController/Transports/SocketTransport.ts b/src/renderer/src/model/ConnController/Transports/SocketTransport.ts index 3d27b80d..adabd45b 100644 --- a/src/renderer/src/model/ConnController/Transports/SocketTransport.ts +++ b/src/renderer/src/model/ConnController/Transports/SocketTransport.ts @@ -51,6 +51,7 @@ export class SocketTransport implements Transport { const target = this.connectedTo ?? { host: this.session.settings.portConfiguration.socketHost, port: this.session.settings.portConfiguration.socketPort, + connTimeoutMs: this.session.settings.portConfiguration.socketConnTimeoutMs.appliedValue, }; try { diff --git a/src/renderer/src/model/Settings/DisplaySettings/DisplaySettings.ts b/src/renderer/src/model/Settings/DisplaySettings/DisplaySettings.ts index d5f04b3e..e74cd001 100644 --- a/src/renderer/src/model/Settings/DisplaySettings/DisplaySettings.ts +++ b/src/renderer/src/model/Settings/DisplaySettings/DisplaySettings.ts @@ -1,7 +1,6 @@ import { makeAutoObservable } from 'mobx'; import { z } from 'zod'; -import type { AppDataManager } from 'src/model/AppDataManager/AppDataManager'; import type { Session } from 'src/model/Session/Session'; import type { DisplaySettingsData } from 'src/model/AppDataManager/DataClasses/DisplaySettingsData'; import { SettingsBranch } from '../SettingsBranch'; @@ -76,11 +75,6 @@ export const TERMINAL_FONT_FALLBACK_STACK = `${NINJATERM_FONT_FAMILY}, ${SYSTEM_ export default class DisplaySettings { session: Session; - /** App-wide data (presets, MCP flags). Reached through the session. */ - get profileManager(): AppDataManager { - return this.session.app.profileManager; - } - /** See `SettingsBranch` for how this class relates to `DisplaySettingsData`. */ private readonly branch = new SettingsBranch( 'settings.displaySettings', diff --git a/src/renderer/src/model/Settings/PortSettings/PortSettings.ts b/src/renderer/src/model/Settings/PortSettings/PortSettings.ts index d926e062..0c6a1cff 100644 --- a/src/renderer/src/model/Settings/PortSettings/PortSettings.ts +++ b/src/renderer/src/model/Settings/PortSettings/PortSettings.ts @@ -1,7 +1,6 @@ import { makeAutoObservable, runInAction } from 'mobx'; import { z } from 'zod'; -import type { AppDataManager } from 'src/model/AppDataManager/AppDataManager'; import type { Session } from 'src/model/Session/Session'; import { ConnController } from '@/model/ConnController/ConnController'; import type { PortSettingsData } from 'src/model/AppDataManager/DataClasses/PortSettingsData'; @@ -68,11 +67,6 @@ export class PortSettings { session: Session; - /** App-wide data (presets, MCP flags). Reached through the session. */ - get profileManager(): AppDataManager { - return this.session.app.profileManager; - } - /** See `SettingsBranch` for how this class relates to `PortSettingsData`. */ private readonly branch = new SettingsBranch( 'settings.portSettings', diff --git a/src/renderer/src/model/Settings/RxSettings/RxSettings.ts b/src/renderer/src/model/Settings/RxSettings/RxSettings.ts index 5dc0e3e4..a9216117 100644 --- a/src/renderer/src/model/Settings/RxSettings/RxSettings.ts +++ b/src/renderer/src/model/Settings/RxSettings/RxSettings.ts @@ -1,7 +1,6 @@ import { makeAutoObservable } from "mobx"; import { z } from "zod"; -import type { AppDataManager } from "src/model/AppDataManager/AppDataManager"; import type { Session } from "src/model/Session/Session"; import type { RxSettingsData } from "src/model/AppDataManager/DataClasses/RxSettingsData"; import { SettingsBranch } from "../SettingsBranch"; @@ -159,11 +158,6 @@ export default class RxSettings { session: Session; - /** App-wide data (presets, MCP flags). Reached through the session. */ - get profileManager(): AppDataManager { - return this.session.app.profileManager; - } - /** See `SettingsBranch` for how this class relates to `RxSettingsData`. */ private readonly branch = new SettingsBranch( 'settings.rxSettings', diff --git a/src/renderer/src/model/Settings/TxSettings/TxSettings.ts b/src/renderer/src/model/Settings/TxSettings/TxSettings.ts index 538decdb..3f6eef6c 100644 --- a/src/renderer/src/model/Settings/TxSettings/TxSettings.ts +++ b/src/renderer/src/model/Settings/TxSettings/TxSettings.ts @@ -1,5 +1,4 @@ import { makeAutoObservable } from 'mobx'; -import type { AppDataManager } from 'src/model/AppDataManager/AppDataManager'; import type { Session } from 'src/model/Session/Session'; import type { TxSettingsData } from 'src/model/AppDataManager/DataClasses/TxSettingsData'; import { SettingsBranch } from '../SettingsBranch'; @@ -57,11 +56,6 @@ export default class TxSettings { session: Session; - /** App-wide data (presets, MCP flags). Reached through the session. */ - get profileManager(): AppDataManager { - return this.session.app.profileManager; - } - /** See `SettingsBranch` for how this class relates to `TxSettingsData`. */ private readonly branch = new SettingsBranch( 'settings.txSettings', diff --git a/src/renderer/src/model/Terminals/RightDrawer/Macros/Macro.ts b/src/renderer/src/model/Terminals/RightDrawer/Macros/Macro.ts index 379e60cc..4a3480ff 100644 --- a/src/renderer/src/model/Terminals/RightDrawer/Macros/Macro.ts +++ b/src/renderer/src/model/Terminals/RightDrawer/Macros/Macro.ts @@ -387,7 +387,7 @@ export class Macro { * settings modal can surface invalid-regex feedback in red. */ get rxMatchRegex(): RegExp | null { - const key = `${this.rxMatchPattern}${this.rxMatchCaseSensitive ? 'c' : 'i'}`; + const key = `${this.rxMatchPattern}\u0000${this.rxMatchCaseSensitive ? 'c' : 'i'}`; if (this._rxMatchRegexCache !== null && this._rxMatchRegexCache.key === key) { return this._rxMatchRegexCache.regex; } diff --git a/src/renderer/src/view/Settings/RxSettings/RxSettingsView.tsx b/src/renderer/src/view/Settings/RxSettings/RxSettingsView.tsx index e1af1004..211f5300 100644 --- a/src/renderer/src/view/Settings/RxSettings/RxSettingsView.tsx +++ b/src/renderer/src/view/Settings/RxSettings/RxSettingsView.tsx @@ -20,12 +20,16 @@ import RxSettings, { import BorderedSection from 'src/view/Components/BorderedSection'; import ApplyableTextFieldView from 'src/view/Components/ApplyableTextFieldView'; +import DisplaySettings from 'src/model/Settings/DisplaySettings/DisplaySettings'; + interface Props { rxSettings: RxSettings; + /** For the tooltip configuration. */ + displaySettings: DisplaySettings; } function RxSettingsView(props: Props) { - const { rxSettings } = props; + const { rxSettings, displaySettings } = props; return (
@@ -43,11 +47,11 @@ function RxSettingsView(props: Props) { }} > {/* ASCII */} - + } label="ASCII" /> {/* NUMBER */} - + } label="Number (e.g. hex, uint8, int16, ...)" /> @@ -73,8 +77,8 @@ function RxSettingsView(props: Props) { title="If enabled, ANSI escape codes will be parsed. At present, CSI color codes and some of the move cursor commands are supported." placement="top" - {...rxSettings.profileManager.app.settings.displaySettings.getBasicTooltipConfig()} - {...rxSettings.profileManager.app.settings.displaySettings.getBasicTooltipConfig()} + {...displaySettings.getBasicTooltipConfig()} + {...displaySettings.getBasicTooltipConfig()} >