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(capture): add a tab picker for capturing more steps

Luis Ortiz2e9c19e366ca
diff --git a/src/core/capture/recordable-tabs.ts b/src/core/capture/recordable-tabs.ts
new file mode 100644
index 0000000..6a144b4
--- /dev/null
+++ b/src/core/capture/recordable-tabs.ts
@@ -0,0 +1,27 @@
+import { queryTabs } from '@/lib/browser-api';
+
+const WEBSTORE_PREFIX = 'https://chrome.google.com/webstore';
+
+export interface RecordableTab {
+ id: number;
+ title: string;
+ url: string;
+ favIconUrl?: string;
+}
+
+export function isRecordableUrl(url: string | undefined): boolean {
+ if (!url || url.startsWith(WEBSTORE_PREFIX)) return false;
+ return /^https?:/.test(url);
+}
+
+export async function getRecordableTabs(): Promise<RecordableTab[]> {
+ const tabs = await queryTabs({ currentWindow: true });
+ return tabs
+ .filter((tab) => tab.id !== undefined && isRecordableUrl(tab.url || tab.pendingUrl))
+ .map((tab) => ({
+ id: tab.id as number,
+ title: tab.title || ((tab.url || tab.pendingUrl) as string),
+ url: (tab.url || tab.pendingUrl) as string,
+ favIconUrl: tab.favIconUrl,
+ }));
+}
diff --git a/src/core/capture/start-insert-recording.ts b/src/core/capture/start-insert-recording.ts
new file mode 100644
index 0000000..8f09e95
--- /dev/null
+++ b/src/core/capture/start-insert-recording.ts
@@ -0,0 +1,36 @@
+import { focusWindow, getTab, requestHostPermissions, updateTab } from '@/lib/browser-api';
+import { logger } from '@/lib/logger';
+import { sendMessage } from '@/lib/messaging';
+import { isRecordableUrl } from './recordable-tabs';
+
+export async function startInsertRecording(
+ guideId: string,
+ insertAtIndex: number,
+ tabId: number,
+): Promise<string | null> {
+ if (!(await requestHostPermissions())) {
+ logger.warn('Host permissions not granted, cannot start recording');
+ return null;
+ }
+
+ const tab = await getTab(tabId).catch(() => null);
+ if (!isRecordableUrl(tab?.url || tab?.pendingUrl)) {
+ logger.warn('Selected tab can no longer be recorded');
+ return null;
+ }
+
+ await updateTab(tabId, { active: true });
+ if (tab?.windowId) await focusWindow(tab.windowId);
+
+ try {
+ const res = await sendMessage('startRecording', {
+ url: tab?.url || '',
+ insertTargetGuideId: guideId,
+ insertAtIndex,
+ });
+ return res.guideId ?? null;
+ } catch (err) {
+ logger.error(' START_RECORDING error', err);
+ return null;
+ }
+}
diff --git a/src/locales/de.yml b/src/locales/de.yml
index b1f09a6..6a178b5 100644
--- a/src/locales/de.yml
+++ b/src/locales/de.yml
@@ -189,6 +189,13 @@ editor:
descriptionErrorSaveFailed: Die Beschreibung wurde erstellt, konnte aber nicht gespeichert werden. Versuche es erneut.
writingStepDescription: "Beschreibung wird geschrieben…"
+capture:
+ recordSteps: Schritte aufzeichnen
+ moreStepsTitle: Weitere Schritte aufnehmen
+ moreStepsBody: "Neue Schritte werden hier eingefügt. Wähle den Tab zum Aufzeichnen."
+ startCapture: Aufnahme starten
+ noRecordableTabs: In diesem Fenster ist kein aufzeichenbarer Tab offen.
+
blocks:
add: "Block hinzufügen"
heading: "Überschrift"
diff --git a/src/locales/en.yml b/src/locales/en.yml
index c39484a..07cdd3f 100644
--- a/src/locales/en.yml
+++ b/src/locales/en.yml
@@ -189,6 +189,13 @@ editor:
rewriteErrorFailed: Could not rewrite the selection. Try again.
rewriteErrorStale: The text changed. Select it again.
+capture:
+ recordSteps: Record steps
+ moreStepsTitle: Capture more steps
+ moreStepsBody: New steps are inserted here. Pick the tab to record in.
+ startCapture: Start capture
+ noRecordableTabs: No recordable tabs are open in this window.
+
blocks:
add: Add block
heading: Heading
diff --git a/src/locales/es.yml b/src/locales/es.yml
index 102055c..f5ba7c4 100644
--- a/src/locales/es.yml
+++ b/src/locales/es.yml
@@ -189,6 +189,13 @@ editor:
rewriteErrorFailed: "No se pudo reescribir la selecci\xF3n. Int\xE9ntalo de nuevo."
rewriteErrorStale: "El texto cambi\xF3. Vuelve a seleccionarlo."
+capture:
+ recordSteps: Grabar pasos
+ moreStepsTitle: Capturar más pasos
+ moreStepsBody: "Los nuevos pasos se insertan aquí. Elige la pestaña que quieres grabar."
+ startCapture: Iniciar captura
+ noRecordableTabs: No hay pestañas grabables abiertas en esta ventana.
+
blocks:
add: "Añadir bloque"
heading: Encabezado
diff --git a/src/locales/fr.yml b/src/locales/fr.yml
index 07ff767..2b4b9ba 100644
--- a/src/locales/fr.yml
+++ b/src/locales/fr.yml
@@ -189,6 +189,13 @@ editor:
rewriteErrorFailed: "Impossible de r\xE9\xE9crire la s\xE9lection. R\xE9essayez."
rewriteErrorStale: "Le texte a chang\xE9. S\xE9lectionnez-le \xE0 nouveau."
+capture:
+ recordSteps: "Enregistrer des étapes"
+ moreStepsTitle: "Capturer d'autres étapes"
+ moreStepsBody: "Les nouvelles étapes sont insérées ici. Choisissez l'onglet à enregistrer."
+ startCapture: "Démarrer la capture"
+ noRecordableTabs: "Aucun onglet enregistrable n'est ouvert dans cette fenêtre."
+
blocks:
add: Ajouter un bloc
heading: Titre
diff --git a/src/locales/pt-BR.yml b/src/locales/pt-BR.yml
index df7fa98..33eaffa 100644
--- a/src/locales/pt-BR.yml
+++ b/src/locales/pt-BR.yml
@@ -189,6 +189,13 @@ editor:
rewriteErrorFailed: "N\xE3o foi poss\xEDvel reescrever a sele\xE7\xE3o. Tente novamente."
rewriteErrorStale: O texto mudou. Selecione-o novamente.
+capture:
+ recordSteps: Gravar etapas
+ moreStepsTitle: Capturar mais etapas
+ moreStepsBody: "As novas etapas entram aqui. Escolha a aba que quer gravar."
+ startCapture: Iniciar captura
+ noRecordableTabs: Nenhuma aba gravável está aberta nesta janela.
+
blocks:
add: Adicionar bloco
heading: "Título"
diff --git a/src/ui/shared/CaptureTabDialog.tsx b/src/ui/shared/CaptureTabDialog.tsx
new file mode 100644
index 0000000..c327379
--- /dev/null
+++ b/src/ui/shared/CaptureTabDialog.tsx
@@ -0,0 +1,73 @@
+import { Globe } from 'lucide-react';
+import { useEffect, useState } from 'react';
+import { i18n } from '#imports';
+import { getRecordableTabs, type RecordableTab } from '@/core/capture/recordable-tabs';
+import { Button } from '@/ui/components/ui/button';
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from '@/ui/components/ui/dialog';
+
+interface CaptureTabDialogProps {
+ open: boolean;
+ onCancel: () => void;
+ onStart: (tabId: number) => void;
+}
+
+export default function CaptureTabDialog({ open, onCancel, onStart }: CaptureTabDialogProps) {
+ const [tabs, setTabs] = useState<RecordableTab[]>([]);
+ const [selected, setSelected] = useState<number | null>(null);
+
+ useEffect(() => {
+ if (!open) return;
+ setSelected(null);
+ getRecordableTabs().then(setTabs);
+ }, [open]);
+
+ return (
+ <Dialog open={open} onOpenChange={(next) => !next && onCancel()}>
+ <DialogContent className="sm:max-w-[400px]">
+ <DialogHeader>
+ <DialogTitle>{i18n.t('capture.moreStepsTitle')}</DialogTitle>
+ <DialogDescription>{i18n.t('capture.moreStepsBody')}</DialogDescription>
+ </DialogHeader>
+ <div className="max-h-[240px] overflow-y-auto flex flex-col gap-1.5">
+ {tabs.length === 0 ? (
+ <p className="text-[13px] text-muted-foreground py-2">{i18n.t('capture.noRecordableTabs')}</p>
+ ) : (
+ tabs.map((tab) => (
+ <button
+ key={tab.id}
+ type="button"
+ onClick={() => setSelected(tab.id)}
+ aria-pressed={selected === tab.id}
+ className={`flex items-center gap-2 rounded-lg border px-2.5 py-2 text-left transition-colors ${
+ selected === tab.id ? 'border-accent bg-secondary' : 'border-border hover:bg-secondary'
+ }`}
+ >
+ {tab.favIconUrl ? (
+ <img src={tab.favIconUrl} alt="" width={16} height={16} className="shrink-0 rounded" />
+ ) : (
+ <Globe size={16} className="shrink-0 text-muted-foreground" />
+ )}
+ <span className="text-[13px] text-foreground truncate">{tab.title}</span>
+ </button>
+ ))
+ )}
+ </div>
+ <DialogFooter>
+ <Button variant="outline" size="sm" onClick={onCancel}>
+ {i18n.t('common.cancel')}
+ </Button>
+ <Button size="sm" disabled={selected === null} onClick={() => selected !== null && onStart(selected)}>
+ {i18n.t('capture.startCapture')}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+}