Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(desktop): keep a quick click on a different spot as its own step

Luis Ortizb1b79070dbe6
diff --git a/apps/desktop/src/main/__tests__/recorder-rules.test.ts b/apps/desktop/src/main/__tests__/recorder-rules.test.ts
index 40a0399..03a2fbd 100644
--- a/apps/desktop/src/main/__tests__/recorder-rules.test.ts
+++ b/apps/desktop/src/main/__tests__/recorder-rules.test.ts
@@ -105,11 +105,18 @@ describe('clicks', () => {
expect(shouldCapture({ ...DEFAULT_CAPTURE_SETTINGS, keepClicksBeyondArea: false }, region, outside)).toBe(true);
});
- it('treats a second press within 500 ms as the same click', () => {
- expect(isRepeatClick(1_000, 1_120)).toBe(true);
- expect(isRepeatClick(1_000, 1_500)).toBe(true);
- expect(isRepeatClick(1_000, 1_501)).toBe(false);
- expect(isRepeatClick(null, 1_000)).toBe(false);
+ it('treats a second press on the same spot within 500 ms as the same click', () => {
+ const at = (time: number, x = 100, y = 100) => ({ at: time, point: { x, y } });
+ expect(isRepeatClick(at(1_000), at(1_120))).toBe(true);
+ expect(isRepeatClick(at(1_000), at(1_500, 103, 102))).toBe(true);
+ expect(isRepeatClick(at(1_000), at(1_501))).toBe(false);
+ expect(isRepeatClick(null, at(1_000))).toBe(false);
+ });
+
+ it('keeps a quick click on a different button as its own step', () => {
+ expect(isRepeatClick({ at: 1_000, point: { x: 100, y: 100 } }, { at: 1_150, point: { x: 180, y: 100 } })).toBe(
+ false,
+ );
});
it('frames the display, the window under the click, or the area', () => {
diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.ts
index 5a295d3..74fbc4b 100644
--- a/apps/desktop/src/main/capture/recorder.ts
+++ b/apps/desktop/src/main/capture/recorder.ts
@@ -26,6 +26,7 @@ import { type CaptureMode, type CaptureSettings, DEFAULT_CAPTURE_SETTINGS } from
const TARGET_SIZE = 28;
const SETTLE_MS = 60;
const REPEAT_CLICK_MS = 500;
+const SAME_SPOT_PX = 4;
const HIDDEN_CHARACTERS = /[\p{Cf}\uFFFC\uFFFD]/gu;
const STEP_TEXT_LIMIT = 200;
@@ -126,8 +127,14 @@ function inside(region: Rect, point: Point): boolean {
);
}
-export function isRepeatClick(previousAt: number | null, at: number): boolean {
- return previousAt !== null && at - previousAt <= REPEAT_CLICK_MS;
+export interface PressedAt {
+ at: number;
+ point: Point;
+}
+
+export function isRepeatClick(previous: PressedAt | null, next: PressedAt): boolean {
+ if (previous === null || next.at - previous.at > REPEAT_CLICK_MS) return false;
+ return Math.hypot(next.point.x - previous.point.x, next.point.y - previous.point.y) <= SAME_SPOT_PX;
}
export function shouldCapture(settings: CaptureSettings, region: Rect, point: Point): boolean {
@@ -213,7 +220,7 @@ export class DesktopRecorder {
private hook = new InputHook();
private queue: Promise<unknown> = Promise.resolve();
private running = false;
- private lastClickAt: number | null = null;
+ private lastClick: PressedAt | null = null;
private lastKey: { keycode: number; at: number } | null = null;
private readonly input: InputSession;
private passwordWatch: PasswordWatch | null = null;
@@ -265,7 +272,7 @@ export class DesktopRecorder {
});
if (!started.ok) return { ok: false, reason: started.reason, detail: started.detail };
this.running = true;
- this.lastClickAt = null;
+ this.lastClick = null;
return { ok: true };
}
@@ -293,9 +300,9 @@ export class DesktopRecorder {
const point = { x: action.x, y: action.y };
if (this.ignores(point)) return;
if (!shouldCapture(this.settings(), this.region(), point)) return;
- const at = Date.now();
- const repeat = isRepeatClick(this.lastClickAt, at);
- this.lastClickAt = at;
+ const pressed = { at: Date.now(), point };
+ const repeat = isRepeatClick(this.lastClick, pressed);
+ this.lastClick = pressed;
if (repeat) return;
this.clickAt(clickAction(action.button), point);
}