Wire General Assist and screen capture through Electron IPC

This commit is contained in:
CREDO23 2026-04-24 19:14:37 +02:00
parent 7097f542fb
commit b0810b4d47
7 changed files with 40 additions and 49 deletions

View file

@ -1,13 +1,14 @@
import { app, globalShortcut, Menu, nativeImage, Tray } from 'electron';
import { app, globalShortcut, Menu, nativeImage, Tray, type NativeImage } from 'electron';
import path from 'path';
import { getMainWindow, createMainWindow } from './window';
import { runGeneralAssistShortcut } from './general-assist';
import { showMainWindow } from './window';
import { getShortcuts } from './shortcuts';
import { trackEvent } from './analytics';
let tray: Tray | null = null;
let currentShortcut: string | null = null;
function getTrayIcon(): nativeImage {
function getTrayIcon(): NativeImage {
const iconName = process.platform === 'win32' ? 'icon.ico' : 'icon.png';
const iconPath = app.isPackaged
? path.join(process.resourcesPath, 'assets', iconName)
@ -16,18 +17,6 @@ function getTrayIcon(): nativeImage {
return img.resize({ width: 16, height: 16 });
}
function showMainWindow(source: 'tray_click' | 'tray_menu' | 'shortcut' = 'tray_click'): void {
const existing = getMainWindow();
const reopened = !existing || existing.isDestroyed();
if (reopened) {
createMainWindow('/dashboard');
} else {
existing.show();
existing.focus();
}
trackEvent('desktop_main_window_shown', { source, reopened });
}
function registerShortcut(accelerator: string): void {
if (currentShortcut) {
globalShortcut.unregister(currentShortcut);
@ -35,11 +24,14 @@ function registerShortcut(accelerator: string): void {
}
if (!accelerator) return;
try {
const ok = globalShortcut.register(accelerator, () => showMainWindow('shortcut'));
const ok = globalShortcut.register(accelerator, () => {
void runGeneralAssistShortcut();
});
if (ok) {
currentShortcut = accelerator;
console.log(`[general-assist] Register ${accelerator}: OK`);
} else {
console.warn(`[tray] Failed to register General Assist shortcut: ${accelerator}`);
console.warn(`[general-assist] Register ${accelerator}: FAILED (OS or another app may own this chord)`);
}
} catch (err) {
console.error(`[tray] Error registering General Assist shortcut:`, err);