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): record inserted steps into a staging guide

Luis Ortiz3aefd5aef382
diff --git a/src/core/capture/machine.ts b/src/core/capture/machine.ts
index 94692ea..d144355 100644
--- a/src/core/capture/machine.ts
+++ b/src/core/capture/machine.ts
@@ -8,7 +8,7 @@ export const CaptureState = {
export type CaptureStateValue = (typeof CaptureState)[keyof typeof CaptureState];
type CaptureEvent =
- | { type: 'START_RECORDING'; url?: string }
+ | { type: 'START_RECORDING'; url?: string; insertTargetGuideId?: string; insertAtIndex?: number }
| { type: 'STOP_RECORDING' }
| { type: 'USER_ACTION' }
| { type: 'URL_CHANGED'; url: string };
@@ -17,6 +17,8 @@ interface CaptureContext {
currentGuideId: string | null;
stepCount: number;
currentUrl: string;
+ insertTargetGuideId: string | null;
+ insertAtIndex: number | null;
}
export const captureMachine = createMachine({
@@ -30,6 +32,8 @@ export const captureMachine = createMachine({
currentGuideId: null,
stepCount: 0,
currentUrl: '',
+ insertTargetGuideId: null,
+ insertAtIndex: null,
},
states: {
[CaptureState.IDLE]: {
@@ -40,6 +44,8 @@ export const captureMachine = createMachine({
currentGuideId: () => crypto.randomUUID(),
stepCount: 0,
currentUrl: ({ event }) => event.url ?? '',
+ insertTargetGuideId: ({ event }) => event.insertTargetGuideId ?? null,
+ insertAtIndex: ({ event }) => event.insertAtIndex ?? null,
}),
},
},
@@ -52,6 +58,8 @@ export const captureMachine = createMachine({
currentGuideId: null,
stepCount: 0,
currentUrl: '',
+ insertTargetGuideId: null,
+ insertAtIndex: null,
}),
},
USER_ACTION: {
diff --git a/src/entrypoints/background/index.ts b/src/entrypoints/background/index.ts
index ad513ed..f6c13de 100644
--- a/src/entrypoints/background/index.ts
+++ b/src/entrypoints/background/index.ts
@@ -4,7 +4,13 @@ import { validateApiKey } from '@/core/capture/ai/validate';
import { stepRequiresManual } from '@/core/guideme/manual';
import { advanceSession, cancelSession, completeSession, getSession, startSession } from '@/core/guideme/session';
import { actionSteps } from '@/core/guides/blocks';
-import { createGuide, getScreenshotsForSteps, getStepsForGuide } from '@/core/guides/service';
+import {
+ createGuide,
+ createSnapshot,
+ getScreenshotsForSteps,
+ getStepsForGuide,
+ mergeGuideInto,
+} from '@/core/guides/service';
import type { Step } from '@/core/guides/types';
import { getActiveTab, localStorage, sendMessageToTab, setSidePanelBehavior, updateTab } from '@/lib/browser-api';
import { logger } from '@/lib/logger';
@@ -86,10 +92,15 @@ export default defineBackground(() => {
onMessage('startRecording', async ({ data }) => {
await waitUntilReady();
const actor = getActor();
- actor.send({ type: 'START_RECORDING', url: data.url });
+ actor.send({
+ type: 'START_RECORDING',
+ url: data.url,
+ insertTargetGuideId: data.insertTargetGuideId,
+ insertAtIndex: data.insertAtIndex,
+ });
const guideId = actor.getSnapshot().context.currentGuideId!;
- await createGuide(guideId);
+ await createGuide(guideId, data.insertTargetGuideId !== undefined);
const activeTab = await getActiveTab();
if (activeTab?.id) await showNotificationOnTab(activeTab.id);
@@ -101,13 +112,19 @@ export default defineBackground(() => {
onMessage('stopRecording', async () => {
await waitUntilReady();
const actor = getActor();
- const guideId = actor.getSnapshot().context.currentGuideId;
+ const { currentGuideId: guideId, insertTargetGuideId, insertAtIndex } = actor.getSnapshot().context;
await broadcastStopCapture();
actor.send({ type: 'STOP_RECORDING' });
+ if (guideId && insertTargetGuideId !== null && insertAtIndex !== null) {
+ await createSnapshot(insertTargetGuideId);
+ await mergeGuideInto(guideId, insertTargetGuideId, insertAtIndex);
+ return { success: true, guideId: insertTargetGuideId, inserted: true };
+ }
+
if (guideId) generateGuideMetaOnStop(guideId).catch(() => {});
- return { success: true, guideId: guideId ?? undefined };
+ return { success: true, guideId: guideId ?? undefined, inserted: false };
});
onMessage('enterBlurMode', async () => {
diff --git a/src/lib/messaging.ts b/src/lib/messaging.ts
index cd2b76d..694c5ec 100644
--- a/src/lib/messaging.ts
+++ b/src/lib/messaging.ts
@@ -11,6 +11,8 @@ export interface GetStateResponse {
export interface StartRecordingData {
url: string;
+ insertTargetGuideId?: string;
+ insertAtIndex?: number;
}
export interface StartRecordingResponse {
@@ -20,6 +22,7 @@ export interface StartRecordingResponse {
export interface StopRecordingResponse {
success: boolean;
guideId?: string;
+ inserted?: boolean;
}
export interface CaptureStepData {