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): record a double click as one step

Luis Ortiz17d75cad8ea1
diff --git a/AGENTS.md b/AGENTS.md
index e384598..d2931cb 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -526,13 +526,22 @@ and the editor show it with no export-side work. Keeping it out of the file mean
never decoded and re-encoded on the way to disk, and the pointer can be moved or removed later
without touching the original.
+A double click is one action, so it is one step. `isRepeatClick` drops a press that lands within
+500 ms of the one before it, and the clock is reset on every press rather than on every capture, so a
+burst of clicks stays suppressed until there is a real gap. The rule is time only, deliberately: it
+takes its timestamps as arguments rather than reading the clock, so it is exercised without a mouse.
+
+The cost is that two deliberate presses on different controls less than 500 ms apart become one step.
+Matching on position as well would separate them, and that was tried and dropped in favour of keeping
+the rule identical to the one this behaviour was modelled on.
+
A click outside the capture area cannot be framed by a region that does not contain it, so those
captures fall back to the whole display the click landed on. `shouldCapture` is exported for that
decision rather than being inline in the hook handler, so the rule is testable on its own. It only
filters in `region` mode; the other two modes frame every click by construction.
`check:pipeline` covers all five: clamping and persistence round-trip through the real file, an
-unknown mode falls back, the opt-in rule holds in four positions, `frameFor` returns the right
+unknown mode falls back, the opt-in rule holds in four positions, a double click collapses to one step, `frameFor` returns the right
rectangle for all three modes including both window fallbacks, a 400 ms delay measurably slows the
grab, and the same synthetic frame renders to a different size once a cursor is drawn over it. It restores whatever
settings were on disk when it finishes.
diff --git a/apps/desktop/scripts/check-pipeline.ts b/apps/desktop/scripts/check-pipeline.ts
index dfe516c..ff9516e 100644
--- a/apps/desktop/scripts/check-pipeline.ts
+++ b/apps/desktop/scripts/check-pipeline.ts
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
import { join } from 'node:path';
import { app, BrowserWindow, nativeImage, protocol, screen } from 'electron';
import { ask } from '../src/main/ask';
-import { DesktopRecorder, frameFor, shouldCapture } from '../src/main/capture/recorder';
+import { DesktopRecorder, frameFor, isRepeatClick, shouldCapture } from '../src/main/capture/recorder';
import { clampToDisplays } from '../src/main/capture/region';
import { registerScreenshotProtocol, SCREENSHOT_SCHEME, sweepScreenshots } from '../src/main/capture/screenshot-store';
import { DEFAULT_CAPTURE_SETTINGS, loadSettings, normaliseSettings, saveSettings } from '../src/main/capture/settings';
@@ -102,6 +102,16 @@ app.whenReady().then(async () => {
detail: 'ignored when off, captured when on, inside always captured, never filtered outside region mode',
});
+ results.push({
+ name: 'a double click is one step',
+ ok:
+ isRepeatClick(1_000, 1_120) &&
+ isRepeatClick(1_000, 1_500) &&
+ !isRepeatClick(1_000, 1_501) &&
+ !isRepeatClick(null, 1_000),
+ detail: 'a press within 500 ms of the last one is dropped, later is kept, the first always captures',
+ });
+
const insidePoint = { x: region.x + 10, y: region.y + 10 };
const windowRect = { x: region.x + 5, y: region.y + 5, width: 300, height: 200 };
const elsewhere = { x: region.x + 900, y: region.y + 900, width: 100, height: 100 };
diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.ts
index 696b532..2071c68 100644
--- a/apps/desktop/src/main/capture/recorder.ts
+++ b/apps/desktop/src/main/capture/recorder.ts
@@ -11,6 +11,7 @@ import { type CaptureMode, type CaptureSettings, DEFAULT_CAPTURE_SETTINGS } from
const TARGET_SIZE = 28;
const SETTLE_MS = 60;
+const REPEAT_CLICK_MS = 500;
export interface CursorMark {
x: number;
@@ -41,6 +42,10 @@ function inside(region: Region, point: { x: number; y: number }): boolean {
);
}
+export function isRepeatClick(previousAt: number | null, at: number): boolean {
+ return previousAt !== null && at - previousAt <= REPEAT_CLICK_MS;
+}
+
export function shouldCapture(settings: CaptureSettings, region: Region, point: { x: number; y: number }): boolean {
if (settings.captureMode !== 'region') return true;
return inside(region, point) || settings.captureOutsideClicks;
@@ -63,6 +68,7 @@ export class DesktopRecorder {
private queue: Promise<unknown> = Promise.resolve();
private paused = false;
private running = false;
+ private lastClickAt: number | null = null;
constructor(
private readonly region: () => Region,
@@ -79,6 +85,7 @@ export class DesktopRecorder {
if (!started.ok) return { ok: false, reason: started.reason, detail: started.detail };
this.running = true;
this.paused = false;
+ this.lastClickAt = null;
return { ok: true };
}
@@ -105,6 +112,10 @@ 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;
+ if (repeat) return;
this.enqueue(point);
}