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): reach the capture overlay from the app shell and tray

Luis Ortizd6e2b9dd527f
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index aeb29d3..e1f5b44 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -1,9 +1,11 @@
import { join } from 'node:path';
import { app, BrowserWindow, ipcMain, Menu, nativeImage, shell, Tray } from 'electron';
+import { CaptureOverlay, type OverlayCommand } from './overlay';
import { checkForUpdates } from './updater';
let mainWindow: BrowserWindow | null = null;
let tray: Tray | null = null;
+let overlay: CaptureOverlay | null = null;
function resource(file: string): string {
return app.isPackaged ? join(process.resourcesPath, file) : join(__dirname, '../../resources', file);
@@ -76,6 +78,7 @@ function refreshTrayMenu(): void {
tray.setContextMenu(
Menu.buildFromTemplate([
{ label: 'Open Mimik', click: () => showWindow() },
+ { label: 'Set capture area', click: () => overlay?.edit() },
{ type: 'separator' },
{
label: 'Start at login',
@@ -98,6 +101,10 @@ function createTray(): void {
refreshTrayMenu();
}
+function broadcastOverlay(command: OverlayCommand): void {
+ mainWindow?.webContents.send('mimik:capture:command', command, overlay?.state, overlay?.region);
+}
+
let isQuitting = false;
function quit(): void {
@@ -118,6 +125,10 @@ if (!app.requestSingleInstanceLock()) {
});
ipcMain.handle('mimik:version', () => app.getVersion());
+ overlay = new CaptureOverlay(broadcastOverlay);
+ ipcMain.handle('mimik:capture:region', () => overlay?.region);
+ ipcMain.handle('mimik:capture:edit', () => overlay?.edit());
+
createWindow();
createTray();
checkForUpdates({ notifyWhenUpToDate: false });
@@ -126,6 +137,7 @@ if (!app.requestSingleInstanceLock()) {
app.on('activate', () => showWindow());
app.on('before-quit', () => {
isQuitting = true;
+ overlay?.destroy();
});
app.on('window-all-closed', () => {});
}
diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts
index 8b40eec..4c2b23b 100644
--- a/apps/desktop/src/preload/index.ts
+++ b/apps/desktop/src/preload/index.ts
@@ -1,7 +1,23 @@
import { contextBridge, ipcRenderer } from 'electron';
+interface Region {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+}
+
const api = {
version: (): Promise<string> => ipcRenderer.invoke('mimik:version'),
+ capture: {
+ region: (): Promise<Region> => ipcRenderer.invoke('mimik:capture:region'),
+ edit: (): Promise<void> => ipcRenderer.invoke('mimik:capture:edit'),
+ onCommand: (handler: (command: string, state: string, region: Region) => void): void => {
+ ipcRenderer.on('mimik:capture:command', (_event, command: string, state: string, region: Region) =>
+ handler(command, state, region),
+ );
+ },
+ },
openAtLogin: {
get: (): Promise<boolean> => ipcRenderer.invoke('mimik:openAtLogin:get'),
set: (enabled: boolean): Promise<boolean> => ipcRenderer.invoke('mimik:openAtLogin:set', enabled),
diff --git a/apps/desktop/src/renderer/main.ts b/apps/desktop/src/renderer/main.ts
index 09f4430..384eea1 100644
--- a/apps/desktop/src/renderer/main.ts
+++ b/apps/desktop/src/renderer/main.ts
@@ -7,6 +7,17 @@ declare global {
mimik: {
version(): Promise<string>;
openAtLogin: { get(): Promise<boolean>; set(enabled: boolean): Promise<boolean> };
+ capture: {
+ region(): Promise<{ x: number; y: number; width: number; height: number }>;
+ edit(): Promise<void>;
+ onCommand(
+ handler: (
+ command: string,
+ state: string,
+ region: { x: number; y: number; width: number; height: number },
+ ) => void,
+ ): void;
+ };
};
}
}
@@ -14,7 +25,11 @@ declare global {
const root = document.getElementById('root') as HTMLElement;
async function render(): Promise<void> {
- const [version, atLogin] = await Promise.all([window.mimik.version(), window.mimik.openAtLogin.get()]);
+ const [version, atLogin, region] = await Promise.all([
+ window.mimik.version(),
+ window.mimik.openAtLogin.get(),
+ window.mimik.capture.region(),
+ ]);
root.replaceChildren();
const title = document.createElement('h1');
@@ -37,7 +52,19 @@ async function render(): Promise<void> {
shared.className = 'meta';
shared.textContent = `Smart Blur categories from @mimik/core: ${Object.values(PRESET_LABELS).join(', ')}`;
- root.append(title, meta, label, shared);
+ const area = document.createElement('p');
+ area.className = 'meta';
+ area.textContent = `Capture area ${region.width} Γ— ${region.height} at ${region.x}, ${region.y}`;
+
+ const edit = document.createElement('button');
+ edit.textContent = 'Set capture area';
+ edit.addEventListener('click', () => window.mimik.capture.edit());
+
+ window.mimik.capture.onCommand((_command, _state, next) => {
+ area.textContent = `Capture area ${next.width} Γ— ${next.height} at ${next.x}, ${next.y}`;
+ });
+
+ root.append(title, meta, label, area, edit, shared);
}
render();