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 📖

feat(desktop): add the settings screen with capture, AI and shortcut sections

Luis Ortiz97523e087109
diff --git a/AGENTS.md b/AGENTS.md
index f0fc9aa..d91389e 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -741,6 +741,26 @@ rectangle for all three modes including both window fallbacks, a 400 ms delay me
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.
+## Desktop Settings
+
+Three sections behind one left nav: Capture, AI descriptions, Shortcuts. The split is the same one
+that decides where a file lives. Capture and Shortcuts describe things the extension has no concept
+of, so they are written in `apps/desktop` against `capture-settings.json`. AI descriptions are
+identical on both surfaces, so `AiSettings` lives in `packages/ui` and each app hands it a
+`validate` function — the desktop passes core's `validateApiKey` directly, and the extension goes
+through its background messaging, which is the only part that differs.
+
+`SettingsView`, the extension's own 699-line settings screen, was deliberately **not** moved. It
+carries voice narration, smart blur, brand logos and a microphone picker, none of which mean
+anything on desktop, and it reaches for `@/lib/browser-api`. Moving it would have dragged all of
+that across for the sake of four fields; extracting the four was less code and leaves the extension
+untouched.
+
+The shortcut recorder reads a keystroke and writes an Electron accelerator. It refuses a bare key,
+because a global accelerator with no modifier takes that key from every application on the machine,
+and it ignores a modifier pressed alone, because `Shift` is not a shortcut. `accelerator()` is a
+pure function over the event so it is tested without a keyboard.
+
## Capture Shortcuts
Three global accelerators, stored in `capture-settings.json` beside everything else: start/stop,
diff --git a/apps/desktop/src/renderer/App.tsx b/apps/desktop/src/renderer/App.tsx
index 325c4bf..c6a9a25 100644
--- a/apps/desktop/src/renderer/App.tsx
+++ b/apps/desktop/src/renderer/App.tsx
@@ -29,7 +29,7 @@ export default function App() {
<div className="min-h-screen flex flex-col bg-background">
<TopNav route={route} onSettings={library ? () => setSettingsOpen(true) : undefined} />
{settingsOpen ? (
- <main className="flex-1">
+ <main className="flex-1 min-h-0">
<SettingsPanel onClose={() => setSettingsOpen(false)} />
</main>
) : route.page === 'guide' ? (
diff --git a/apps/desktop/src/renderer/SettingsPanel.tsx b/apps/desktop/src/renderer/SettingsPanel.tsx
index f13950f..a88ea54 100644
--- a/apps/desktop/src/renderer/SettingsPanel.tsx
+++ b/apps/desktop/src/renderer/SettingsPanel.tsx
@@ -1,16 +1,56 @@
+import { validateApiKey } from '@mimik/core/capture/ai/validate';
import { i18n } from '@mimik/core/env';
-import { Button } from '@mimik/ui/components/ui/button';
+import AiSettings from '@mimik/ui/shared/AiSettings';
import { useEffect, useState } from 'react';
-import type { CaptureSettings } from '../main/capture/settings';
+import type { CaptureSettings, CaptureShortcuts } from '../main/capture/settings';
+import ShortcutRecorder from './ShortcutRecorder';
+
+type Section = 'capture' | 'ai' | 'shortcuts';
+
+const SECTIONS: { id: Section; labelKey: string }[] = [
+ { id: 'capture', labelKey: 'desktop_capturingSection' },
+ { id: 'ai', labelKey: 'settings_aiDescriptions' },
+ { id: 'shortcuts', labelKey: 'desktop_shortcutsSection' },
+];
const STYLES: CaptureSettings['cursorStyle'][] = ['arrow', 'hand', 'dot'];
-const MODES: { id: CaptureSettings['captureMode']; label: string }[] = [
- { id: 'window', label: 'desktop_modeWindow' },
- { id: 'screen', label: 'desktop_modeScreen' },
- { id: 'region', label: 'desktop_modeRegion' },
+const MODES: { id: CaptureSettings['captureMode']; labelKey: string }[] = [
+ { id: 'window', labelKey: 'desktop_modeWindow' },
+ { id: 'screen', labelKey: 'desktop_modeScreen' },
+ { id: 'region', labelKey: 'desktop_modeRegion' },
];
+const KEYS: { id: keyof CaptureShortcuts; labelKey: string }[] = [
+ { id: 'startStop', labelKey: 'desktop_shortcutStartStop' },
+ { id: 'pauseResume', labelKey: 'desktop_shortcutPauseResume' },
+ { id: 'capture', labelKey: 'desktop_shortcutCapture' },
+];
+
+const SELECT = 'h-9 rounded-[10px] border border-border bg-card px-2.5 text-sm text-foreground';
+
+function Toggle({
+ checked,
+ label,
+ hint,
+ onChange,
+}: {
+ checked: boolean;
+ label: string;
+ hint?: string;
+ onChange: (next: boolean) => void;
+}) {
+ return (
+ <label className="flex cursor-pointer items-start gap-3">
+ <input type="checkbox" checked={checked} onChange={(e) => onChange(e.target.checked)} className="mt-0.5" />
+ <span className="flex flex-col gap-0.5">
+ <span className="text-sm text-foreground">{label}</span>
+ {hint && <span className="text-xs text-muted-foreground">{hint}</span>}
+ </span>
+ </label>
+ );
+}
export default function SettingsPanel({ onClose }: { onClose(): void }) {
+ const [section, setSection] = useState<Section>('capture');
const [settings, setSettings] = useState<CaptureSettings | null>(null);
useEffect(() => {
@@ -22,86 +62,147 @@ export default function SettingsPanel({ onClose }: { onClose(): void }) {
};
return (
- <div className="mx-auto w-full max-w-2xl p-8">
- <div className="mb-6 flex items-center">
- <h1 className="mr-auto text-lg font-semibold text-foreground">{i18n.t('settings_title')}</h1>
- <Button variant="ghost" size="sm" onClick={onClose}>
+ <div className="flex h-full">
+ <nav className="w-56 shrink-0 border-r border-border bg-secondary/25 p-3">
+ <p className="px-3 pb-2.5 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground">
+ {i18n.t('settings_title')}
+ </p>
+ {SECTIONS.map((item) => (
+ <button
+ key={item.id}
+ type="button"
+ onClick={() => setSection(item.id)}
+ className={`mb-0.5 flex h-9 w-full items-center rounded-[9px] px-3 text-left text-sm transition-colors ${
+ section === item.id
+ ? 'bg-secondary font-semibold text-foreground'
+ : 'text-foreground hover:bg-secondary/60'
+ }`}
+ >
+ {i18n.t(item.labelKey)}
+ </button>
+ ))}
+ <button
+ type="button"
+ onClick={onClose}
+ className="mt-3 flex h-9 w-full items-center rounded-[9px] px-3 text-left text-sm text-muted-foreground hover:bg-secondary/60"
+ >
{i18n.t('common_close')}
- </Button>
- </div>
+ </button>
+ </nav>
+
+ <div className="min-w-0 flex-1 overflow-y-auto px-10 py-8">
+ <div className="mx-auto flex max-w-[640px] flex-col gap-5">
+ {section === 'ai' && <AiSettings validate={validateApiKey} />}
+
+ {section === 'capture' && settings && (
+ <>
+ <label className="flex items-center gap-3 text-sm text-foreground">
+ <span className="mr-auto">{i18n.t('desktop_captureMode')}</span>
+ <select
+ className={SELECT}
+ value={settings.captureMode}
+ onChange={(e) => save({ captureMode: e.target.value as CaptureSettings['captureMode'] })}
+ >
+ {MODES.map((mode) => (
+ <option key={mode.id} value={mode.id}>
+ {i18n.t(mode.labelKey)}
+ </option>
+ ))}
+ </select>
+ </label>
- {settings && (
- <section className="mb-8 rounded-xl border border-border bg-secondary/40 p-5">
- <h2 className="mb-4 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
- {i18n.t('desktop_capturingSection')}
- </h2>
-
- <label className="mb-3 flex items-center gap-3 text-sm text-foreground">
- <span className="mr-auto">{i18n.t('desktop_captureMode')}</span>
- <select
- className="rounded-md border border-border bg-background px-2 py-1"
- value={settings.captureMode}
- onChange={(e) => save({ captureMode: e.target.value as CaptureSettings['captureMode'] })}
- >
- {MODES.map((mode) => (
- <option key={mode.id} value={mode.id}>
- {i18n.t(mode.label)}
- </option>
- ))}
- </select>
- </label>
-
- <label className="mb-3 flex items-center gap-3 text-sm text-foreground">
- <input
- type="checkbox"
- checked={settings.showCursor}
- onChange={(e) => save({ showCursor: e.target.checked })}
- />
- {i18n.t('desktop_showCursor')}
- </label>
-
- <label className="mb-3 flex items-center gap-3 text-sm text-foreground">
- <span className="mr-auto">{i18n.t('desktop_pointerStyle')}</span>
- <select
- className="rounded-md border border-border bg-background px-2 py-1"
- value={settings.cursorStyle}
- disabled={!settings.showCursor}
- onChange={(e) => save({ cursorStyle: e.target.value as CaptureSettings['cursorStyle'] })}
- >
- {STYLES.map((style) => (
- <option key={style} value={style}>
- {style}
- </option>
- ))}
- </select>
- </label>
-
- <label className="mb-3 flex items-center gap-3 text-sm text-foreground">
- <span className="mr-auto">{i18n.t('desktop_screenshotDelay')}</span>
- <input
- type="number"
- min={0}
- max={2000}
- step={50}
- className="w-24 rounded-md border border-border bg-background px-2 py-1"
- value={settings.screenshotDelayMs}
- onChange={(e) => save({ screenshotDelayMs: Number(e.target.value) })}
- />
- <span className="text-muted-foreground">{i18n.t('desktop_milliseconds')}</span>
- </label>
-
- {settings.captureMode === 'region' && (
- <label className="flex items-center gap-3 text-sm text-foreground">
- <input
- type="checkbox"
- checked={settings.captureOutsideClicks}
- onChange={(e) => save({ captureOutsideClicks: e.target.checked })}
+ <Toggle
+ checked={settings.showCursor}
+ label={i18n.t('desktop_showCursor')}
+ onChange={(showCursor) => save({ showCursor })}
/>
- {i18n.t('desktop_captureOutside')}
- </label>
+
+ <label className="flex items-center gap-3 text-sm text-foreground">
+ <span className="mr-auto">{i18n.t('desktop_pointerStyle')}</span>
+ <select
+ className={SELECT}
+ value={settings.cursorStyle}
+ disabled={!settings.showCursor}
+ onChange={(e) => save({ cursorStyle: e.target.value as CaptureSettings['cursorStyle'] })}
+ >
+ {STYLES.map((style) => (
+ <option key={style} value={style}>
+ {style}
+ </option>
+ ))}
+ </select>
+ </label>
+
+ <label className="flex items-center gap-3 text-sm text-foreground">
+ <span className="mr-auto">{i18n.t('desktop_screenshotDelay')}</span>
+ <input
+ type="number"
+ min={0}
+ max={2000}
+ step={50}
+ className={`${SELECT} w-24`}
+ value={settings.screenshotDelayMs}
+ onChange={(e) => save({ screenshotDelayMs: Number(e.target.value) })}
+ />
+ <span className="text-muted-foreground">{i18n.t('desktop_milliseconds')}</span>
+ </label>
+
+ {settings.captureMode === 'region' && (
+ <Toggle
+ checked={settings.captureOutsideClicks}
+ label={i18n.t('desktop_captureOutside')}
+ onChange={(captureOutsideClicks) => save({ captureOutsideClicks })}
+ />
+ )}
+
+ <div className="my-1 h-px bg-border" />
+
+ <Toggle
+ checked={settings.captureKeys}
+ label={i18n.t('desktop_captureKeys')}
+ onChange={(captureKeys) => save({ captureKeys })}
+ />
+ <Toggle
+ checked={settings.captureTyping}
+ label={i18n.t('desktop_captureTyping')}
+ onChange={(captureTyping) => save({ captureTyping })}
+ />
+ <Toggle
+ checked={settings.typingSmartDetection}
+ label={i18n.t('desktop_typingSmart')}
+ hint={i18n.t('desktop_typingSmartHint')}
+ onChange={(typingSmartDetection) => save({ typingSmartDetection })}
+ />
+
+ <label className="flex items-center gap-3 text-sm text-foreground">
+ <span className="mr-auto">{i18n.t('desktop_typingDebounce')}</span>
+ <input
+ type="number"
+ min={200}
+ max={5000}
+ step={100}
+ disabled={!settings.captureTyping}
+ className={`${SELECT} w-24`}
+ value={settings.typingDebounceMs}
+ onChange={(e) => save({ typingDebounceMs: Number(e.target.value) })}
+ />
+ <span className="text-muted-foreground">{i18n.t('desktop_milliseconds')}</span>
+ </label>
+ </>
)}
- </section>
- )}
+
+ {section === 'shortcuts' &&
+ settings &&
+ KEYS.map((key) => (
+ <ShortcutRecorder
+ key={key.id}
+ label={i18n.t(key.labelKey)}
+ value={settings.shortcuts[key.id]}
+ onChange={(next) => save({ shortcuts: { ...settings.shortcuts, [key.id]: next } })}
+ />
+ ))}
+ </div>
+ </div>
</div>
);
}
diff --git a/apps/desktop/src/renderer/ShortcutRecorder.tsx b/apps/desktop/src/renderer/ShortcutRecorder.tsx
new file mode 100644
index 0000000..664bcda
--- /dev/null
+++ b/apps/desktop/src/renderer/ShortcutRecorder.tsx
@@ -0,0 +1,62 @@
+import { i18n } from '@mimik/core/env';
+import { X } from 'lucide-react';
+import { useState } from 'react';
+
+const MODIFIERS = new Set(['Control', 'Alt', 'Shift', 'Meta']);
+
+export function accelerator(event: React.KeyboardEvent): string | null {
+ if (MODIFIERS.has(event.key)) return null;
+ const held: string[] = [];
+ if (event.metaKey) held.push('Super');
+ if (event.ctrlKey) held.push('Control');
+ if (event.altKey) held.push('Alt');
+ if (event.shiftKey) held.push('Shift');
+ if (held.length === 0) return null;
+ const key = event.key.length === 1 ? event.key.toUpperCase() : event.key;
+ return [...held, key].join('+');
+}
+
+interface ShortcutRecorderProps {
+ label: string;
+ value: string | null;
+ onChange: (accelerator: string | null) => void;
+}
+
+export default function ShortcutRecorder({ label, value, onChange }: ShortcutRecorderProps) {
+ const [listening, setListening] = useState(false);
+
+ return (
+ <div className="flex items-center gap-3">
+ <span className="mr-auto text-sm text-foreground">{label}</span>
+ <button
+ type="button"
+ onKeyDown={(event) => {
+ if (!listening) return;
+ event.preventDefault();
+ const next = accelerator(event);
+ if (!next) return;
+ onChange(next);
+ setListening(false);
+ }}
+ onClick={() => setListening(true)}
+ onBlur={() => setListening(false)}
+ className={`h-9 min-w-[188px] rounded-[10px] border px-3 text-[13px] font-medium transition-colors ${
+ listening
+ ? 'border-accent text-accent ring-2 ring-accent/25'
+ : 'border-border bg-card text-foreground hover:border-violet'
+ }`}
+ >
+ {listening ? i18n.t('desktop_shortcutPress') : (value ?? '—')}
+ </button>
+ <button
+ type="button"
+ aria-label={i18n.t('desktop_shortcutClear')}
+ onClick={() => onChange(null)}
+ disabled={!value}
+ className="flex size-9 items-center justify-center rounded-[10px] border border-border bg-card text-muted-foreground hover:text-accent disabled:opacity-35"
+ >
+ <X size={15} />
+ </button>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/renderer/__tests__/shortcut-recorder.test.ts b/apps/desktop/src/renderer/__tests__/shortcut-recorder.test.ts
new file mode 100644
index 0000000..9fc0d10
--- /dev/null
+++ b/apps/desktop/src/renderer/__tests__/shortcut-recorder.test.ts
@@ -0,0 +1,24 @@
+import type React from 'react';
+import { describe, expect, it } from 'vitest';
+import { accelerator } from '../ShortcutRecorder';
+
+const press = (key: string, held: Partial<Record<'ctrlKey' | 'altKey' | 'shiftKey' | 'metaKey', boolean>> = {}) =>
+ ({ key, ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, ...held }) as React.KeyboardEvent;
+
+describe('accelerator', () => {
+ it('names a held combination the way Electron does', () => {
+ expect(accelerator(press('s', { ctrlKey: true, shiftKey: true }))).toBe('Control+Shift+S');
+ expect(accelerator(press('r', { altKey: true, shiftKey: true }))).toBe('Alt+Shift+R');
+ expect(accelerator(press('F9', { ctrlKey: true }))).toBe('Control+F9');
+ });
+
+ it('refuses anything that would steal a bare key', () => {
+ expect(accelerator(press('s'))).toBeNull();
+ expect(accelerator(press('Enter'))).toBeNull();
+ });
+
+ it('ignores a modifier pressed on its own', () => {
+ expect(accelerator(press('Shift', { shiftKey: true }))).toBeNull();
+ expect(accelerator(press('Control', { ctrlKey: true }))).toBeNull();
+ });
+});
diff --git a/src/locales/de.yml b/src/locales/de.yml
index 7d69305..ff3e382 100644
--- a/src/locales/de.yml
+++ b/src/locales/de.yml
@@ -180,6 +180,18 @@ desktop:
startButton: Starten
guideCount: $1 Anleitung
guideCountPlural: $1 Anleitungen
+ shortcutsSection: "Tastenkürzel"
+ captureKeys: "Kürzel und benannte Tasten aufzeichnen"
+ captureTyping: "Eingaben aufzeichnen"
+ typingDebounce: "Eingabeschritt beenden nach"
+ typingSmart: "Den Feldtext lesen, wenn möglich"
+ typingSmartHint: "Andernfalls werden die Tastenanschläge aufgezeichnet"
+ shortcutStartStop: "Aufnahme starten oder beenden"
+ shortcutPauseResume: "Pausieren oder fortsetzen"
+ shortcutCapture: "Jetzt einen Schritt aufnehmen"
+ shortcutPress: "Tasten drücken…"
+ shortcutClear: "Löschen"
+ shortcutTaken: "Eine andere Anwendung nutzt diese Taste bereits"
fullview:
allGuides: Alle Anleitungen
diff --git a/src/locales/en.yml b/src/locales/en.yml
index 819c718..a5f4819 100644
--- a/src/locales/en.yml
+++ b/src/locales/en.yml
@@ -180,6 +180,18 @@ desktop:
startButton: Start
guideCount: $1 guide
guideCountPlural: $1 guides
+ shortcutsSection: "Shortcuts"
+ captureKeys: "Record shortcuts and named keys"
+ captureTyping: "Record what you type"
+ typingDebounce: "Close a typing step after"
+ typingSmart: "Read the field's own text when it can"
+ typingSmartHint: "Off means the guide records your keystrokes instead"
+ shortcutStartStop: "Start or finish a recording"
+ shortcutPauseResume: "Pause or resume"
+ shortcutCapture: "Capture a step now"
+ shortcutPress: "Press keys…"
+ shortcutClear: "Clear"
+ shortcutTaken: "Another application already owns this key"
fullview:
allGuides: All Guides
diff --git a/src/locales/es.yml b/src/locales/es.yml
index 907e664..467a77a 100644
--- a/src/locales/es.yml
+++ b/src/locales/es.yml
@@ -180,6 +180,18 @@ desktop:
startButton: Iniciar
guideCount: $1 guía
guideCountPlural: $1 guías
+ shortcutsSection: "Atajos"
+ captureKeys: "Registrar atajos y teclas con nombre"
+ captureTyping: "Registrar lo que escribes"
+ typingDebounce: "Cerrar el paso de escritura tras"
+ typingSmart: "Leer el texto del propio campo cuando se pueda"
+ typingSmartHint: "Si se desactiva, la guía registra tus pulsaciones"
+ shortcutStartStop: "Iniciar o finalizar una grabación"
+ shortcutPauseResume: "Pausar o reanudar"
+ shortcutCapture: "Capturar un paso ahora"
+ shortcutPress: "Pulsa las teclas…"
+ shortcutClear: "Borrar"
+ shortcutTaken: "Otra aplicación ya usa esta tecla"
fullview:
allGuides: Todas las guías
diff --git a/src/locales/fr.yml b/src/locales/fr.yml
index 0da3ae5..92fa517 100644
--- a/src/locales/fr.yml
+++ b/src/locales/fr.yml
@@ -180,6 +180,18 @@ desktop:
startButton: Démarrer
guideCount: $1 guide
guideCountPlural: $1 guides
+ shortcutsSection: "Raccourcis"
+ captureKeys: "Enregistrer les raccourcis et touches nommées"
+ captureTyping: "Enregistrer ce que vous tapez"
+ typingDebounce: "Clôturer l'étape de saisie après"
+ typingSmart: "Lire le texte du champ lorsque c’est possible"
+ typingSmartHint: "Sinon, le guide enregistre vos frappes"
+ shortcutStartStop: "Démarrer ou terminer un enregistrement"
+ shortcutPauseResume: "Mettre en pause ou reprendre"
+ shortcutCapture: "Capturer une étape maintenant"
+ shortcutPress: "Appuyez sur les touches…"
+ shortcutClear: "Effacer"
+ shortcutTaken: "Une autre application utilise déjà cette touche"
fullview:
allGuides: Tous les guides
diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.yml
index 2af8dae..f8d46c3 100644
--- a/src/locales/pt-BR.yml
+++ b/src/locales/pt-BR.yml
@@ -180,6 +180,18 @@ desktop:
startButton: Iniciar
guideCount: $1 guia
guideCountPlural: $1 guias
+ shortcutsSection: "Atalhos"
+ captureKeys: "Registrar atalhos e teclas nomeadas"
+ captureTyping: "Registrar o que você digita"
+ typingDebounce: "Encerrar a etapa de digitação após"
+ typingSmart: "Ler o texto do próprio campo quando possível"
+ typingSmartHint: "Se desligado, o guia registra suas teclas"
+ shortcutStartStop: "Iniciar ou finalizar uma gravação"
+ shortcutPauseResume: "Pausar ou retomar"
+ shortcutCapture: "Capturar uma etapa agora"
+ shortcutPress: "Pressione as teclas…"
+ shortcutClear: "Limpar"
+ shortcutTaken: "Outro aplicativo já usa esta tecla"
fullview:
allGuides: Todos os guias
diff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.yml
index 524802d..354e0e0 100644
--- a/src/locales/zh-CN.yml
+++ b/src/locales/zh-CN.yml
@@ -180,6 +180,18 @@ desktop:
startButton: 开始
guideCount: $1 个指南
guideCountPlural: $1 个指南
+ shortcutsSection: "快捷键"
+ captureKeys: "记录快捷键和命名按键"
+ captureTyping: "记录输入内容"
+ typingDebounce: "输入步骤结束延迟"
+ typingSmart: "尽可能读取输入框自身的文本"
+ typingSmartHint: "关闭时改为记录按键"
+ shortcutStartStop: "开始或结束录制"
+ shortcutPauseResume: "暂停或继续"
+ shortcutCapture: "立即捕获一步"
+ shortcutPress: "请按下按键…"
+ shortcutClear: "清除"
+ shortcutTaken: "其他应用已占用该按键"
fullview:
allGuides: 全部指南