π¬ A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots π
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
feat(desktop): add a runnable storage check across two renderer windows
Luis Ortiz9aac62b60be4
diff --git a/apps/desktop/electron.vite.config.ts b/apps/desktop/electron.vite.config.tsindex bda5490..73a3f17 100644--- a/apps/desktop/electron.vite.config.ts+++ b/apps/desktop/electron.vite.config.ts@@ -12,6 +12,7 @@ export default defineConfig({input: {index: resolve(__dirname, 'src/main/index.ts'),'check-capture': resolve(__dirname, 'scripts/check-capture.ts'),+ 'check-storage': resolve(__dirname, 'scripts/check-storage.ts'),},output: { entryFileNames: '[name].js' },},@@ -30,7 +31,12 @@ export default defineConfig({build: {outDir: resolve(__dirname, 'out/renderer'),emptyOutDir: true,- rollupOptions: { input: resolve(__dirname, 'src/renderer/index.html') },+ rollupOptions: {+ input: {+ index: resolve(__dirname, 'src/renderer/index.html'),+ 'check-storage': resolve(__dirname, 'src/renderer/check-storage.html'),+ },+ },},},});diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex 032223e..908e4de 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -9,13 +9,15 @@"build": "electron-vite build","pack": "electron-vite build && electron-builder --dir","typecheck": "tsc --noEmit -p tsconfig.json",- "check:capture": "electron-vite build && electron out/main/check-capture.js"+ "check:capture": "electron-vite build && electron out/main/check-capture.js",+ "check:storage": "electron-vite build && electron out/main/check-storage.js"},"dependencies": {"electron-updater": "^6.6.2","@mimik/core": "workspace:*","uiohook-napi": "^1.5.5",- "get-windows": "^9.3.0"+ "get-windows": "^9.3.0",+ "dexie": "^4.3.0"},"devDependencies": {"electron": "^33.2.1",diff --git a/apps/desktop/scripts/check-storage.ts b/apps/desktop/scripts/check-storage.tsnew file mode 100644index 0000000..ee42dba--- /dev/null+++ b/apps/desktop/scripts/check-storage.ts@@ -0,0 +1,56 @@+import { join } from 'node:path';+import { randomUUID } from 'node:crypto';+import { app, BrowserWindow } from 'electron';++const TAG = 'MIMIK_STORAGE_CHECK ';++interface CheckResult {+ name: string;+ ok: boolean;+ detail: string;+}++function line(result: CheckResult): void {+ process.stdout.write(`${result.ok ? 'ok ' : 'FAIL'} ${result.name.padEnd(26)} ${result.detail}\n`);+}++function runRole(role: 'write' | 'read', guideId: string): Promise<CheckResult[]> {+ const win = new BrowserWindow({ show: false });++ return new Promise((resolve) => {+ const timer = setTimeout(+ () => finish([{ name: `${role} window`, ok: false, detail: 'timed out after 20s' }]),+ 20_000,+ );++ function finish(results: CheckResult[]): void {+ clearTimeout(timer);+ if (!win.isDestroyed()) win.destroy();+ resolve(results);+ }++ win.webContents.on('console-message', (_event, _level, message) => {+ if (message.startsWith(TAG)) finish(JSON.parse(message.slice(TAG.length)));+ });+ win.webContents.on('did-fail-load', (_e, code, description) =>+ finish([{ name: `${role} window`, ok: false, detail: `load failed (${code}): ${description}` }]),+ );+ win.webContents.on('render-process-gone', (_e, details) =>+ finish([{ name: `${role} window`, ok: false, detail: `renderer gone: ${details.reason}` }]),+ );+ win.loadFile(join(__dirname, '../renderer/check-storage.html'), { hash: `${role}:${guideId}` });+ });+}++app.disableHardwareAcceleration();+app.on('window-all-closed', () => {});++app.whenReady().then(async () => {+ const guideId = randomUUID();+ const results = [...(await runRole('write', guideId)), ...(await runRole('read', guideId))];+ results.forEach(line);++ const failures = results.filter((r) => !r.ok).length;+ process.stdout.write(`\n${failures === 0 ? 'storage layer carries over unchanged' : `${failures} failure(s)`}\n`);+ app.exit(failures === 0 ? 0 : 1);+});diff --git a/apps/desktop/src/renderer/check-storage.html b/apps/desktop/src/renderer/check-storage.htmlnew file mode 100644index 0000000..cdbfbb7--- /dev/null+++ b/apps/desktop/src/renderer/check-storage.html@@ -0,0 +1,10 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="UTF-8" />+ <title>Mimik storage check</title>+ </head>+ <body>+ <script type="module" src="./check-storage.ts"></script>+ </body>+</html>diff --git a/apps/desktop/src/renderer/check-storage.ts b/apps/desktop/src/renderer/check-storage.tsnew file mode 100644index 0000000..82b0bdb--- /dev/null+++ b/apps/desktop/src/renderer/check-storage.ts@@ -0,0 +1,128 @@+import './core-env';+import { db, MimikDB } from '@mimik/core/guides/db';+import {+ addStepToGuide,+ createGuide,+ createSnapshot,+ createStep,+ getGuide,+ permanentlyDeleteGuide,+ saveScreenshot,+} from '@mimik/core/guides/service';+import Dexie from 'dexie';++export interface CheckResult {+ name: string;+ ok: boolean;+ detail: string;+}++const MIGRATION_DB = 'mimik-migration-check';++async function migration(): Promise<CheckResult> {+ await Dexie.delete(MIGRATION_DB);++ const v1 = new Dexie(MIGRATION_DB);+ v1.version(1).stores({+ guides: 'id, createdAt, updatedAt, starred, deletedAt',+ steps: 'id, guideId, index',+ screenshots: 'id, stepId',+ });+ await v1.open();+ await v1.table('guides').add({ id: 'legacy', title: 'Written at v1', createdAt: 1, updatedAt: 1, stepIds: [] });+ v1.close();++ const upgraded = new MimikDB(MIGRATION_DB);+ await upgraded.open();+ const survivor = await upgraded.guides.get('legacy');+ const snapshotCount = await upgraded.snapshots.count();+ const verno = upgraded.verno;+ upgraded.close();+ await Dexie.delete(MIGRATION_DB);++ return {+ name: 'v1 to v2 migration',+ ok: verno === 2 && survivor?.title === 'Written at v1' && snapshotCount === 0,+ detail: `reopened at v${verno}, v1 row ${survivor ? 'survived' : 'lost'}, snapshots table readable`,+ };+}++async function open(): Promise<CheckResult> {+ await db.open();+ const tables = db.tables.map((t) => t.name).sort();+ const expected = ['guides', 'screenshots', 'snapshots', 'steps'];+ return {+ name: 'MimikDB opens',+ ok: db.verno === 2 && expected.every((t) => tables.includes(t)),+ detail: `v${db.verno}, tables: ${tables.join(', ')}`,+ };+}++async function write(guideId: string): Promise<CheckResult> {+ const stepId = `${guideId}-step`;+ const screenshotId = `${guideId}-shot`;++ await createGuide(guideId);+ await saveScreenshot({+ id: screenshotId,+ stepId,+ blob: new Blob([new Uint8Array([137, 80, 78, 71])], { type: 'image/png' }),+ mimeType: 'image/png',+ width: 2,+ height: 2,+ });+ await createStep({+ id: stepId,+ guideId,+ index: 0,+ description: 'Click Save',+ action: 'click',+ url: '',+ app: { name: 'Mimik Desktop' },+ window: { title: 'Storage check' },+ timestamp: Date.now(),+ screenshotId,+ });+ await addStepToGuide(guideId, stepId);+ const snapshot = await createSnapshot(guideId);++ return {+ name: 'write through @mimik/core',+ ok: snapshot !== null,+ detail: snapshot+ ? `guide, step, screenshot and snapshot ${snapshot.id.slice(0, 8)} stored`+ : 'snapshot not created',+ };+}++async function read(guideId: string): Promise<CheckResult> {+ const found = await getGuide(guideId);+ const step = found?.steps[0];+ const shot = found ? found.screenshots.get(step?.id ?? '') : undefined;+ const blobBytes = shot ? (await shot.blob.arrayBuffer()).byteLength : 0;+ await permanentlyDeleteGuide(guideId);++ return {+ name: 'read from a second window',+ ok: Boolean(found) && step?.app?.name === 'Mimik Desktop' && blobBytes === 4,+ detail: found+ ? `${found.steps.length} step, app "${step?.app?.name}", screenshot blob ${blobBytes} bytes`+ : 'guide not found',+ };+}++async function run(): Promise<CheckResult[]> {+ const [role, guideId] = (window.location.hash.slice(1) || 'write:unknown').split(':');+ if (role === 'read') return [await read(guideId)];+ return [await migration(), await open(), await write(guideId)];+}++function report(results: CheckResult[]): void {+ console.log(`MIMIK_STORAGE_CHECK ${JSON.stringify(results)}`);+}++run()+ .then(report)+ .catch((error) =>+ report([{ name: 'storage check', ok: false, detail: error instanceof Error ? error.message : String(error) }]),+ );diff --git a/packages/core/src/guides/db.ts b/packages/core/src/guides/db.tsindex 2c22a9e..7247ad9 100644--- a/packages/core/src/guides/db.ts+++ b/packages/core/src/guides/db.ts@@ -7,8 +7,8 @@ export class MimikDB extends Dexie {screenshots!: EntityTable<Screenshot, 'id'>;snapshots!: EntityTable<Snapshot, 'id'>;- constructor() {- super('mimik');+ constructor(name = 'mimik') {+ super(name);this.version(1).stores({guides: 'id, createdAt, updatedAt, starred, deletedAt',steps: 'id, guideId, index',diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 2f37981..f92ac3c 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -152,6 +152,9 @@ importers:'@mimik/core':specifier: workspace:*version: link:../../packages/core+ dexie:+ specifier: ^4.3.0+ version: 4.4.1electron-updater:specifier: ^6.6.2version: 6.8.9