Template tests / tests (pull_request) Failing after 33s
Phase 3 groundwork of the improvement plan (PR 7 of the sequence). The Linux
work is a platform rewrite, so this first establishes the interface boundary
and moves an OS-specific piece behind it with Windows behavior preserved — no
new process.platform branches in shared code.
- app/platform/index.js is the single factory that selects a platform
implementation; shared code asks it for adapters and never inspects
process.platform itself.
- app/platform/interfaces.js documents the adapter contracts
(WindowContextProvider, ClickSource, PowerPolicy) and the explicit click-
source vocabulary.
- Extracted the foreground-window/element detection into per-OS adapters,
verbatim from text-intel.js:
app/platform/windows/window-context.js (PowerShell UIAutomation)
app/platform/linux/window-context.js (xprop)
app/platform/darwin/window-context.js (AppleScript)
text-intel.js now delegates to the injected provider and its three
platform-branching methods (and the now-dead child_process import) are gone.
- app/platform/linux/diagnostics.js detects session type, portal/PipeWire,
xinput, readable input devices, and the resulting click/screen-capture
profile, returning actionable messages for the UI. Exposed via a new
platform:capabilities IPC + preload method.
This is behavior-preserving: the Windows/macOS/Linux window-context code is
the same, just relocated behind the factory, and the capture pipeline is
untouched.
Tests: platform selection for every OS, provider validity + null-object for
unsupported OS, the shared service delegating to an injected provider, Linux
capability detection (x11/xinput, Wayland-without-PipeWire messaging, no-click
fallback, evdev), the capability facade, and a guard that text-intel no longer
branches on process.platform. 268 unit tests pass; startup smoke passes and
the click self-test is unchanged (stream source, markers 3/3, burst 8/8).
Co-Authored-By: Claude Fable 5 <[email protected]>
52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const { execFileSync } = require('node:child_process');
|
|
|
|
function hasBinary(name) {
|
|
try {
|
|
execFileSync('which', [name], { stdio: 'pipe' });
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Linux (X11) WindowContextProvider using xprop on the active window. On
|
|
* Wayland xprop only sees XWayland clients, so context is best-effort; the
|
|
* portal-based capture path does not depend on it. Extracted verbatim from
|
|
* text-intel.js. Never throws.
|
|
*/
|
|
function createLinuxWindowContextProvider() {
|
|
return {
|
|
async collect() {
|
|
try {
|
|
if (!hasBinary('xprop')) return { appName: '', windowTitle: '' };
|
|
const active = execFileSync('xprop', ['-root', '_NET_ACTIVE_WINDOW'], {
|
|
encoding: 'utf8',
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
timeout: 1200,
|
|
});
|
|
const activeMatch = active.match(/window id # (0x[0-9a-fA-F]+)/);
|
|
if (!activeMatch) return { appName: '', windowTitle: '' };
|
|
const winId = activeMatch[1];
|
|
const details = execFileSync('xprop', ['-id', winId, '_NET_WM_NAME', 'WM_NAME', 'WM_CLASS'], {
|
|
encoding: 'utf8',
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
timeout: 1200,
|
|
});
|
|
const titleMatch = details.match(/(?:_NET_WM_NAME\(UTF8_STRING\)|WM_NAME\(STRING\)|WM_NAME\(UTF8_STRING\)) = "([^"]*)"/);
|
|
const classMatch = details.match(/WM_CLASS\(STRING\) = "([^"]*)"(?:, "([^"]*)")?/);
|
|
return {
|
|
appName: classMatch ? (classMatch[2] || classMatch[1] || '') : '',
|
|
windowTitle: titleMatch ? titleMatch[1] : '',
|
|
};
|
|
} catch {
|
|
return { appName: '', windowTitle: '' };
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
module.exports = { createLinuxWindowContextProvider, hasBinary };
|