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): record clicks and keys on macOS through the addon's event tap

Luis Ortiz96d5eaea8061
diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.yml
index 722f3e0..f58f904 100644
--- a/apps/desktop/electron-builder.yml
+++ b/apps/desktop/electron-builder.yml
@@ -26,9 +26,12 @@ publish:
repo: mimik
mac:
category: public.app-category.productivity
+ artifactName: ${productName}-${version}-${arch}.${ext}
target:
- dmg
- zip
+ extendInfo:
+ NSMicrophoneUsageDescription: Mimik listens while you narrate a recording, when you turn narration on.
win:
target:
- nsis
diff --git a/apps/desktop/scripts/third-party-notices.ts b/apps/desktop/scripts/third-party-notices.ts
index 51307f1..fdbf76e 100644
--- a/apps/desktop/scripts/third-party-notices.ts
+++ b/apps/desktop/scripts/third-party-notices.ts
@@ -28,6 +28,11 @@ interface CrateNode {
const APP = resolve(__dirname, '..');
const ADDON = resolve(APP, '../../packages/capture-native');
+const ADDON_TARGETS: Record<string, string> = {
+ 'capture-native.win32-x64-msvc.node': 'x86_64-pc-windows-msvc',
+ 'capture-native.darwin-arm64.node': 'aarch64-apple-darwin',
+ 'capture-native.darwin-x64.node': 'x86_64-apple-darwin',
+};
const OUT = join(APP, 'out/THIRD_PARTY_NOTICES.txt');
const LICENCE_FILE = /^(licen[cs]e|copying|notice|copyright)([.\-_].*)?$/i;
const PACKAGE_DIR = /^(.*[\\/]node_modules[\\/](?:@[^\\/]+[\\/])?[^\\/]+)[\\/]/;
@@ -106,8 +111,9 @@ function shippedPackages(): string[] {
}
function crateNotices(): Notice[] {
- if (!existsSync(join(ADDON, 'capture-native.win32-x64-msvc.node'))) return [];
- const args = ['metadata', '--format-version', '1', '--offline', '--filter-platform', 'x86_64-pc-windows-msvc'];
+ const target = Object.entries(ADDON_TARGETS).find(([binary]) => existsSync(join(ADDON, binary)))?.[1];
+ if (!target) return [];
+ const args = ['metadata', '--format-version', '1', '--offline', '--filter-platform', target];
const meta: { packages: Crate[]; resolve: { root: string; nodes: CrateNode[] } } = JSON.parse(
execFileSync('cargo', [...args, '--manifest-path', join(ADDON, 'Cargo.toml')], {
encoding: 'utf8',
diff --git a/apps/desktop/src/main/capture/focused-window.ts b/apps/desktop/src/main/capture/focused-window.ts
index 905b32a..8e0bd11 100644
--- a/apps/desktop/src/main/capture/focused-window.ts
+++ b/apps/desktop/src/main/capture/focused-window.ts
@@ -40,8 +40,10 @@ function fromNative(found: ActiveWindow): FocusedWindowResult {
};
}
+const NATIVE_WINDOWS = new Set<NodeJS.Platform>(['win32', 'darwin']);
+
export async function windowAt(point: { x: number; y: number }): Promise<FocusedWindowResult> {
- if (process.platform === 'win32') {
+ if (NATIVE_WINDOWS.has(process.platform)) {
const physical = typeof screen.dipToScreenPoint === 'function' ? screen.dipToScreenPoint(point) : point;
const found = await loadNative()
.then((native) => native?.windowAt(Math.round(physical.x), Math.round(physical.y)) ?? null)
@@ -60,7 +62,7 @@ export async function focusedWindow(): Promise<FocusedWindowResult> {
};
}
- if (process.platform === 'win32') {
+ if (NATIVE_WINDOWS.has(process.platform)) {
const found = await loadNative()
.then((native) => native?.activeWindow() ?? null)
.catch(() => null);
diff --git a/apps/desktop/src/main/capture/input-hook.ts b/apps/desktop/src/main/capture/input-hook.ts
index 7990a78..5965e7a 100644
--- a/apps/desktop/src/main/capture/input-hook.ts
+++ b/apps/desktop/src/main/capture/input-hook.ts
@@ -1,3 +1,6 @@
+import type { HookEvent } from '@mimik/capture-native';
+import { loadNative } from './native';
+
export interface PointerAction {
kind: 'click';
button: number;
@@ -23,6 +26,27 @@ export type InputHookStart =
| { ok: true }
| { ok: false; reason: 'unsupported-session' | 'unavailable'; detail: string };
+const macTap: { started: boolean; listener: ((action: InputAction) => void) | null } = {
+ started: false,
+ listener: null,
+};
+
+function fromTap(event: HookEvent): InputAction {
+ const at = Date.now();
+ if (event.kind === 'click') {
+ return { kind: 'click', button: event.button, x: event.x, y: event.y, clicks: event.clicks, at };
+ }
+ return {
+ kind: 'keydown',
+ keycode: event.keycode,
+ shift: event.shift,
+ alt: event.alt,
+ ctrl: event.ctrl,
+ meta: event.meta,
+ at,
+ };
+}
+
export class InputHook {
private hook: typeof import('uiohook-napi').uIOhook | null = null;
private running = false;
@@ -42,6 +66,23 @@ export class InputHook {
};
}
+ if (process.platform === 'darwin') {
+ try {
+ macTap.listener = onAction;
+ if (!macTap.started) {
+ const native = await loadNative();
+ if (!native) throw new Error('the capture addon is missing');
+ native.startInputHook((event) => macTap.listener?.(fromTap(event)));
+ macTap.started = true;
+ }
+ this.running = true;
+ return { ok: true };
+ } catch (error) {
+ macTap.listener = null;
+ return { ok: false, reason: 'unavailable', detail: error instanceof Error ? error.message : String(error) };
+ }
+ }
+
try {
const { uIOhook } = await import('uiohook-napi');
this.hook = uIOhook;
@@ -79,10 +120,14 @@ export class InputHook {
}
stop(): void {
- if (!this.running || !this.hook) return;
- this.hook.removeAllListeners();
- this.hook.stop();
+ if (!this.running) return;
this.running = false;
+ if (process.platform === 'darwin') {
+ macTap.listener = null;
+ return;
+ }
+ this.hook?.removeAllListeners();
+ this.hook?.stop();
this.hook = null;
}
diff --git a/apps/desktop/src/main/capture/native.ts b/apps/desktop/src/main/capture/native.ts
index defc7fc..2ed00e6 100644
--- a/apps/desktop/src/main/capture/native.ts
+++ b/apps/desktop/src/main/capture/native.ts
@@ -1,4 +1,4 @@
-import type { ActiveWindow, UiElement } from '@mimik/capture-native';
+import type { ActiveWindow, HookEvent, UiElement } from '@mimik/capture-native';
export type Addon = {
elementAtPoint(x: number, y: number): Promise<UiElement | null>;
@@ -9,6 +9,7 @@ export type Addon = {
resolveKey(keycode: number, shift: boolean, ctrl: boolean, alt: boolean): string | null;
clearDeadKey(): void;
isSupported(): boolean;
+ startInputHook(callback: (event: HookEvent) => void): void;
};
let addon: Addon | null | undefined;
diff --git a/apps/desktop/src/main/capture/recorder.ts b/apps/desktop/src/main/capture/recorder.ts
index fa5a138..49a4523 100644
--- a/apps/desktop/src/main/capture/recorder.ts
+++ b/apps/desktop/src/main/capture/recorder.ts
@@ -126,9 +126,10 @@ export function isRepeatKey(previous: { keycode: number; at: number } | null, ke
export function comboLabel(action: KeyAction, key: string): string {
const held: string[] = [];
- if (action.meta) held.push('Meta');
+ const mac = process.platform === 'darwin';
+ if (action.meta) held.push(mac ? 'Cmd' : 'Meta');
if (action.ctrl) held.push('Ctrl');
- if (action.alt) held.push('Alt');
+ if (action.alt) held.push(mac ? 'Option' : 'Alt');
if (action.shift) held.push('Shift');
return [...held, key].join('+');
}
@@ -170,7 +171,7 @@ export function isBoundShortcut(accelerator: string | null, action: KeyAction, k
export function isTextKey(action: KeyAction): boolean {
if (MODIFIER_KEYS.has(action.keycode)) return false;
- if (action.ctrl || action.alt || action.meta) return false;
+ if (action.ctrl || action.meta || (action.alt && process.platform !== 'darwin')) return false;
return !COMMIT_KEYS.has(action.keycode);
}