INNER CODE UNIT · TypeScript
ensureInitialized
AmrDab/clawdcursor · src/surface/cli.ts:1304
const ensureInitialized = async (): Promise<void> => {
if (initialized) return;
if (initPromise) return initPromise;
initPromise = (async () => {
await desktop.connect();
platform = await getPlatform();
screenshotScaleFactor = desktop.getScaleFactor();
// mouseScaleFactor: image-space → mouse-driver coords.
// • Windows / Linux-X11: nut-js drives in PHYSICAL pixels → use the
// physical/image ratio (screenshotScaleFactor).
// • macOS: nut-js drives in LOGICAL points (Cocoa/CGEvent space). On a
// Retina panel physical≠logical, so the physical scale double-counts
// the backing scale and every click lands ~2× off (#154). Map
// image-space → LOGICAL instead, using NSScreen's logical width.
// (Mirrors imageScale() in agent-loop/coord-scale.ts for System B.)
if (process.platform === 'darwin') {
try {
const { LLM_TARGET_WIDTH } = await import('../core/agent-loop/coord-scale');