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(desktop): add a runnable capture pipeline check

Luis Ortizba613920e658
diff --git a/apps/desktop/electron.vite.config.ts b/apps/desktop/electron.vite.config.ts
index 95c75a1..e8c06dd 100644
--- a/apps/desktop/electron.vite.config.ts
+++ b/apps/desktop/electron.vite.config.ts
@@ -14,6 +14,7 @@ export default defineConfig({
'check-capture': resolve(__dirname, 'scripts/check-capture.ts'),
'check-storage': resolve(__dirname, 'scripts/check-storage.ts'),
'check-overlay': resolve(__dirname, 'scripts/check-overlay.ts'),
+ 'check-pipeline': resolve(__dirname, 'scripts/check-pipeline.ts'),
},
output: { entryFileNames: '[name].js', chunkFileNames: '[name].js' },
},
@@ -43,6 +44,7 @@ export default defineConfig({
index: resolve(__dirname, 'src/renderer/index.html'),
'check-storage': resolve(__dirname, 'src/renderer/check-storage.html'),
overlay: resolve(__dirname, 'src/renderer/overlay.html'),
+ 'check-pipeline': resolve(__dirname, 'src/renderer/check-pipeline.html'),
},
},
},
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 102a103..53405c0 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -11,7 +11,8 @@
"typecheck": "tsc --noEmit -p tsconfig.json",
"check:capture": "electron-vite build && electron out/main/check-capture.js",
"check:storage": "electron-vite build && electron out/main/check-storage.js",
- "check:overlay": "electron-vite build && node scripts/run-check.mjs out/main/check-overlay.js"
+ "check:overlay": "electron-vite build && node scripts/run-check.mjs out/main/check-overlay.js",
+ "check:pipeline": "electron-vite build && electron out/main/check-pipeline.js"
},
"dependencies": {
"electron-updater": "^6.6.2",
diff --git a/apps/desktop/scripts/check-pipeline.ts b/apps/desktop/scripts/check-pipeline.ts
new file mode 100644
index 0000000..07e9fcd
--- /dev/null
+++ b/apps/desktop/scripts/check-pipeline.ts
@@ -0,0 +1,71 @@
+import { join } from 'node:path';
+import { app, BrowserWindow, nativeImage, screen } from 'electron';
+import { ask } from '../src/main/ask';
+import { DesktopRecorder } from '../src/main/capture/recorder';
+import { clampToDisplays } from '../src/main/capture/region';
+import type { Capture } from '../src/main/capture/screenshot';
+
+interface CheckResult {
+ name: string;
+ ok: boolean;
+ detail: string;
+}
+
+function bail(error: unknown): never {
+ process.stdout.write(`FAIL check-pipeline aborted: ${error instanceof Error ? error.stack : String(error)}\n`);
+ app.exit(1);
+ throw error;
+}
+
+setTimeout(() => bail(new Error('check did not finish within 120s')), 120_000).unref();
+
+app.disableHardwareAcceleration();
+app.on('window-all-closed', () => {});
+
+app.whenReady().then(async () => {
+ const win = new BrowserWindow({
+ show: false,
+ webPreferences: { preload: join(__dirname, '../preload/index.cjs'), contextIsolation: true },
+ });
+ await win.loadFile(join(__dirname, '../renderer/check-pipeline.html'));
+ const region = clampToDisplays({ x: 0, y: 0, width: 800, height: 600 });
+ const display = screen.getDisplayMatching(region);
+
+ function syntheticDisplay(displayId: number): Promise<Capture> {
+ const scale = display.scaleFactor;
+ const width = Math.round(display.bounds.width * scale);
+ const height = Math.round(display.bounds.height * scale);
+ const pixels = Buffer.alloc(width * height * 4);
+ for (let i = 0; i < pixels.length; i += 4) {
+ pixels[i] = (i / 4) % 256;
+ pixels[i + 1] = 80;
+ pixels[i + 2] = 200;
+ pixels[i + 3] = 255;
+ }
+ const image = nativeImage.createFromBuffer(pixels, { width, height });
+ return Promise.resolve({ png: image.toPNG(), width, height, scaleFactor: scale, displayId });
+ }
+
+ const recorder = new DesktopRecorder(
+ () => region,
+ (fn) => fn(),
+ (request) => ask(win.webContents, 'mimik:capture:step', { ...request, guideId }),
+ syntheticDisplay,
+ );
+ const guideId = await ask<string>(win.webContents, 'mimik:capture:startGuide');
+
+ await recorder.capture({ x: region.x + 120, y: region.y + 90 });
+ await recorder.capture({ x: region.x + 400, y: region.y + 300 });
+ const results = await ask<CheckResult[]>(win.webContents, 'mimik:check:verify', guideId, 60_000);
+
+ process.stdout.write(
+ `capture area ${region.width} Γ— ${region.height} on a ${display.bounds.width} Γ— ${display.bounds.height} display at ${display.scaleFactor}x\n\n`,
+ );
+ for (const result of results) {
+ process.stdout.write(`${result.ok ? 'ok ' : 'FAIL'} ${result.name.padEnd(36)} ${result.detail}\n`);
+ }
+
+ const failures = results.filter((r) => !r.ok).length;
+ process.stdout.write(`\n${failures === 0 ? 'desktop captures are ordinary guides' : `${failures} failure(s)`}\n`);
+ app.exit(failures === 0 ? 0 : 1);
+}).catch(bail);
diff --git a/apps/desktop/src/renderer/check-pipeline.html b/apps/desktop/src/renderer/check-pipeline.html
new file mode 100644
index 0000000..b98078c
--- /dev/null
+++ b/apps/desktop/src/renderer/check-pipeline.html
@@ -0,0 +1,10 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <title>Mimik pipeline check</title>
+ </head>
+ <body>
+ <script type="module" src="./check-pipeline.ts"></script>
+ </body>
+</html>
diff --git a/apps/desktop/src/renderer/check-pipeline.ts b/apps/desktop/src/renderer/check-pipeline.ts
new file mode 100644
index 0000000..f65941d
--- /dev/null
+++ b/apps/desktop/src/renderer/check-pipeline.ts
@@ -0,0 +1,85 @@
+import './core-env';
+import type { CaptureStepData } from '@mimik/core/capture/sink';
+import { exportGuideAsDOCX } from '@mimik/core/export/docx-export';
+import { exportGuideAsHTML } from '@mimik/core/export/html-export';
+import { exportGuideAsMarkdown } from '@mimik/core/export/markdown-export';
+import { exportGuideAsPDF } from '@mimik/core/export/pdf-export';
+import { getGuide, permanentlyDeleteGuide } from '@mimik/core/guides/service';
+import { elementSource } from '@mimik/core/guides/types';
+import { DesktopCaptureSink } from './capture-sink';
+
+interface CheckResult {
+ name: string;
+ ok: boolean;
+ detail: string;
+}
+
+const sink = new DesktopCaptureSink();
+
+window.mimik.onRequest('mimik:capture:startGuide', () => sink.startGuide());
+window.mimik.onRequest('mimik:capture:step', (payload) => sink.captureStep(payload as CaptureStepData));
+
+window.mimik.onRequest('mimik:check:verify', async (payload) => {
+ const guideId = payload as string;
+ const results: CheckResult[] = [];
+ const found = await getGuide(guideId);
+
+ if (!found) {
+ return [{ name: 'guide in the library', ok: false, detail: 'guide not found' }];
+ }
+
+ const { guide, steps, screenshots } = found;
+ const step = steps[0];
+ const meta = step?.elementMeta;
+ const shot = step ? screenshots.get(step.id) : undefined;
+
+ results.push({
+ name: 'steps land in the library',
+ ok: steps.length === 2 && guide.stepIds.length === 2,
+ detail: `${steps.length} step(s), ${guide.stepIds.length} id(s) on the guide`,
+ });
+
+ results.push({
+ name: 'step carries screen provenance',
+ ok: meta !== undefined && elementSource(meta) === 'screen',
+ detail: meta
+ ? `source ${elementSource(meta)}, app "${step.app?.name ?? 'none'}", window "${step.window?.title ?? 'none'}"`
+ : 'no element metadata',
+ });
+
+ results.push({
+ name: 'screenshot cropped to the region',
+ ok: shot !== undefined && shot.blob.size > 0,
+ detail: shot ? `${shot.width} Γ— ${shot.height}, ${shot.blob.size} bytes` : 'no screenshot',
+ });
+
+ results.push({
+ name: 'description came from the shared heuristic',
+ ok: (step?.description.length ?? 0) > 0 && step?.descriptionSource === 'heuristic',
+ detail: `"${step?.description ?? ''}"`,
+ });
+
+ const exporters: [string, () => Promise<string | Blob>][] = [
+ ['HTML', () => exportGuideAsHTML(guide, steps, screenshots)],
+ ['Markdown', () => exportGuideAsMarkdown(guide, steps, screenshots)],
+ ['PDF', () => exportGuideAsPDF(guide, steps, screenshots)],
+ ['DOCX', () => exportGuideAsDOCX(guide, steps, screenshots)],
+ ];
+
+ for (const [name, run] of exporters) {
+ try {
+ const output = await run();
+ const size = typeof output === 'string' ? output.length : output.size;
+ results.push({ name: `${name} export`, ok: size > 0, detail: `${size} bytes` });
+ } catch (error) {
+ results.push({
+ name: `${name} export`,
+ ok: false,
+ detail: error instanceof Error ? error.message : String(error),
+ });
+ }
+ }
+
+ await permanentlyDeleteGuide(guideId);
+ return results;
+});