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 our own capture shortcuts out of the recording

Luis Ortiz3d8703581d18
diff --git a/AGENTS.md b/AGENTS.md
index 40a37e8..750b16a 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -723,6 +723,13 @@ which is what makes that possible in `region` mode.
Capture-now writes an ordinary click step at the cursor. There is no separate action for it: the
point of pressing it is that the cursor is already on the thing worth capturing.
+The keystroke that drives a shortcut must not also be recorded as one. Without that check, pausing a
+recording writes "Press Alt+Shift+P on Mimik" as a step, which is both wrong and confusing, and
+resuming writes another. `matchesShortcut` compares a keystroke against each configured accelerator
+before `captureKey` writes anything, and it compares by parts rather than by string so
+`Shift+Alt+P` and `Alt+Shift+P` are the same shortcut. `CommandOrControl` resolves to Control
+everywhere but macOS.
+
## Export Formats
| Format | Generator | Details |
diff --git a/apps/desktop/scripts/check-pipeline.ts b/apps/desktop/scripts/check-pipeline.ts
index cf541a4..3becc11 100644
--- a/apps/desktop/scripts/check-pipeline.ts
+++ b/apps/desktop/scripts/check-pipeline.ts
@@ -14,6 +14,7 @@ import {
isRepeatClick,
isRepeatKey,
isTypingKey,
+ matchesShortcut,
shouldCapture,
targetRect,
} from '../src/main/capture/recorder';
@@ -200,7 +201,11 @@ app.whenReady().then(async () => {
},
{
grab: syntheticDisplay,
- settings: () => ({ ...REGION_MODE, showCursor: true }),
+ settings: () => ({
+ ...REGION_MODE,
+ showCursor: true,
+ shortcuts: { ...REGION_MODE.shortcuts, capture: 'Alt+Shift+S' },
+ }),
lookup: () => Promise.resolve(control),
focused: () => Promise.resolve(field),
label: (keycode) => Promise.resolve(keycode === 31 ? 'S' : null),
@@ -314,6 +319,23 @@ app.whenReady().then(async () => {
await metaRecorder.captureKey(pressed(99, { ctrl: true }));
const unnamed = seen as CaptureRequest | null;
+ seen = null;
+ await metaRecorder.captureKey(pressed(31, { alt: true, shift: true }));
+ const ownHotkey = seen as CaptureRequest | null;
+
+ results.push({
+ name: 'our own hotkey never becomes a step',
+ ok:
+ ownHotkey === null &&
+ matchesShortcut('Alt+Shift+S', pressed(31, { alt: true, shift: true }), 'S') &&
+ matchesShortcut('shift+ALT+s', pressed(31, { alt: true, shift: true }), 'S') &&
+ !matchesShortcut('Alt+Shift+S', pressed(31, { alt: true }), 'S') &&
+ !matchesShortcut('Alt+Shift+S', pressed(31, { alt: true, shift: true, ctrl: true }), 'S') &&
+ !matchesShortcut('Alt+Shift+S', pressed(31, { alt: true, shift: true }), 'R') &&
+ !matchesShortcut(null, pressed(31, { alt: true, shift: true }), 'S'),
+ detail: 'the configured accelerator is dropped whatever order it is written in, a near miss is not',
+ });
+
results.push({
name: 'a shortcut is its own step',
ok:
diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.ts
index afa5d5d..924389f 100644
--- a/apps/desktop/src/main/capture/recorder.ts
+++ b/apps/desktop/src/main/capture/recorder.ts
@@ -143,6 +143,27 @@ export function chooseTypedText(field: ScreenElement | null, buffer: string, sma
return value;
}
+export function matchesShortcut(accelerator: string | null, action: KeyAction, key: string): boolean {
+ if (!accelerator) return false;
+ const parts = accelerator
+ .split('+')
+ .map((part) => part.trim().toLowerCase())
+ .filter(Boolean);
+ const wanted = parts.pop();
+ if (!wanted || wanted !== key.toLowerCase()) return false;
+
+ const held = new Set(parts);
+ const either = held.has('commandorcontrol') || held.has('cmdorctrl');
+ const onMac = process.platform === 'darwin';
+ return (
+ held.has('alt') === action.alt &&
+ held.has('shift') === action.shift &&
+ (held.has('control') || held.has('ctrl') || (either && !onMac)) === action.ctrl &&
+ (held.has('super') || held.has('meta') || held.has('cmd') || held.has('command') || (either && onMac)) ===
+ action.meta
+ );
+}
+
export function isTypingKey(action: KeyAction): boolean {
if (MODIFIER_KEYS.has(action.keycode)) return false;
if (action.ctrl || action.alt || action.meta) return false;
@@ -285,6 +306,8 @@ export class DesktopRecorder {
async captureKey(action: KeyAction): Promise<void> {
const key = await this.label(action.keycode);
if (!key) return;
+ const { shortcuts } = this.settings();
+ if (Object.values(shortcuts).some((accelerator) => matchesShortcut(accelerator, action, key))) return;
const field = await this.focused();
await this.write(`keydown:${comboLabel(action, key)}`, centreOf(field) ?? cursorPoint(), Promise.resolve(field));
}