Introduce the platform adapter layer; extract window context behind it
Template tests / tests (pull_request) Failing after 33s
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]>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* The single factory that selects a platform implementation. The rest of the
|
||||
* app depends on the interfaces in ./interfaces.js and asks this module for a
|
||||
* concrete adapter — it never branches on `process.platform` itself.
|
||||
*
|
||||
* As Linux runtime capture is implemented, its ClickSource / ScreenFrameSource
|
||||
* adapters are added here; today this provides the WindowContextProvider for
|
||||
* every platform and the Linux capability diagnostics.
|
||||
*/
|
||||
|
||||
const { assertWindowContextProvider } = require('./interfaces');
|
||||
|
||||
function detectPlatform(platform = process.platform) {
|
||||
if (platform === 'win32') return 'windows';
|
||||
if (platform === 'darwin') return 'darwin';
|
||||
if (platform === 'linux') return 'linux';
|
||||
return 'unsupported';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the WindowContextProvider for the current OS. `platform` is injectable
|
||||
* so the selection logic is unit-testable off the target OS.
|
||||
*/
|
||||
function createWindowContextProvider({ platform = process.platform } = {}) {
|
||||
const os = detectPlatform(platform);
|
||||
let provider;
|
||||
switch (os) {
|
||||
case 'windows':
|
||||
provider = require('./windows/window-context').createWindowsWindowContextProvider();
|
||||
break;
|
||||
case 'darwin':
|
||||
provider = require('./darwin/window-context').createDarwinWindowContextProvider();
|
||||
break;
|
||||
case 'linux':
|
||||
provider = require('./linux/window-context').createLinuxWindowContextProvider();
|
||||
break;
|
||||
default:
|
||||
// Unsupported OS: a null-object provider so callers still work.
|
||||
provider = { async collect() { return { appName: '', windowTitle: '' }; } };
|
||||
}
|
||||
return assertWindowContextProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Capability profile for the current OS (used by diagnostics UI). Only Linux
|
||||
* has a rich profile today; other platforms report their OS and a capable
|
||||
* baseline.
|
||||
*/
|
||||
function detectCapabilities({ platform = process.platform, env = process.env } = {}) {
|
||||
const os = detectPlatform(platform);
|
||||
if (os === 'linux') {
|
||||
return require('./linux/diagnostics').detectLinuxCapabilities({ env });
|
||||
}
|
||||
return {
|
||||
os,
|
||||
sessionType: os,
|
||||
isWayland: false,
|
||||
clickCapture: os === 'windows' ? 'windows-hook' : os,
|
||||
screenCapture: os,
|
||||
messages: [],
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { detectPlatform, createWindowContextProvider, detectCapabilities };
|
||||
Reference in New Issue
Block a user