🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots 📖
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
feat(desktop): frame a capture by the window, the screen or a drawn area
Luis Ortizf621e6bc7002
diff --git a/apps/desktop/src/main/capture/focused-window.ts b/apps/desktop/src/main/capture/focused-window.tsindex ffc5bf6..da14b45 100644--- a/apps/desktop/src/main/capture/focused-window.ts+++ b/apps/desktop/src/main/capture/focused-window.ts@@ -1,3 +1,5 @@+import { screen } from 'electron';+export interface FocusedWindow {title: string | null;app: { name: string; id?: string };@@ -15,6 +17,16 @@ function classify(message: string): Exclude<FocusedWindowResult, { ok: true }>['return 'unknown';}+function toDip(bounds: FocusedWindow['bounds']): FocusedWindow['bounds'] {+ if (!bounds || bounds.width <= 0 || bounds.height <= 0) return null;+ if (process.platform !== 'win32' || typeof screen.screenToDipRect !== 'function') return bounds;+ try {+ return screen.screenToDipRect(null, bounds);+ } catch {+ return bounds;+ }+}+export async function focusedWindow(): Promise<FocusedWindowResult> {if (process.platform === 'linux' && process.env.XDG_SESSION_TYPE === 'wayland') {return {@@ -33,7 +45,7 @@ export async function focusedWindow(): Promise<FocusedWindowResult> {window: {title: found.title || null,app: { name: found.owner.name, id: 'bundleId' in found.owner ? found.owner.bundleId : found.owner.path },- bounds: found.bounds ?? null,+ bounds: toDip(found.bounds ?? null),},};} catch (error) {diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.tsindex 70f1034..696b532 100644--- a/apps/desktop/src/main/capture/recorder.ts+++ b/apps/desktop/src/main/capture/recorder.ts@@ -7,7 +7,7 @@ import { type InputAction, InputHook } from './input-hook';import type { Region } from './region';import { type Capture, captureArea, type Rect } from './screenshot';import { writeScreenshot } from './screenshot-store';-import { type CaptureSettings, DEFAULT_CAPTURE_SETTINGS } from './settings';+import { type CaptureMode, type CaptureSettings, DEFAULT_CAPTURE_SETTINGS } from './settings';const TARGET_SIZE = 28;const SETTLE_MS = 60;@@ -42,9 +42,22 @@ function inside(region: Region, point: { x: number; y: number }): boolean {}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;}+export function frameFor(+ mode: CaptureMode,+ point: { x: number; y: number },+ region: Region,+ window: Rect | null,+): Rect {+ const display = screen.getDisplayNearestPoint(point).bounds;+ if (mode === 'screen') return display;+ if (mode === 'window') return window && inside(window, point) ? window : display;+ return inside(region, point) ? region : display;+}+export class DesktopRecorder {private hook = new InputHook();private queue: Promise<unknown> = Promise.resolve();@@ -57,6 +70,7 @@ export class DesktopRecorder {private readonly send: (request: CaptureRequest) => Promise<unknown>,private readonly grab: (area: Rect) => Promise<Capture> = captureArea,private readonly settings: () => CaptureSettings = () => DEFAULT_CAPTURE_SETTINGS,+ private readonly ignores: (point: { x: number; y: number }) => boolean = () => false,) {}async start(): Promise<RecorderStart> {@@ -89,6 +103,7 @@ export class DesktopRecorder {private onAction(action: InputAction): void {if (action.kind !== 'click' || !this.isRecording) return;const point = { x: action.x, y: action.y };+ if (this.ignores(point)) return;if (!shouldCapture(this.settings(), this.region(), point)) return;this.enqueue(point);}@@ -103,8 +118,8 @@ export class DesktopRecorder {async capture(point: { x: number; y: number }): Promise<void> {const settings = this.settings();- const region = this.region();- const framed = inside(region, point) ? region : screen.getDisplayNearestPoint(point).bounds;+ const found = await focusedWindow();+ const framed = frameFor(settings.captureMode, point, this.region(), found.ok ? found.window.bounds : null);const shot = await this.withHidden(async () => {await delay(SETTLE_MS + settings.screenshotDelayMs);@@ -114,7 +129,6 @@ export class DesktopRecorder {const screenshotId = randomUUID();const local = { x: point.x - framed.x, y: point.y - framed.y };- const found = await focusedWindow();await this.send({action: 'click',diff --git a/apps/desktop/src/main/capture/settings.ts b/apps/desktop/src/main/capture/settings.tsindex 187eb90..37eb3cb 100644--- a/apps/desktop/src/main/capture/settings.ts+++ b/apps/desktop/src/main/capture/settings.ts@@ -3,11 +3,14 @@ import { join } from 'node:path';import { app } from 'electron';export type CursorStyle = 'arrow' | 'hand' | 'dot';+export type CaptureMode = 'window' | 'screen' | 'region';export const CURSOR_STYLES: CursorStyle[] = ['arrow', 'hand', 'dot'];+export const CAPTURE_MODES: CaptureMode[] = ['window', 'screen', 'region'];export const MAX_SCREENSHOT_DELAY_MS = 2000;export interface CaptureSettings {+ captureMode: CaptureMode;showCursor: boolean;cursorStyle: CursorStyle;screenshotDelayMs: number;@@ -15,6 +18,7 @@ export interface CaptureSettings {}export const DEFAULT_CAPTURE_SETTINGS: CaptureSettings = {+ captureMode: 'window',showCursor: true,cursorStyle: process.platform === 'darwin' ? 'arrow' : process.platform === 'win32' ? 'arrow' : 'dot',screenshotDelayMs: 0,@@ -28,6 +32,9 @@ function file(): string {export function normaliseSettings(input: Partial<CaptureSettings>): CaptureSettings {const delay = Number(input.screenshotDelayMs);return {+ captureMode: CAPTURE_MODES.includes(input.captureMode as CaptureMode)+ ? (input.captureMode as CaptureMode)+ : DEFAULT_CAPTURE_SETTINGS.captureMode,showCursor: typeof input.showCursor === 'boolean' ? input.showCursor : DEFAULT_CAPTURE_SETTINGS.showCursor,cursorStyle: CURSOR_STYLES.includes(input.cursorStyle as CursorStyle)? (input.cursorStyle as CursorStyle)diff --git a/apps/desktop/src/renderer/SettingsPanel.tsx b/apps/desktop/src/renderer/SettingsPanel.tsxindex ee59454..f13950f 100644--- a/apps/desktop/src/renderer/SettingsPanel.tsx+++ b/apps/desktop/src/renderer/SettingsPanel.tsx@@ -1,9 +1,14 @@-import { useEffect, useState } from 'react';import { i18n } from '@mimik/core/env';-import type { CaptureSettings } from '../main/capture/settings';import { Button } from '@mimik/ui/components/ui/button';+import { useEffect, useState } from 'react';+import type { CaptureSettings } from '../main/capture/settings';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' },+];export default function SettingsPanel({ onClose }: { onClose(): void }) {const [settings, setSettings] = useState<CaptureSettings | null>(null);@@ -31,6 +36,21 @@ export default function SettingsPanel({ onClose }: { onClose(): void }) {{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"><inputtype="checkbox"@@ -70,17 +90,18 @@ export default function SettingsPanel({ onClose }: { onClose(): void }) {<span className="text-muted-foreground">{i18n.t('desktop_milliseconds')}</span></label>- <label className="flex items-center gap-3 text-sm text-foreground">- <input- type="checkbox"- checked={settings.captureOutsideClicks}- onChange={(e) => save({ captureOutsideClicks: e.target.checked })}- />- {i18n.t('desktop_captureOutside')}- </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 })}+ />+ {i18n.t('desktop_captureOutside')}+ </label>+ )}</section>)}-</div>);}diff --git a/src/locales/de.yml b/src/locales/de.ymlindex 32c9e5a..8470752 100644--- a/src/locales/de.yml+++ b/src/locales/de.yml@@ -171,6 +171,15 @@ desktop:newGuide: New GuidecapturingSection: Capturingmilliseconds: ms+ captureMode: Was aufnehmen+ modeWindow: Aktives Fenster+ modeScreen: Vollbild+ modeRegion: Ausgewählter Bereich+ readyToRecord: Bereit zur Aufnahme+ startSheetTitle: Aufnahme starten+ startButton: Starten+ guideCount: $1 Anleitung+ guideCountPlural: $1 Anleitungenfullview:allGuides: Alle Anleitungendiff --git a/src/locales/en.yml b/src/locales/en.ymlindex 12b338b..35fbe47 100644--- a/src/locales/en.yml+++ b/src/locales/en.yml@@ -171,6 +171,15 @@ desktop:newGuide: New GuidecapturingSection: Capturingmilliseconds: ms+ captureMode: What to capture+ modeWindow: Active Window+ modeScreen: Full Screen+ modeRegion: Selected Region+ readyToRecord: Ready to record+ startSheetTitle: Start a capture+ startButton: Start+ guideCount: $1 guide+ guideCountPlural: $1 guidesfullview:allGuides: All Guidesdiff --git a/src/locales/es.yml b/src/locales/es.ymlindex dd69f40..c8f7e6f 100644--- a/src/locales/es.yml+++ b/src/locales/es.yml@@ -171,6 +171,15 @@ desktop:newGuide: New GuidecapturingSection: Capturingmilliseconds: ms+ captureMode: Qué capturar+ modeWindow: Ventana activa+ modeScreen: Pantalla completa+ modeRegion: Región seleccionada+ readyToRecord: Listo para grabar+ startSheetTitle: Iniciar una captura+ startButton: Iniciar+ guideCount: $1 guía+ guideCountPlural: $1 guíasfullview:allGuides: Todas las guíasdiff --git a/src/locales/fr.yml b/src/locales/fr.ymlindex b98abd1..d382943 100644--- a/src/locales/fr.yml+++ b/src/locales/fr.yml@@ -171,6 +171,15 @@ desktop:newGuide: New GuidecapturingSection: Capturingmilliseconds: ms+ captureMode: Quoi capturer+ modeWindow: Fenêtre active+ modeScreen: Plein écran+ modeRegion: Région sélectionnée+ readyToRecord: Prêt à enregistrer+ startSheetTitle: Démarrer une capture+ startButton: Démarrer+ guideCount: $1 guide+ guideCountPlural: $1 guidesfullview:allGuides: Tous les guidesdiff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.ymlindex dee77c1..59ac2b3 100644--- a/src/locales/pt-BR.yml+++ b/src/locales/pt-BR.yml@@ -171,6 +171,15 @@ desktop:newGuide: New GuidecapturingSection: Capturingmilliseconds: ms+ captureMode: O que capturar+ modeWindow: Janela ativa+ modeScreen: Tela inteira+ modeRegion: Região selecionada+ readyToRecord: Pronto para gravar+ startSheetTitle: Iniciar uma captura+ startButton: Iniciar+ guideCount: $1 guia+ guideCountPlural: $1 guiasfullview:allGuides: Todos os guiasdiff --git a/src/locales/zh-CN.yml b/src/locales/zh-CN.ymlindex ebc6f3f..165fa5b 100644--- a/src/locales/zh-CN.yml+++ b/src/locales/zh-CN.yml@@ -171,6 +171,15 @@ desktop:newGuide: New GuidecapturingSection: Capturingmilliseconds: ms+ captureMode: 捕获范围+ modeWindow: 活动窗口+ modeScreen: 整个屏幕+ modeRegion: 选定区域+ readyToRecord: 可以开始录制+ startSheetTitle: 开始捕获+ startButton: 开始+ guideCount: $1 个指南+ guideCountPlural: $1 个指南fullview:allGuides: 全部指南