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): redraw the area editor and open it from the paused card

Luis Ortizb0cda365c577
diff --git a/apps/desktop/scripts/check-overlay.ts b/apps/desktop/scripts/check-overlay.ts
index 710fbd0..b081129 100644
--- a/apps/desktop/scripts/check-overlay.ts
+++ b/apps/desktop/scripts/check-overlay.ts
@@ -272,6 +272,49 @@ app.whenReady().then(async () => {
`${framed.length} overlay window(s), active mode button is ${active}`,
);
+ const editorWindows = () => webContents.getAllWebContents().filter((wc) => wc.getURL().includes('#editor'));
+ const inEditor = (script: string) => editorWindows()[0]?.executeJavaScript(script);
+ const pickArea = () =>
+ windowWithHash('controls')?.webContents.executeJavaScript("document.querySelector('button.mode[data-mode=\"area\"]').click()");
+ overlay.pause();
+ await settle();
+ await pickArea();
+ await settle();
+ const opened = { state: overlay.state, editors: editorWindows().length, sent: commands.at(-1) };
+ const look = JSON.parse(
+ String(
+ (await inEditor(
+ "JSON.stringify({ buttons: [...document.querySelectorAll('#bar button')].map((b) => b.textContent.trim()), edge: getComputedStyle(document.querySelector('#region'), '::after').borderTopStyle, corner: getComputedStyle(document.querySelector('.handle[data-handle=\"nw\"]')).borderTopColor })",
+ )) ?? '{}',
+ ),
+ ) as { buttons?: string[]; edge?: string; corner?: string };
+ await inEditor("document.querySelector('#bar button.secondary').click()");
+ await settle();
+ const cancelled = { state: overlay.state, editors: editorWindows().length, sent: commands.at(-1) };
+ await pickArea();
+ await settle();
+ await inEditor("document.querySelector('#bar button.primary').click()");
+ await settle();
+ const confirmed = { state: overlay.state, editors: editorWindows().length, sent: commands.at(-1) };
+ check(
+ 'picking Area while paused opens the editor, Done resumes and Cancel stays paused',
+ opened.state === 'editing' &&
+ opened.editors === displays.length &&
+ opened.sent === 'mode:region' &&
+ cancelled.state === 'paused' &&
+ cancelled.editors === 0 &&
+ cancelled.sent === 'mode:screen' &&
+ confirmed.state === 'recording' &&
+ confirmed.editors === 0 &&
+ confirmed.sent === 'resume',
+ `opened ${JSON.stringify(opened)}, cancel ${JSON.stringify(cancelled)}, done ${JSON.stringify(confirmed)}`,
+ );
+ check(
+ 'the area editor uses the action bar and the crop frame',
+ look.buttons?.join('|') === 'CancelEsc|DoneEnter' && look.edge === 'dashed' && look.corner === 'rgb(79, 70, 229)',
+ `buttons ${look.buttons?.join(', ')}, edge ${look.edge}, corner ${look.corner}`,
+ );
+
const outside = { x: overlay.region.x - 5000, y: overlay.region.y - 5000 };
const bars = windowWithHash('controls')?.getBounds();
check(
diff --git a/apps/desktop/src/main/overlay/index.ts b/apps/desktop/src/main/overlay/index.ts
index 1509665..ad07ce0 100644
--- a/apps/desktop/src/main/overlay/index.ts
+++ b/apps/desktop/src/main/overlay/index.ts
@@ -112,6 +112,8 @@ export class CaptureOverlay {
private step: OverlayStep | null = null;
private size = { width: CONTROLS.width, height: CONTROLS.height };
private busy = false;
+ private editingFrom: OverlayState = 'hidden';
+ private modeBeforeEdit: CaptureMode | null = null;
private hiding: { shown: BrowserWindow[]; ready: Promise<unknown>; users: number } | null = null;
private starting = false;
@@ -251,6 +253,7 @@ export class CaptureOverlay {
}
edit(): void {
+ if (this.current !== 'editing') this.editingFrom = this.current;
this.current = 'editing';
if (this.boundary && !this.boundary.isDestroyed()) this.boundary.hide();
if (this.controls && !this.controls.isDestroyed()) this.controls.hide();
@@ -347,7 +350,24 @@ export class CaptureOverlay {
private command(command: OverlayCommand): void {
if (command.startsWith('mode:')) {
+ const before = this.mode();
this.onCommand(command);
+ if (command === 'mode:region' && this.current === 'paused') {
+ this.modeBeforeEdit = before;
+ this.edit();
+ }
+ return;
+ }
+ const recording = this.editingFrom === 'recording' || this.editingFrom === 'paused';
+ if (this.current === 'editing' && recording && (command === 'arm' || command === 'cancel')) {
+ if (command === 'cancel' && this.modeBeforeEdit) this.onCommand(`mode:${this.modeBeforeEdit}`);
+ this.modeBeforeEdit = null;
+ if (this.editingFrom === 'recording') this.record();
+ else if (command === 'cancel') this.pause();
+ else {
+ this.record();
+ this.onCommand('resume');
+ }
return;
}
if (command === 'intro:done') {
diff --git a/apps/desktop/src/renderer/overlay.css b/apps/desktop/src/renderer/overlay.css
index 99af9f4..38b443a 100644
--- a/apps/desktop/src/renderer/overlay.css
+++ b/apps/desktop/src/renderer/overlay.css
@@ -34,89 +34,178 @@ body.editor {
#region {
position: absolute;
- box-shadow: 0 0 0 100vmax rgba(30, 27, 75, 0.38);
- outline: 2px dashed var(--accent);
- outline-offset: -1px;
+ border: 2px solid #fff;
+ box-shadow: 0 0 0 100vmax rgba(30, 27, 75, 0.55);
cursor: move;
}
+#region::after {
+ content: '';
+ position: absolute;
+ inset: -2px;
+ border: 2px dashed var(--accent);
+ pointer-events: none;
+}
+
#region.empty {
display: none;
}
#size {
position: absolute;
- top: -26px;
- left: 0;
- padding: 2px 8px;
+ top: 12px;
+ left: 12px;
+ padding: 3px 9px;
border-radius: 6px;
background: var(--deep);
- color: var(--lavender);
- font-size: 11px;
+ color: #fff;
+ font-family: 'Poppins', system-ui, sans-serif;
+ font-size: 11.5px;
+ font-weight: 600;
font-variant-numeric: tabular-nums;
}
.handle {
position: absolute;
- width: 12px;
- height: 12px;
- border: 2px solid var(--accent);
- border-radius: 3px;
- background: #fff;
+ z-index: 1;
}
-.handle[data-handle^='n'] {
- top: -6px;
-}
-.handle[data-handle^='s'] {
- bottom: -6px;
-}
-.handle[data-handle$='w'] {
- left: -6px;
-}
-.handle[data-handle$='e'] {
- right: -6px;
-}
.handle[data-handle='n'],
.handle[data-handle='s'] {
- left: calc(50% - 6px);
+ left: 26px;
+ right: 26px;
+ height: 12px;
+ cursor: ns-resize;
}
-.handle[data-handle='w'],
-.handle[data-handle='e'] {
- top: calc(50% - 6px);
+.handle[data-handle='n'] {
+ top: -8px;
}
-.handle[data-handle='n'],
.handle[data-handle='s'] {
- cursor: ns-resize;
+ bottom: -8px;
}
.handle[data-handle='w'],
.handle[data-handle='e'] {
+ top: 26px;
+ bottom: 26px;
+ width: 12px;
cursor: ew-resize;
}
+.handle[data-handle='w'] {
+ left: -8px;
+}
+.handle[data-handle='e'] {
+ right: -8px;
+}
+
.handle[data-handle='nw'],
+.handle[data-handle='ne'],
+.handle[data-handle='se'],
+.handle[data-handle='sw'] {
+ width: 26px;
+ height: 26px;
+ border: 0 solid var(--accent);
+ filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
+}
+.handle[data-handle='nw'] {
+ top: -2px;
+ left: -2px;
+ border-width: 4px 0 0 4px;
+ cursor: nwse-resize;
+}
+.handle[data-handle='ne'] {
+ top: -2px;
+ right: -2px;
+ border-width: 4px 4px 0 0;
+ cursor: nesw-resize;
+}
.handle[data-handle='se'] {
+ bottom: -2px;
+ right: -2px;
+ border-width: 0 4px 4px 0;
cursor: nwse-resize;
}
-.handle[data-handle='ne'],
.handle[data-handle='sw'] {
+ bottom: -2px;
+ left: -2px;
+ border-width: 0 0 4px 4px;
cursor: nesw-resize;
}
-#hint {
+#bar {
position: absolute;
+ top: 20px;
left: 50%;
- bottom: 40px;
transform: translateX(-50%);
- padding: 10px 16px;
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 8px 8px 8px 16px;
+ border-radius: 12px;
+ border: 1px solid var(--lavender);
+ background: #fff;
+ box-shadow: 0 12px 30px rgba(15, 14, 40, 0.28);
+ font-family: 'Poppins', system-ui, sans-serif;
+ cursor: default;
+}
+
+#barText {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 12.5px;
+ font-weight: 500;
+ color: var(--deep);
+ white-space: nowrap;
+}
+
+#barText svg {
+ color: var(--accent);
+}
+
+#barActions {
+ display: flex;
+ gap: 8px;
+}
+
+#bar button {
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ height: 36px;
+ padding: 0 14px;
border-radius: 10px;
- background: var(--deep);
- font-size: 12px;
+ font-family: inherit;
+ font-size: 12.5px;
+ font-weight: 600;
white-space: nowrap;
+ cursor: pointer;
}
-#hint b {
- color: #fff;
+#bar button.secondary {
+ border: 1px solid var(--lavender);
+ background: #fff;
+ color: var(--deep);
+}
+
+#bar button.primary {
+ border: 0;
+ background: var(--deep);
+ color: var(--lavender);
+}
+
+#bar kbd {
+ padding: 1px 6px;
+ border-radius: 5px;
+ font-family: inherit;
+ font-size: 10.5px;
font-weight: 600;
+ background: #eef2ff;
+ color: var(--deep);
+}
+
+#bar button.primary kbd {
+ background: rgba(199, 210, 254, 0.18);
+ color: var(--lavender);
}
body.boundary #frame {
diff --git a/apps/desktop/src/renderer/overlay/editor.ts b/apps/desktop/src/renderer/overlay/editor.ts
index 4bde3a5..5d1852e 100644
--- a/apps/desktop/src/renderer/overlay/editor.ts
+++ b/apps/desktop/src/renderer/overlay/editor.ts
@@ -1,3 +1,4 @@
+import { icon } from '../icons';
import { el } from './el';
import type { Region } from './types';
@@ -27,16 +28,23 @@ export function editor(origin: { x: number; y: number }): void {
region.append(node);
}
- const hint = el(
+ const cancel = el('button', { type: 'button', className: 'secondary' }, 'Cancel', el('kbd', {}, 'Esc'));
+ const done = el(
+ 'button',
+ { type: 'button', className: 'primary' },
+ icon('check', 15),
+ 'Done',
+ el('kbd', {}, 'Enter'),
+ );
+ cancel.addEventListener('click', () => window.mimikOverlay.command('cancel'));
+ done.addEventListener('click', () => window.mimikOverlay.command('arm'));
+ const bar = el(
'div',
- { id: 'hint' },
- 'Drag to set the capture area β€” ',
- el('b', {}, 'Enter'),
- ' to confirm, ',
- el('b', {}, 'Esc'),
- ' to cancel',
+ { id: 'bar' },
+ el('span', { id: 'barText' }, icon('area', 15), 'Drag to draw the capture area'),
+ el('span', { id: 'barActions' }, cancel, done),
);
- document.body.append(region, hint);
+ document.body.append(region, bar);
let rect: Region | null = null;
@@ -67,6 +75,7 @@ export function editor(origin: { x: number; y: number }): void {
document.body.addEventListener('pointerdown', (event) => {
const target = event.target as HTMLElement;
+ if (bar.contains(target)) return;
const handle = target.dataset.handle as Handle | undefined;
const moving = !handle && region.contains(target) && rect !== null;
const start = { x: event.clientX + origin.x, y: event.clientY + origin.y };