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: add discard to the desktop recording card with a trash icon on both apps, and match the extension on capture more and mic resume

Luis Ortiz6c2da28842b7
diff --git a/apps/desktop/scripts/check-overlay.ts b/apps/desktop/scripts/check-overlay.ts
index 2aeae5d..9c1fdde 100644
--- a/apps/desktop/scripts/check-overlay.ts
+++ b/apps/desktop/scripts/check-overlay.ts
@@ -390,8 +390,8 @@ app.whenReady().then(async () => {
"JSON.stringify([...document.querySelectorAll('#foot button')].map((b) => b.id + ':' + b.textContent.trim()))",
);
check(
- 'Finish leads the footer, with the mic and Pause after it',
- /^\["primary:Finish recording","mic:","secondary:"\]$/.test(String(order)),
+ 'Finish leads the footer, with the mic, Pause and Discard after it',
+ /^\["primary:Finish recording","mic:","secondary:","discard:"\]$/.test(String(order)),
String(order),
);
check(
diff --git a/apps/desktop/scripts/check-pipeline.ts b/apps/desktop/scripts/check-pipeline.ts
index 51b8c58..31a7ff2 100644
--- a/apps/desktop/scripts/check-pipeline.ts
+++ b/apps/desktop/scripts/check-pipeline.ts
@@ -726,6 +726,25 @@ app.whenReady().then(async () => {
detail: merged,
});
+ let discarded = 'no reply';
+ try {
+ const kept = await ask<string>(app_.webContents, 'mimik:capture:createGuide', {}, 20_000);
+ const staging = await ask<string>(app_.webContents, 'mimik:capture:createGuide', { staging: true }, 20_000);
+ await ask(app_.webContents, 'mimik:capture:discardRecording', { guideId: kept, staging: false }, 20_000);
+ await ask(app_.webContents, 'mimik:capture:discardRecording', { guideId: staging, staging: true }, 20_000);
+ const trashed = await ask<boolean | null>(win.webContents, 'mimik:check:trashed', kept, 20_000);
+ const left = await ask<boolean | null>(win.webContents, 'mimik:check:trashed', staging, 20_000);
+ discarded = `${trashed ? 'in Trash' : 'not in Trash'}; staging ${left === null ? 'gone' : 'left behind'}`;
+ await ask(app_.webContents, 'mimik:check:cleanup', [kept, staging], 20_000).catch(() => undefined);
+ } catch (error) {
+ discarded = error instanceof Error ? error.message : String(error);
+ }
+ results.push({
+ name: 'a discarded recording goes to Trash, as in the extension',
+ ok: discarded === 'in Trash; staging gone',
+ detail: discarded,
+ });
+
results.push({
name: 'an empty recording is named New guide, as in the extension',
ok: titled === 'New guide',
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index ffd5260..bfd565f 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -4,6 +4,7 @@ import type { AiFailureUpdate } from '@mimik/core/capture/ai/errors';
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 { NARRATION_SETTLE_MS } from '@mimik/core/capture/voice/narration-settle-ms';
import { app, BrowserWindow, dialog, ipcMain, Menu, nativeImage, protocol, screen, shell, Tray } from 'electron';
import { createActor } from 'xstate';
import { shortcutLabel } from '../renderer/lib/shortcut-label';
@@ -28,6 +29,8 @@ import {
import { bindShortcuts, type ShortcutName, shortcutMap, unbindShortcuts } from './shortcuts';
import { checkForUpdates } from './updater';
+const FINISH_TIMEOUT_MS = NARRATION_SETTLE_MS + 15_000;
+
let mainWindow: BrowserWindow | null = null;
let tray: Tray | null = null;
let overlay: CaptureOverlay | null = null;
@@ -366,12 +369,26 @@ async function onOverlayCommand(command: OverlayCommand): Promise<void> {
insertTargetGuideId: target.insertTargetGuideId,
insertAtIndex: target.insertAtIndex,
},
- 45_000,
+ FINISH_TIMEOUT_MS,
).catch(() => undefined);
- if (steps.length > 0) finished = target.insertTargetGuideId;
+ finished = target.insertTargetGuideId;
} else if (currentGuideId) {
finished = currentGuideId;
- void ask(mainWindow?.webContents ?? null, 'mimik:capture:finishGuide', finished, 45_000).catch(() => undefined);
+ void ask(mainWindow?.webContents ?? null, 'mimik:capture:finishGuide', finished, FINISH_TIMEOUT_MS).catch(
+ () => undefined,
+ );
+ }
+ currentGuideId = null;
+ } else if (command === 'discard') {
+ recorder?.stop();
+ await recorder?.drain();
+ const staging = insert !== null;
+ insert = null;
+ if (currentGuideId) {
+ await ask(mainWindow?.webContents ?? null, 'mimik:capture:discardRecording', {
+ guideId: currentGuideId,
+ staging,
+ }).catch(() => undefined);
}
currentGuideId = null;
} else if (command === 'disarm' || command === 'cancelEdit') {
@@ -380,7 +397,9 @@ async function onOverlayCommand(command: OverlayCommand): Promise<void> {
broadcastState(command, finished ?? currentGuideId);
applyShortcuts();
refreshTray();
- if (command === 'stop' || command === 'disarm' || command === 'cancelEdit') leaveCapture(Boolean(finished));
+ if (command === 'stop' || command === 'discard' || command === 'disarm' || command === 'cancelEdit') {
+ leaveCapture(Boolean(finished));
+ }
}
let isQuitting = false;
diff --git a/apps/desktop/src/main/overlay/index.ts b/apps/desktop/src/main/overlay/index.ts
index 8240b47..138371f 100644
--- a/apps/desktop/src/main/overlay/index.ts
+++ b/apps/desktop/src/main/overlay/index.ts
@@ -11,7 +11,7 @@ import type { VoiceErrorReason } from '@mimik/core/capture/voice/voice-update';
import type { DescriptionSource } from '@mimik/core/guides/types';
import { app, BrowserWindow, ipcMain, screen } from 'electron';
import type { Actor } from 'xstate';
-import { clampToDisplays, loadRegion, type Region, saveRegion } from '../capture/region';
+import { loadRegion, type Region, saveRegion } from '../capture/region';
import type { CaptureMode } from '../capture/settings';
export type CaptureActor = Actor<typeof captureMachine>;
@@ -23,6 +23,7 @@ export type OverlayCommand =
| 'pause'
| 'resume'
| 'stop'
+ | 'discard'
| 'mode:window'
| 'mode:screen'
| 'mode:area'
@@ -47,7 +48,7 @@ export interface OverlayProgress {
ms: number;
}
-export interface OverlayShortcuts {
+interface OverlayShortcuts {
startStop: string | null;
capture: string | null;
}
@@ -58,7 +59,7 @@ export interface OverlayNarration {
reason?: VoiceErrorReason;
}
-export interface OverlayAim {
+interface OverlayAim {
x: number;
y: number;
aspect: number;
@@ -518,7 +519,7 @@ export class CaptureOverlay {
this.stopEditing();
this.capture.send({ type: 'RESUME_CAPTURE' });
this.onCommand(command);
- } else if (command === 'stop' && state !== CaptureState.IDLE) {
+ } else if ((command === 'stop' || command === 'discard') && state !== CaptureState.IDLE) {
this.reset();
this.onCommand(command);
}
@@ -564,4 +565,4 @@ export class CaptureOverlay {
}
}
-export { clampToDisplays, loadRegion, type Region, saveRegion };
+export type { Region };
diff --git a/apps/desktop/src/renderer/capture-host.ts b/apps/desktop/src/renderer/capture-host.ts
index bfd683c..4b93a31 100644
--- a/apps/desktop/src/renderer/capture-host.ts
+++ b/apps/desktop/src/renderer/capture-host.ts
@@ -1,21 +1,21 @@
import { finishGuide } from '@mimik/core/capture/ai/finish-guide';
-import { settleDescriptions } from '@mimik/core/capture/ai/settle-descriptions';
+import { mergeRecording } from '@mimik/core/capture/ai/merge-recording';
import { CaptureState } from '@mimik/core/capture/machine';
import type { CaptureStepData } from '@mimik/core/capture/sink';
import { i18n, localStorage } from '@mimik/core/env';
import { getMostCommonApp } from '@mimik/core/guides/most-common-app';
import {
allScreenshotIds,
- createSnapshot,
deleteStep,
getStepsForGuide,
- mergeGuideInto,
permanentlyDeleteGuide,
+ softDeleteGuide,
} from '@mimik/core/guides/service';
import { DesktopCaptureSink } from './capture-sink';
import { desktopNarration as narration } from './desktop-narration';
const sink = new DesktopCaptureSink(narration);
+let narratingBeforePause = false;
allScreenshotIds().then((ids) => window.mimik.screenshots.sweep(ids));
@@ -30,10 +30,16 @@ window.mimik.capture.onStateUpdate(async ({ command, state, currentGuideId }) =>
}
if (!currentGuideId) return;
const recording = state === CaptureState.RECORDING;
- if (command === 'start' || command === 'resume' || (command === 'narration:start' && recording)) {
+ if (
+ command === 'start' ||
+ (command === 'resume' && narratingBeforePause) ||
+ (command === 'narration:start' && recording)
+ ) {
narration.start(currentGuideId);
- } else if (command === 'pause') narration.stop();
- else if (command === 'narration:stop') narration.abort();
+ } else if (command === 'pause') {
+ narratingBeforePause = narration.update.phase === 'recording';
+ narration.stop();
+ } else if (command === 'narration:stop') narration.abort();
});
window.mimik.onRequest('mimik:capture:deleteStep', async (payload) => {
@@ -52,16 +58,21 @@ window.mimik.onRequest('mimik:capture:finishGuide', async (payload) => {
return true;
});
+window.mimik.onRequest('mimik:capture:discardRecording', async (payload) => {
+ const { guideId, staging } = payload as { guideId: string; staging: boolean };
+ narration.abort();
+ if (staging) await permanentlyDeleteGuide(guideId);
+ else await softDeleteGuide(guideId);
+ return true;
+});
+
window.mimik.onRequest('mimik:capture:mergeGuideInto', async (payload) => {
const { guideId, insertTargetGuideId, insertAtIndex } = payload as {
guideId: string;
insertTargetGuideId: string;
insertAtIndex: number;
};
- await narration.settle();
- await settleDescriptions(guideId);
- await createSnapshot(insertTargetGuideId);
- await mergeGuideInto(guideId, insertTargetGuideId, insertAtIndex);
+ await mergeRecording(guideId, { insertTargetGuideId, insertAtIndex }, () => narration.settle());
return true;
});
diff --git a/apps/desktop/src/renderer/check-pipeline.ts b/apps/desktop/src/renderer/check-pipeline.ts
index b595fd1..4063ff1 100644
--- a/apps/desktop/src/renderer/check-pipeline.ts
+++ b/apps/desktop/src/renderer/check-pipeline.ts
@@ -47,6 +47,11 @@ window.mimik.onRequest('mimik:check:steps', async (payload) => {
return found ? found.steps.map((step) => step.description) : null;
});
+window.mimik.onRequest('mimik:check:trashed', async (payload) => {
+ const found = await getGuide(payload as string);
+ return found ? found.guide.deletedAt != null : null;
+});
+
window.mimik.onRequest('mimik:check:title', async (payload) => {
const found = await getGuide(payload as string);
return found?.guide.title ?? null;
diff --git a/apps/desktop/src/renderer/overlay.css b/apps/desktop/src/renderer/overlay.css
index bdf242b..1cd2d46 100644
--- a/apps/desktop/src/renderer/overlay.css
+++ b/apps/desktop/src/renderer/overlay.css
@@ -12,6 +12,7 @@
--violet-mid: #3730a3;
--muted: #6b7280;
--success: #059669;
+ --destructive: #dc2626;
}
* {
@@ -827,10 +828,19 @@ body.controls #foot button {
body.controls #foot #primary {
flex: 1 1 0;
+ min-width: 0;
+}
+
+body.controls #foot #primary span {
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
}
body.controls #foot #mic,
-body.controls #foot #secondary {
+body.controls #foot #secondary,
+body.controls #foot #discard {
width: 40px;
padding: 0;
color: var(--muted);
@@ -841,6 +851,11 @@ body.controls #foot #mic:hover {
color: var(--accent);
}
+body.controls #foot #discard:hover {
+ border-color: rgba(220, 38, 38, 0.3);
+ color: var(--destructive);
+}
+
body.controls #foot #mic.on {
border-color: var(--accent);
background: #eef2ff;
diff --git a/apps/desktop/src/renderer/overlay/controls.ts b/apps/desktop/src/renderer/overlay/controls.ts
index abc1868..2396866 100644
--- a/apps/desktop/src/renderer/overlay/controls.ts
+++ b/apps/desktop/src/renderer/overlay/controls.ts
@@ -1,9 +1,9 @@
import { aiFailureNotice } from '@mimik/core/capture/ai/errors';
import { CaptureState } from '@mimik/core/capture/machine';
import { splitAtShortcut } from '@mimik/core/capture/split-at-shortcut';
-import { hasVoiceApiKey, VOICE_KEY_SETTINGS } from '@mimik/core/capture/voice/api-key';
+import { readVoiceSettings } from '@mimik/core/capture/voice/read-voice-settings';
import { voiceErrorKey } from '@mimik/core/capture/voice/voice-error-key';
-import { i18n, localStorage } from '@mimik/core/env';
+import { i18n } from '@mimik/core/env';
import { STEP_SOURCE_LABELS } from '@mimik/core/guides/step-source-labels';
import type { OverlayView } from '../../main/overlay';
import { icon } from '../icons';
@@ -113,7 +113,10 @@ export function controls(): void {
const secondary = el('button', { id: 'secondary', type: 'button' });
const primary = el('button', { id: 'primary', type: 'button', className: 'primary' });
const mic = el('button', { id: 'mic', type: 'button' });
- const foot = el('div', { id: 'foot' }, primary, mic, secondary);
+ const discard = el('button', { id: 'discard', type: 'button', title: i18n.t('recording.discard') });
+ discard.setAttribute('aria-label', i18n.t('recording.discard'));
+ discard.append(icon('trash', 16));
+ const foot = el('div', { id: 'foot' }, primary, mic, secondary, discard);
document.body.append(head, body, modes, aiNotice, foot);
@@ -316,11 +319,12 @@ export function controls(): void {
secondary.title = secondaryLabel;
secondary.setAttribute('aria-label', secondaryLabel);
primary.replaceChildren(icon(armed ? 'video' : 'check'));
- primary.append(i18n.t(armed ? 'desktop.startButton' : 'recording.finishRecording'));
+ primary.append(el('span', {}, i18n.t(armed ? 'desktop.startButton' : 'recording.finishRecording')));
}
secondary.dataset.command = armed ? 'disarm' : recording ? 'pause' : 'resume';
primary.dataset.command = armed ? 'start' : 'stop';
primary.disabled = starting || (busy && !armed);
+ discard.hidden = armed;
foot.hidden = collapsed;
aiNotice.hidden = collapsed || armed || !aiFailure;
@@ -371,13 +375,14 @@ export function controls(): void {
primary.addEventListener('click', () => window.mimikOverlay.command(primary.dataset.command ?? 'start'));
secondary.addEventListener('click', () => window.mimikOverlay.command(secondary.dataset.command ?? 'disarm'));
remove.addEventListener('click', () => window.mimikOverlay.command('deleteStep'));
+ discard.addEventListener('click', () => window.mimikOverlay.command('discard'));
mic.addEventListener('click', () => {
if (mic.className !== 'locked') window.mimikOverlay.command(micOn ? 'narration:stop' : 'narration:start');
});
const readMic = () =>
- localStorage.get([...VOICE_KEY_SETTINGS, 'voiceEnabled']).then((stored) => {
- micOn = stored.voiceEnabled === true;
- micKeyed = hasVoiceApiKey(stored);
+ readVoiceSettings().then((voice) => {
+ micOn = voice.enabled;
+ micKeyed = voice.hasApiKey;
paint();
});
void readMic();
diff --git a/src/ui/sidepanel/RecordingView.tsx b/src/ui/sidepanel/RecordingView.tsx
index ac09f46..c4f435e 100644
--- a/src/ui/sidepanel/RecordingView.tsx
+++ b/src/ui/sidepanel/RecordingView.tsx
@@ -8,7 +8,7 @@ import {
TooltipContent,
TooltipTrigger,
} from '@mimik/ui';
-import { Check, EyeOff, Loader2, Pause, Play, X } from 'lucide-react';
+import { Check, EyeOff, Loader2, Pause, Play, Trash2, X } from 'lucide-react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { i18n } from '#imports';
import type { PauseReason } from '@/core/capture/machine';
@@ -126,7 +126,6 @@ export function RecordingView({
[guideId, loadSteps],
);
- const _domain = extractDomain(siteUrl);
return (
<div className="flex flex-col h-screen bg-card relative">
{/* Floating recording pill */}
@@ -264,7 +263,7 @@ export function RecordingView({
onClick={onDiscard}
className="w-9 h-9 shrink-0 rounded-full border border-border flex items-center justify-center transition-colors text-purple hover:border-destructive/30 hover:text-destructive"
>
- <X size={16} />
+ <Trash2 size={16} />
</button>
</TooltipTrigger>
<TooltipContent align="end">{i18n.t('recording.discard')}</TooltipContent>