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,11 @@
export interface ShortcutConfig {
generalAssist: string;
quickAsk: string;
autocomplete: string;
}
const DEFAULTS: ShortcutConfig = {
generalAssist: 'CommandOrControl+Shift+S',
quickAsk: 'CommandOrControl+Alt+S',
autocomplete: 'CommandOrControl+Shift+Space',
generalAssist: 'Alt+Shift+G',
quickAsk: 'Alt+Shift+Q',
};
const STORE_KEY = 'shortcuts';
@ -27,14 +25,16 @@ async function getStore() {
export async function getShortcuts(): Promise<ShortcutConfig> {
const s = await getStore();
const stored = s.get(STORE_KEY) as Partial<ShortcutConfig> | undefined;
return { ...DEFAULTS, ...stored };
const raw = (s.get(STORE_KEY) as Record<string, string> | undefined) ?? {};
const { autocomplete: _drop, ...rest } = raw;
return { ...DEFAULTS, ...rest };
}
export async function setShortcuts(config: Partial<ShortcutConfig>): Promise<ShortcutConfig> {
const s = await getStore();
const current = (s.get(STORE_KEY) as ShortcutConfig) ?? DEFAULTS;
const merged = { ...current, ...config };
const raw = (s.get(STORE_KEY) as Record<string, string> | undefined) ?? {};
const { autocomplete: _drop, ...current } = raw;
const merged = { ...DEFAULTS, ...current, ...config };
s.set(STORE_KEY, merged);
return merged;
}

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);

View file

@ -1,5 +1,6 @@
import { app, BrowserWindow, shell, session } from 'electron';
import path from 'path';
import { trackEvent } from './analytics';
import { showErrorDialog } from './errors';
import { getServerPort } from './server';
import { setActiveSearchSpaceId } from './active-search-space';
@ -93,3 +94,15 @@ export function createMainWindow(initialPath = '/dashboard'): BrowserWindow {
return mainWindow;
}
export 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 });
}