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): read the focused window beside the grab, not on the click

Luis Ortiz4b747115fba0
diff --git a/AGENTS.md b/AGENTS.md
index d2931cb..75d1fcf 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -423,6 +423,16 @@ Files outlive the rows that point at them, because deleting a guide only removes
renderer sends every known screenshot id to main at startup and main deletes any file not in that
set, so an interrupted delete costs disk until the next launch rather than forever.
+Which window is focused is read **after** the settle delay, not when the click arrives. The input hook
+fires on the press, and the operating system has not necessarily moved the foreground window yet, so
+asking first frames whatever was in front a moment ago β€” the recording card included, if that was the
+last thing touched. Reading it beside the grab is the only ordering that describes the screen being
+photographed.
+
+The card itself is not focusable, so clicking Pause or Finish never makes the app frontmost and never
+changes what active-window mode will frame next. The region editors stay focusable because they read
+Enter and Escape; the card has no keyboard of its own to lose.
+
What a capture frames is `captureMode`'s decision, and `frameFor` owns it: the focused window's
bounds, the whole display under the cursor, or the drawn region. The window rectangle is resolved on
every click rather than once at Start, so a window that moves or is resized between steps is followed
diff --git a/apps/desktop/scripts/check-overlay.ts b/apps/desktop/scripts/check-overlay.ts
index d826584..a24353b 100644
--- a/apps/desktop/scripts/check-overlay.ts
+++ b/apps/desktop/scripts/check-overlay.ts
@@ -107,6 +107,12 @@ app.whenReady().then(async () => {
`hint is ${parsed.tip}, content ${parsed.body}px in a ${parsed.win}px window`,
);
+ check(
+ 'the controls card never takes focus',
+ controls !== null && !controls.isFocusable() && overlayWindows().every((w) => !w.isFocused()),
+ `controls focusable: ${controls?.isFocusable()}, focused overlay windows: ${overlayWindows().filter((w) => w.isFocused()).length}`,
+ );
+
await controls?.webContents.executeJavaScript("document.querySelector('#primary').click()");
await settle();
check(
diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.ts
index 2071c68..48ddfa8 100644
--- a/apps/desktop/src/main/capture/recorder.ts
+++ b/apps/desktop/src/main/capture/recorder.ts
@@ -129,13 +129,15 @@ export class DesktopRecorder {
async capture(point: { x: number; y: number }): Promise<void> {
const settings = this.settings();
- const found = await focusedWindow();
- const framed = frameFor(settings.captureMode, point, this.region(), found.ok ? found.window.bounds : null);
+ const region = this.region();
- const shot = await this.withHidden(async () => {
+ const taken = await this.withHidden(async () => {
await delay(SETTLE_MS + settings.screenshotDelayMs);
- return this.grab(framed);
+ const focused = await focusedWindow();
+ const rect = frameFor(settings.captureMode, point, region, focused.ok ? focused.window.bounds : null);
+ return { found: focused, framed: rect, shot: await this.grab(rect) };
});
+ const { found, framed, shot } = taken;
const scale = shot.scaleFactor;
const screenshotId = randomUUID();
diff --git a/apps/desktop/src/main/overlay/index.ts b/apps/desktop/src/main/overlay/index.ts
index 2cd99f9..7ed7070 100644
--- a/apps/desktop/src/main/overlay/index.ts
+++ b/apps/desktop/src/main/overlay/index.ts
@@ -31,7 +31,12 @@ function protect(win: BrowserWindow): void {
if (!win.isDestroyed()) win.setContentProtection(true);
}
-function overlayWindow(bounds: Electron.Rectangle, hash: string, interactive: boolean): BrowserWindow {
+function overlayWindow(
+ bounds: Electron.Rectangle,
+ hash: string,
+ interactive: boolean,
+ focusable = interactive,
+): BrowserWindow {
const win = new BrowserWindow({
...bounds,
show: false,
@@ -44,7 +49,7 @@ function overlayWindow(bounds: Electron.Rectangle, hash: string, interactive: bo
fullscreenable: false,
skipTaskbar: true,
hasShadow: false,
- focusable: interactive,
+ focusable,
acceptFirstMouse: true,
webPreferences: { preload: preloadFile(), contextIsolation: true, nodeIntegration: false },
});
@@ -186,7 +191,7 @@ export class CaptureOverlay {
private ensureControls(): void {
if (this.controls?.isDestroyed()) this.controls = null;
if (!this.controls) {
- this.controls = overlayWindow({ x: 0, y: 0, ...this.size }, 'controls', true);
+ this.controls = overlayWindow({ x: 0, y: 0, ...this.size }, 'controls', true, false);
this.controls.setIgnoreMouseEvents(false);
}
this.positionControls();