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

fix(extension): keep a click made just before pause or finish

Luis Ortiz75f2e4697dfa
diff --git a/src/entrypoints/background/__tests__/pause.test.ts b/src/entrypoints/background/__tests__/pause.test.ts
index 0d44fca..d068f9b 100644
--- a/src/entrypoints/background/__tests__/pause.test.ts
+++ b/src/entrypoints/background/__tests__/pause.test.ts
@@ -22,7 +22,7 @@ vi.mock('../actor', () => ({ getActor: () => actor }));
vi.mock('../tab-manager', () => ({
broadcastDismissBlur: record('dismissBlur'),
broadcastClearBlur: record('clearBlur'),
- broadcastStopCaptureAndFlush: record('flush'),
+ broadcastStopCaptureAndFlush: vi.fn(record('flush')),
broadcastStartCapture: record('startCapture'),
injectContentScript: record('inject'),
isInjectableTab: (tab: { url?: string }) => !!tab.url?.startsWith('https://'),
@@ -59,6 +59,19 @@ describe('pauseCapture', () => {
expect(calls).toContain('flush');
});
+ it('flushes the frames while still recording, so a click made just before the pause is kept', async () => {
+ const { broadcastStopCaptureAndFlush } = await import('../tab-manager');
+ let stateDuringFlush: string | null = null;
+ vi.mocked(broadcastStopCaptureAndFlush).mockImplementationOnce(async () => {
+ stateDuringFlush = actor.getSnapshot().value;
+ });
+
+ await pauseCapture('manual');
+
+ expect(stateDuringFlush).toBe(CaptureState.RECORDING);
+ expect(actor.getSnapshot().value).toBe(CaptureState.PAUSED);
+ });
+
it('refuses when nothing is recording, without touching the frames', async () => {
actor.send({ type: 'STOP_RECORDING' });
diff --git a/src/entrypoints/background/index.ts b/src/entrypoints/background/index.ts
index 371b223..c182c0f 100644
--- a/src/entrypoints/background/index.ts
+++ b/src/entrypoints/background/index.ts
@@ -14,6 +14,8 @@ import {
getScreenshotsForSteps,
getStepsForGuide,
mergeGuideInto,
+ permanentlyDeleteGuide,
+ softDeleteGuide,
} from '@/core/guides/service';
import type { Step } from '@/core/guides/types';
import { getActiveTab } from '@/lib/browser-api/get-active-tab';
@@ -36,10 +38,12 @@ import {
broadcastClearBlur,
broadcastStartCapture,
broadcastStopCapture,
+ broadcastStopCaptureAndFlush,
isInjectableTab,
showNotificationOnTab,
} from './tab-manager';
import {
+ abortVoiceNarration,
canStartNarrationNow,
getVoiceUpdate,
registerVoiceListeners,
@@ -155,7 +159,7 @@ export default defineBackground(() => {
await whenPauseSettled();
const actor = getActor();
const { currentGuideId: guideId, insertTargetGuideId, insertAtIndex } = actor.getSnapshot().context;
- await broadcastStopCapture();
+ await broadcastStopCaptureAndFlush();
await broadcastClearBlur();
actor.send({ type: 'STOP_RECORDING' });
@@ -173,6 +177,21 @@ export default defineBackground(() => {
return { success: true, guideId: guideId ?? undefined, inserted: false };
});
+ onMessage('discardRecording', async () => {
+ await waitUntilReady();
+ await whenPauseSettled();
+ const actor = getActor();
+ const { currentGuideId: guideId, insertTargetGuideId } = actor.getSnapshot().context;
+ await broadcastStopCapture();
+ await broadcastClearBlur();
+ actor.send({ type: 'STOP_RECORDING' });
+ await abortVoiceNarration();
+ if (!guideId) return { discarded: false };
+ if (insertTargetGuideId !== null) await permanentlyDeleteGuide(guideId);
+ else await softDeleteGuide(guideId);
+ return { discarded: true };
+ });
+
onMessage('startNarration', async () => ({ started: await startNarrationIfPossible() }));
onMessage('enterBlurMode', async () => {
diff --git a/src/entrypoints/background/pause.ts b/src/entrypoints/background/pause.ts
index e87fddb..12fd6ba 100644
--- a/src/entrypoints/background/pause.ts
+++ b/src/entrypoints/background/pause.ts
@@ -28,6 +28,7 @@ export async function whenPauseSettled(): Promise<void> {
}
export function pauseCapture(reason: PauseReason): Promise<boolean> {
+ if (pauseInFlight) return Promise.resolve(false);
if (getActor().getSnapshot().value !== CaptureState.RECORDING) return Promise.resolve(false);
const pausing = pauseAndStopNarration(reason);
pauseInFlight = pausing;
@@ -44,10 +45,11 @@ async function pauseAndStopNarration(reason: PauseReason): Promise<boolean> {
if (actor.getSnapshot().value !== CaptureState.RECORDING) return false;
const narrationWasLive = (await isNarrationLive()) || isNarrationSettling();
+ await broadcastStopCaptureAndFlush();
+ if (actor.getSnapshot().value !== CaptureState.RECORDING) return false;
actor.send({ type: 'PAUSE_CAPTURE', reason, narrationWasLive });
const guideId = actor.getSnapshot().context.currentGuideId;
- await broadcastStopCaptureAndFlush();
if (narrationWasLive && guideId) await stopVoiceNarration(guideId);
return true;
}