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): clear the capturing state once the capture queue empties

Luis Ortiza0fd20ebb344
diff --git a/apps/desktop/scripts/check-pipeline.ts b/apps/desktop/scripts/check-pipeline.ts
index 0b2fdfc..43a8f6d 100644
--- a/apps/desktop/scripts/check-pipeline.ts
+++ b/apps/desktop/scripts/check-pipeline.ts
@@ -516,6 +516,35 @@ app.whenReady().then(async () => {
detail: `with the first step still being written: ${count('lookup')} lookups, ${count('grab')} grabs, ${count('focused')} field reads`,
});
+ let busyNow = false;
+ const stepless = new DesktopRecorder(
+ () => region,
+ (fn) => {
+ busyNow = true;
+ return fn();
+ },
+ () => Promise.resolve(null),
+ {
+ grab: async () => syntheticDisplay,
+ settings: () => REGION_MODE,
+ focused: () => Promise.resolve({ ...control }),
+ resolve: () => Promise.resolve('x'),
+ reset: () => Promise.resolve(),
+ drained: () => {
+ busyNow = false;
+ },
+ },
+ );
+ for (let i = 0; i < 3; i++) stepless.onAction(pressed(30));
+ stepless.onAction(pressed(28));
+ await stepless.drain();
+ await wait(50);
+ results.push({
+ name: 'typing that writes no step leaves the card idle',
+ ok: !busyNow,
+ detail: busyNow ? 'still marked as capturing after the queue emptied' : 'capturing cleared once the queue emptied',
+ });
+
const page = { x: 0, y: 0, width: 800, height: 600 };
const click = { x: 160, y: 66 };
const boxed = (rect: ScreenElement['rect']) => targetRect({ ...control, rect }, page, click).width;
diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.ts
index e3242d9..0aaf6dc 100644
--- a/apps/desktop/src/main/capture/recorder.ts
+++ b/apps/desktop/src/main/capture/recorder.ts
@@ -83,6 +83,7 @@ export interface RecorderHooks {
label?: (keycode: number) => Promise<string | null>;
resolve?: (keycode: number, shift: boolean, ctrl: boolean, alt: boolean) => Promise<string | null>;
reset?: () => Promise<void>;
+ drained?: () => void;
}
export type RecorderStart = { ok: true } | { ok: false; reason: string; detail: string };
@@ -216,6 +217,8 @@ export class DesktopRecorder {
private readonly label: (keycode: number) => Promise<string | null>;
private readonly resolve: (keycode: number, shift: boolean, ctrl: boolean, alt: boolean) => Promise<string | null>;
private readonly reset: () => Promise<void>;
+ private readonly drained: () => void;
+ private pending = 0;
constructor(
private readonly region: () => Region,
@@ -232,6 +235,7 @@ export class DesktopRecorder {
this.label = hooks.label ?? keyLabel;
this.resolve = hooks.resolve ?? resolveKey;
this.reset = hooks.reset ?? clearDeadKey;
+ this.drained = hooks.drained ?? (() => {});
}
async start(): Promise<RecorderStart> {
@@ -378,9 +382,16 @@ export class DesktopRecorder {
}
private enqueue(job: () => Promise<void>): void {
- this.queue = this.queue.then(job).catch((error) => {
- process.stderr.write(`mimik: capture failed: ${error instanceof Error ? error.message : String(error)}\n`);
- });
+ this.pending += 1;
+ this.queue = this.queue
+ .then(job)
+ .catch((error) => {
+ process.stderr.write(`mimik: capture failed: ${error instanceof Error ? error.message : String(error)}\n`);
+ })
+ .finally(() => {
+ this.pending -= 1;
+ if (this.pending === 0) this.drained();
+ });
}
captureNow(point: Point): void {
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 8733c7f..45a3499 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -247,33 +247,30 @@ if (!app.requestSingleInstanceLock()) {
return overlay ? overlay.withHidden(fn) : fn();
},
async (request) => {
- try {
- const reply = await ask<{ stepId?: string; title?: string; pending?: boolean }>(
- mainWindow?.webContents ?? null,
- 'mimik:capture:step',
- { ...request, guideId },
- ).catch(() => undefined);
- if (reply?.stepId && reply.title) {
- const step: OverlayStep = {
- id: reply.stepId,
- index: steps.length + 1,
- title: reply.title,
- src: request.image.src,
- source: 'heuristic',
- pending: reply.pending === true,
- app: request.elementMeta.app?.name ?? null,
- };
- steps.push(step);
- overlay?.showStep(step);
- }
- return reply;
- } finally {
- overlay?.setBusy(false);
+ const reply = await ask<{ stepId?: string; title?: string; pending?: boolean }>(
+ mainWindow?.webContents ?? null,
+ 'mimik:capture:step',
+ { ...request, guideId },
+ ).catch(() => undefined);
+ if (reply?.stepId && reply.title) {
+ const step: OverlayStep = {
+ id: reply.stepId,
+ index: steps.length + 1,
+ title: reply.title,
+ src: request.image.src,
+ source: 'heuristic',
+ pending: reply.pending === true,
+ app: request.elementMeta.app?.name ?? null,
+ };
+ steps.push(step);
+ overlay?.showStep(step);
}
+ return reply;
},
{
settings: () => captureSettings ?? loadSettings(),
ignores: (point) => overlay?.ignores(point) ?? false,
+ drained: () => overlay?.setBusy(false),
},
);