Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(remote-desktop): 滚轮批次在注入时读取实际系统光标位置

Dash31c13b0aafd2
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts
index c43c22a3c7..a7cdedcb4b 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/inputHost.test.ts
@@ -14,11 +14,14 @@ const flush = async () => {
for (let i = 0; i < 20; i++) await Promise.resolve();
};
+// The system cursor, which the local user can move between the viewer's batches.
+let cursor = { x: 0, y: 0 };
vi.mock('electron', () => ({
app: {},
screen: {
getAllDisplays: () => [{ id: 1, bounds: { x: 0, y: 0, width: 100, height: 100 } }],
dipToScreenPoint: (point: unknown) => point,
+ getCursorScreenPoint: () => cursor,
},
}));
vi.mock('../windowsHost', () => ({
@@ -404,7 +407,9 @@ describe('native input lifecycle', () => {
await flush();
// A batch without pointer events never reports.
expect(pointer).toHaveBeenCalledTimes(2);
- // A wheel has no position: it reports where the pointer already is, even before a move.
+ // A wheel has no position: it reports the live system cursor, which the local user
+ // may have moved since the viewer's last batch, ahead of any positions in its batch.
+ cursor = { x: 7, y: 8 };
host.input([
{ kind: 'scroll', dx: 0, dy: 3 },
{ kind: 'move', x: 0.9, y: 0.9 },
@@ -413,15 +418,15 @@ describe('native input lifecycle', () => {
c.child.stdout.emit('data', Buffer.from('ok\n'));
await flush();
expect(pointer.mock.calls.at(-1)![0]).toEqual([
- { x: 10, y: 10 },
+ { x: 7, y: 8 },
{ x: 89, y: 89 },
]);
+ cursor = { x: 30, y: 40 };
host.input([{ kind: 'scroll', dx: 0, dy: -3 }]);
await flush();
c.child.stdout.emit('data', Buffer.from('ok\n'));
await flush();
- expect(pointer.mock.calls.at(-1)![0]).toEqual([{ x: 89, y: 89 }]);
- // Before any pointer position is known there is nothing to report.
+ expect(pointer.mock.calls.at(-1)![0]).toEqual([{ x: 30, y: 40 }]);
expect(pointer).toHaveBeenCalledTimes(4);
host.stop();
c.exit();
diff --git a/apps/desktop/src/main/remote-desktop/inputHost.ts b/apps/desktop/src/main/remote-desktop/inputHost.ts
index 2424ddf37c..c11ed31631 100644
--- a/apps/desktop/src/main/remote-desktop/inputHost.ts
+++ b/apps/desktop/src/main/remote-desktop/inputHost.ts
@@ -213,8 +213,6 @@ export class DesktopInputHost {
private heartbeat: ReturnType<typeof setInterval> | null = null;
private stopping: Promise<void> = Promise.resolve();
private privacyPaused = false;
- /** Where the viewer's pointer is once everything queued so far has been injected. */
- private lastPoint: { x: number; y: number } | null = null;
private linuxPoint: ((x: number, y: number) => { x: number; y: number }) | null = null;
/** 代输入 live view: the helper confines input to this window and maps 0–1 fractions itself. */
private window: { windowId: number; pid: number } | null = null;
@@ -236,7 +234,6 @@ export class DesktopInputHost {
) {}
async start(displayId: string, window?: { windowId: number; pid: number }): Promise<void> {
this.stop();
- this.lastPoint = null;
const platform = this.runtime.platform ?? process.platform;
if (platform !== 'darwin' && platform !== 'win32' && platform !== 'linux')
throw new Error('DESKTOP_INPUT_UNSUPPORTED');
@@ -397,17 +394,18 @@ export class DesktopInputHost {
const mapped = process.platform === 'win32' ? screen.dipToScreenPoint(point) : point;
return { ...event, ...mapped };
});
- // A wheel carries no position: it lands where the pointer is when it is injected,
- // which, in serialized order, is the last position queued before this batch.
- if (this.lastPoint && events.some((event) => event.kind === 'scroll'))
- points.unshift(this.lastPoint);
- if (points.length) this.lastPoint = points[points.length - 1];
- this.write(native, batch, points);
+ this.write(
+ native,
+ batch,
+ points,
+ events.some((event) => event.kind === 'scroll'),
+ );
}
private write(
events: unknown[],
batch?: { ready: Promise<void>; complete: () => void },
points: { x: number; y: number }[] = [],
+ wheel = false,
): void {
const child = this.child;
const line = `${JSON.stringify(events)}\n`;
@@ -425,7 +423,12 @@ export class DesktopInputHost {
if (generation !== this.generation) return;
// Local-only windows must pass this batch's pointer through for as long as it is
// being injected, not from when it was queued nor after a fixed delay.
- const settled = points.length ? this.onPointer?.(points) : undefined;
+ // A wheel carries no position: it lands on the system cursor as it is when this
+ // batch starts, which the local user may have moved since the viewer last did.
+ const settled =
+ points.length || wheel
+ ? this.onPointer?.(wheel ? [screen.getCursorScreenPoint(), ...points] : points)
+ : undefined;
try {
if (connection) {
if ((await connection.request(line.slice(0, -1))) !== 'ok\n')