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 πŸ“–

refactor: give the + between steps one capture-more prop and the extension's insert field names

Luis Ortizdf26e7db0cf8
diff --git a/apps/desktop/scripts/check-pipeline.ts b/apps/desktop/scripts/check-pipeline.ts
index 1088208..9bf44ea 100644
--- a/apps/desktop/scripts/check-pipeline.ts
+++ b/apps/desktop/scripts/check-pipeline.ts
@@ -709,7 +709,7 @@ app.whenReady().then(async () => {
const before = await ask<string | null>(win.webContents, 'mimik:check:title', target, 20_000);
const staging = await ask<string>(app_.webContents, 'mimik:capture:createGuide', { staging: true }, 20_000);
await labelled(staging, 'Second');
- await ask(app_.webContents, 'mimik:capture:mergeGuideInto', { guideId: staging, targetGuideId: target, atIndex: 1 }, 20_000);
+ await ask(app_.webContents, 'mimik:capture:mergeGuideInto', { guideId: staging, insertTargetGuideId: target, insertAtIndex: 1 }, 20_000);
const order = (await ask<string[] | null>(win.webContents, 'mimik:check:steps', target, 20_000)) ?? [];
const left = await ask<string[] | null>(win.webContents, 'mimik:check:steps', staging, 20_000);
const after = await ask<string | null>(win.webContents, 'mimik:check:title', target, 20_000);
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 26c8585..a68ffc3 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -1,5 +1,6 @@
import { readFile } from 'node:fs/promises';
import { basename, join } from 'node:path';
+import type { CaptureInsert } from '@mimik/core/capture/capture-insert';
import { isLive } from '@mimik/core/capture/is-live';
import { CaptureState, captureMachine } from '@mimik/core/capture/machine';
import { app, BrowserWindow, dialog, ipcMain, Menu, nativeImage, protocol, screen, shell, Tray } from 'electron';
@@ -8,7 +9,6 @@ import { shortcutLabel } from '../renderer/lib/shortcut-label';
import { registerAiFetch } from './ai-fetch';
import { APP_ICON_SCHEME, registerAppIconProtocol } from './app-icon';
import { ask } from './ask';
-import type { CaptureInsert } from './capture/insert';
import { DesktopRecorder, frameFor } from './capture/recorder';
import { grabDisplay } from './capture/screenshot';
import { registerScreenshotProtocol, SCREENSHOT_SCHEME, sweepScreenshots } from './capture/screenshot-store';
@@ -366,10 +366,14 @@ async function onOverlayCommand(command: OverlayCommand): Promise<void> {
await ask(
mainWindow?.webContents ?? null,
'mimik:capture:mergeGuideInto',
- { guideId: currentGuideId, targetGuideId: target.guideId, atIndex: target.atIndex },
+ {
+ guideId: currentGuideId,
+ insertTargetGuideId: target.insertTargetGuideId,
+ insertAtIndex: target.insertAtIndex,
+ },
45_000,
).catch(() => undefined);
- if (steps.length > 0) finished = target.guideId;
+ if (steps.length > 0) finished = target.insertTargetGuideId;
} else if (currentGuideId) {
finished = currentGuideId;
void ask(mainWindow?.webContents ?? null, 'mimik:capture:finishGuide', finished, 45_000).catch(() => undefined);
@@ -450,7 +454,7 @@ if (!app.requestSingleInstanceLock()) {
(command) => void onOverlayCommand(command),
() => (captureSettings ?? loadSettings()).captureMode,
{
- insert: () => (insert ? { insertTargetGuideId: insert.guideId, insertAtIndex: insert.atIndex } : null),
+ insert: () => insert,
introFrame: async () => {
const { captureMode } = captureSettings ?? loadSettings();
const region = overlay?.region ?? { x: 0, y: 0, width: 0, height: 0 };
diff --git a/apps/desktop/src/main/overlay/index.ts b/apps/desktop/src/main/overlay/index.ts
index acce825..bdd8fc1 100644
--- a/apps/desktop/src/main/overlay/index.ts
+++ b/apps/desktop/src/main/overlay/index.ts
@@ -1,5 +1,6 @@
import { join } from 'node:path';
import type { AiFailureReason } from '@mimik/core/capture/ai/errors';
+import type { CaptureInsert } from '@mimik/core/capture/capture-insert';
import {
CaptureState,
type CaptureStateValue,
@@ -89,7 +90,7 @@ export interface OverlayView {
export interface OverlayOptions {
introFrame?: () => Promise<Region>;
- insert?: () => { insertTargetGuideId: string; insertAtIndex: number } | null;
+ insert?: () => CaptureInsert | null;
shortcuts?: () => OverlayShortcuts;
}
@@ -410,7 +411,12 @@ export class CaptureOverlay {
const finished = await this.playIntro(frame);
this.starting = false;
if (!finished || this.state !== CaptureState.ARMED) return;
- this.capture.send({ type: 'START_RECORDING', ...(this.options.insert?.() ?? {}) });
+ const target = this.options.insert?.();
+ this.capture.send({
+ type: 'START_RECORDING',
+ insertTargetGuideId: target?.insertTargetGuideId,
+ insertAtIndex: target?.insertAtIndex,
+ });
this.onCommand('start');
}
diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts
index 8685b9a..9e68625 100644
--- a/apps/desktop/src/preload/index.ts
+++ b/apps/desktop/src/preload/index.ts
@@ -1,5 +1,5 @@
+import type { CaptureInsert } from '@mimik/core/capture/capture-insert';
import { contextBridge, ipcRenderer } from 'electron';
-import type { CaptureInsert } from '../main/capture/insert';
import type { CaptureSettings } from '../main/capture/settings';
import type { OverlayAiFailure, OverlayCommand, OverlayNarration } from '../main/overlay';
import type { CapturePermissions, MicrophoneAccess, PermissionKind } from '../main/permissions';
diff --git a/apps/desktop/src/renderer/App.tsx b/apps/desktop/src/renderer/App.tsx
index d446baa..dca5f83 100644
--- a/apps/desktop/src/renderer/App.tsx
+++ b/apps/desktop/src/renderer/App.tsx
@@ -1,3 +1,4 @@
+import type { CaptureInsert } from '@mimik/core/capture/capture-insert';
import { i18n, localStorage } from '@mimik/core/env';
import {
AppFrame,
@@ -11,7 +12,6 @@ import {
VoiceNotice,
} from '@mimik/ui';
import { useCallback, useEffect, useState } from 'react';
-import type { CaptureInsert } from '../main/capture/insert';
import { CaptureSheet } from './CaptureSheet';
import { DesktopOnboarding } from './DesktopOnboarding';
import { GuideZoom } from './GuideZoom';
diff --git a/apps/desktop/src/renderer/CaptureSheet.tsx b/apps/desktop/src/renderer/CaptureSheet.tsx
index f268956..10e6db0 100644
--- a/apps/desktop/src/renderer/CaptureSheet.tsx
+++ b/apps/desktop/src/renderer/CaptureSheet.tsx
@@ -1,8 +1,8 @@
+import type { CaptureInsert } from '@mimik/core/capture/capture-insert';
import { i18n } from '@mimik/core/env';
import { Button } from '@mimik/ui';
import { AppWindow, Crop, Monitor, Video, X } from 'lucide-react';
import { useEffect, useState } from 'react';
-import type { CaptureInsert } from '../main/capture/insert';
import type { CaptureSettings } from '../main/capture/settings';
type Mode = CaptureSettings['captureMode'];
diff --git a/apps/desktop/src/renderer/capture-host.ts b/apps/desktop/src/renderer/capture-host.ts
index 5a96aba..bfd683c 100644
--- a/apps/desktop/src/renderer/capture-host.ts
+++ b/apps/desktop/src/renderer/capture-host.ts
@@ -53,11 +53,15 @@ window.mimik.onRequest('mimik:capture:finishGuide', async (payload) => {
});
window.mimik.onRequest('mimik:capture:mergeGuideInto', async (payload) => {
- const { guideId, targetGuideId, atIndex } = payload as { guideId: string; targetGuideId: string; atIndex: number };
+ const { guideId, insertTargetGuideId, insertAtIndex } = payload as {
+ guideId: string;
+ insertTargetGuideId: string;
+ insertAtIndex: number;
+ };
await narration.settle();
await settleDescriptions(guideId);
- await createSnapshot(targetGuideId);
- await mergeGuideInto(guideId, targetGuideId, atIndex);
+ await createSnapshot(insertTargetGuideId);
+ await mergeGuideInto(guideId, insertTargetGuideId, insertAtIndex);
return true;
});
diff --git a/apps/desktop/src/main/capture/insert.ts b/packages/core/src/capture/capture-insert.ts
similarity index 50%
rename from apps/desktop/src/main/capture/insert.ts
rename to packages/core/src/capture/capture-insert.ts
index f1133af..780da55 100644
--- a/apps/desktop/src/main/capture/insert.ts
+++ b/packages/core/src/capture/capture-insert.ts
@@ -1,5 +1,5 @@
export interface CaptureInsert {
- guideId: string;
- atIndex: number;
+ insertTargetGuideId: string;
+ insertAtIndex: number;
afterStep: number;
}
diff --git a/packages/ui/src/guide/components/GuideContent.tsx b/packages/ui/src/guide/components/GuideContent.tsx
index 12109af..6532cc9 100644
--- a/packages/ui/src/guide/components/GuideContent.tsx
+++ b/packages/ui/src/guide/components/GuideContent.tsx
@@ -1,4 +1,5 @@
import { AI_CREDENTIAL_SETTINGS, resolveAiCredentials } from '@mimik/core/capture/ai/keys';
+import type { CaptureInsert } from '@mimik/core/capture/capture-insert';
import { i18n, localStorage } from '@mimik/core/env';
import { formatDate } from '@mimik/core/export/utils';
import { isReplayable } from '@mimik/core/guideme/session';
@@ -33,13 +34,14 @@ import { VersionHistoryPanel } from '../../history/components/VersionHistoryPane
import { useFullview } from '../../stores/use-fullview';
import { buildPreview } from '../lib/build-preview';
import type { PreviewData } from '../types';
+import { CaptureTabDialog } from './CaptureTabDialog';
import { GuideStepList } from './GuideStepList';
interface GuideContentProps {
guideId: string;
initialStepId?: string;
initialTool?: 'annotate' | 'redact' | 'crop' | 'target';
- onCaptureMore?: (target: { guideId: string; atIndex: number; afterStep: number }) => void;
+ onCaptureMore?: (target: CaptureInsert) => void;
}
interface GuideData {
@@ -78,6 +80,7 @@ export function GuideContent({ guideId, initialStepId, initialTool, onCaptureMor
}));
const [data, setData] = useState<GuideData | null>(null);
+ const [pendingInsert, setPendingInsert] = useState<CaptureInsert | null>(null);
const [loading, setLoading] = useState(true);
const [title, setTitle] = useState('');
const [typingTitle, setTypingTitle] = useState<string | null>(null);
@@ -472,14 +475,22 @@ export function GuideContent({ guideId, initialStepId, initialTool, onCaptureMor
readOnly={!editing || preview !== null}
hasApiKey={desc.hasApiKey}
onChanged={loadGuide}
- onInsertRecording={(targetGuideId, insertAtIndex, tabId) => {
- panel.open();
- void tabs.startInsertRecording(targetGuideId, insertAtIndex, tabId);
- }}
- onCaptureMore={onCaptureMore && ((atIndex, afterStep) => onCaptureMore({ guideId, atIndex, afterStep }))}
+ onCaptureMore={onCaptureMore ?? setPendingInsert}
/>
</div>
+ <CaptureTabDialog
+ open={pendingInsert !== null}
+ onCancel={() => setPendingInsert(null)}
+ onStart={(tabId) => {
+ const target = pendingInsert;
+ setPendingInsert(null);
+ if (!target) return;
+ panel.open();
+ void tabs.startInsertRecording(target.insertTargetGuideId, target.insertAtIndex, tabId);
+ }}
+ />
+
{transcriptOpen && (
<TranscriptPanel
guideId={guideId}
diff --git a/packages/ui/src/guide/components/GuideStepList.tsx b/packages/ui/src/guide/components/GuideStepList.tsx
index 4665f4b..2540397 100644
--- a/packages/ui/src/guide/components/GuideStepList.tsx
+++ b/packages/ui/src/guide/components/GuideStepList.tsx
@@ -1,3 +1,4 @@
+import type { CaptureInsert } from '@mimik/core/capture/capture-insert';
import { i18n } from '@mimik/core/env';
import { isBlock, stepNumbers } from '@mimik/core/guides/blocks';
import { createSnapshot, deleteSteps, insertBlock, reorderSteps } from '@mimik/core/guides/service';
@@ -10,7 +11,6 @@ import { ConfirmDialog } from '../../common/components/ConfirmDialog';
import { Button } from '../../components/ui/button';
import { useFullview } from '../../stores/use-fullview';
import { BlockCard } from './BlockCard';
-import { CaptureTabDialog } from './CaptureTabDialog';
import { EmptyGuideState } from './EmptyGuideState';
import { InsertBlockMenu } from './InsertBlockMenu';
import { StepCard } from './StepCard';
@@ -26,8 +26,7 @@ interface GuideStepListProps {
readOnly?: boolean;
onChanged?: () => void;
hasApiKey?: boolean;
- onInsertRecording?: (guideId: string, insertAtIndex: number, tabId: number) => void;
- onCaptureMore?: (atIndex: number, afterStep: number) => void;
+ onCaptureMore?: (target: CaptureInsert) => void;
}
export function GuideStepList({
@@ -41,7 +40,6 @@ export function GuideStepList({
readOnly,
onChanged,
hasApiKey,
- onInsertRecording,
onCaptureMore,
}: GuideStepListProps) {
const { scrollToStepId, setActiveStepId, bumpHistoryRefresh } = useFullview((s) => ({
@@ -50,7 +48,6 @@ export function GuideStepList({
bumpHistoryRefresh: s.bumpHistoryRefresh,
}));
- const [recordAtIndex, setRecordAtIndex] = useState<number | null>(null);
const [dragIndex, setDragIndex] = useState<number | null>(null);
const [dragOverIndex, setDragOverIndex] = useState<number | null>(null);
const [selected, setSelected] = useState<Set<string>>(new Set());
@@ -59,13 +56,14 @@ export function GuideStepList({
const stepRefs = useRef<Map<string, HTMLDivElement>>(new Map());
const frameRatio = dominantRatio(screenshots);
const numbers = stepNumbers(steps);
- const recordAt =
- onCaptureMore || onInsertRecording
- ? (atIndex: number) => () =>
- onCaptureMore
- ? onCaptureMore(atIndex, steps.slice(0, atIndex).filter((step) => !isBlock(step)).length)
- : setRecordAtIndex(atIndex)
- : undefined;
+ const recordAt = onCaptureMore
+ ? (atIndex: number) => () =>
+ onCaptureMore({
+ insertTargetGuideId: guideId,
+ insertAtIndex: atIndex,
+ afterStep: steps.slice(0, atIndex).filter((step) => !isBlock(step)).length,
+ })
+ : undefined;
useEffect(() => {
if (scrollToStepId) {
@@ -159,18 +157,6 @@ export function GuideStepList({
onDragEnd: handleDragEnd,
};
- const captureDialog = (
- <CaptureTabDialog
- open={recordAtIndex !== null}
- onCancel={() => setRecordAtIndex(null)}
- onStart={(tabId) => {
- const atIndex = recordAtIndex;
- setRecordAtIndex(null);
- if (atIndex !== null) onInsertRecording?.(guideId, atIndex, tabId);
- }}
- />
- );
-
if (steps.length === 0) {
return (
<div className="flex flex-col">
@@ -178,7 +164,6 @@ export function GuideStepList({
{!readOnly && (
<InsertBlockMenu onInsert={(blockType) => handleInsertBlock(0, blockType)} onRecord={recordAt?.(0)} />
)}
- {captureDialog}
</div>
);
}
@@ -247,7 +232,6 @@ export function GuideStepList({
)}
</div>
))}
- {captureDialog}
{selected.size > 0 && (
<div className="fixed bottom-6 left-1/2 -translate-x-1/2 z-40 flex items-center gap-3 rounded-full border border-border bg-card px-4 py-2 shadow-lg">
<span className="text-[12px] font-medium text-foreground">