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(desktop): name a guide after the app most of its steps happened in

Luis Ortiz931e8c318dd8
diff --git a/apps/desktop/src/renderer/capture-host.ts b/apps/desktop/src/renderer/capture-host.ts
index 7192c03..3619ea9 100644
--- a/apps/desktop/src/renderer/capture-host.ts
+++ b/apps/desktop/src/renderer/capture-host.ts
@@ -2,6 +2,7 @@ import { resolveGuideMetaInputs } from '@mimik/core/capture/ai/guide-description
import { settleDescriptions } from '@mimik/core/capture/ai/settle-descriptions';
import type { CaptureStepData } from '@mimik/core/capture/sink';
import { i18n } from '@mimik/core/env';
+import { getMostCommonApp } from '@mimik/core/guides/most-common-app';
import {
allScreenshotIds,
createSnapshot,
@@ -32,7 +33,7 @@ window.mimik.onRequest('mimik:capture:finishGuide', async (payload) => {
const guideId = payload as string;
const steps = await getStepsForGuide(guideId);
if (steps.length === 0) return true;
- const app = steps.find((step) => step.app?.name)?.app?.name;
+ const app = getMostCommonApp(steps)?.name;
const fallback = app ? i18n.t('desktop.guideInApp', [app]) : i18n.t('background.newGuide');
if (!(await resolveGuideMetaInputs(guideId)).ok) {
await updateGuideTitle(guideId, fallback);
diff --git a/packages/core/src/guides/__tests__/most-common-app.test.ts b/packages/core/src/guides/__tests__/most-common-app.test.ts
new file mode 100644
index 0000000..e265472
--- /dev/null
+++ b/packages/core/src/guides/__tests__/most-common-app.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it } from 'vitest';
+import { getMostCommonApp } from '../most-common-app';
+
+const chrome = { name: 'Google Chrome', id: '/Applications/Google Chrome.app' };
+const terminal = { name: 'Terminal', id: '/System/Applications/Utilities/Terminal.app' };
+
+describe('getMostCommonApp', () => {
+ it('picks the app with the most steps, not the first', () => {
+ const steps = [{ app: terminal }, { app: terminal }, ...Array.from({ length: 6 }, () => ({ app: chrome }))];
+ expect(getMostCommonApp(steps)).toEqual(chrome);
+ });
+
+ it('breaks a tie in favour of the app seen first, and skips steps with no app', () => {
+ expect(getMostCommonApp([{}, { app: terminal }, { app: chrome }])).toEqual(terminal);
+ expect(getMostCommonApp([{}])).toBeNull();
+ });
+});
diff --git a/packages/core/src/guides/most-common-app.ts b/packages/core/src/guides/most-common-app.ts
new file mode 100644
index 0000000..98e9e47
--- /dev/null
+++ b/packages/core/src/guides/most-common-app.ts
@@ -0,0 +1,16 @@
+import type { Step } from './types';
+
+type StepApp = NonNullable<Step['app']>;
+
+export function getMostCommonApp(steps: { app?: StepApp }[]): StepApp | null {
+ const counts = new Map<string, { app: StepApp; count: number }>();
+ for (const step of steps) {
+ if (!step.app?.name) continue;
+ const seen = counts.get(step.app.name);
+ if (seen) seen.count += 1;
+ else counts.set(step.app.name, { app: step.app, count: 1 });
+ }
+ let best: { app: StepApp; count: number } | null = null;
+ for (const entry of counts.values()) if (!best || entry.count > best.count) best = entry;
+ return best?.app ?? null;
+}
diff --git a/packages/ui/src/library/lib/load-card-data.ts b/packages/ui/src/library/lib/load-card-data.ts
index da5b3a6..2ee295f 100644
--- a/packages/ui/src/library/lib/load-card-data.ts
+++ b/packages/ui/src/library/lib/load-card-data.ts
@@ -1,4 +1,5 @@
import { getMostCommonDomain } from '@mimik/core/guides/domain';
+import { getMostCommonApp } from '@mimik/core/guides/most-common-app';
import { getFirstScreenshot, getStepsForGuide } from '@mimik/core/guides/service';
import type { Guide, Screenshot, Step } from '@mimik/core/guides/types';
import type { GuidePlace } from '../types';
@@ -6,7 +7,7 @@ import type { GuidePlace } from '../types';
function placeOf(steps: Step[]): GuidePlace | null {
const domain = getMostCommonDomain(steps);
if (domain) return { kind: 'site', name: domain };
- const app = steps.find((step) => step.app?.name)?.app;
+ const app = getMostCommonApp(steps);
return app ? { kind: 'app', name: app.name, id: app.id } : null;
}