From cb9b4177e488f6f31136e0b747cd5605662de341 Mon Sep 17 00:00:00 2001 From: william Date: Sat, 31 Oct 2026 22:38:07 +0100 Subject: [PATCH] refactor(ui): replace native context menu with renderer-driven IPC actions The native Electron Menu can't be styled with the design system CSS at all. Replace the single show-context-menu IPC call with 4 focused actions the renderer will drive from its own menu component: open-login-window, logout, quit-app, and set-pipeline-panel-visible (resizes the avatar window to make room for the pipeline stepper beside the avatar once a session is active). Co-Authored-By: Claude Sonnet 5 --- Max Avatar/src/main/index.ts | 61 ++++++++++++------------------- Max Avatar/src/preload/index.d.ts | 5 ++- Max Avatar/src/preload/index.ts | 13 ++++++- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/Max Avatar/src/main/index.ts b/Max Avatar/src/main/index.ts index b8ce1fb..5a64287 100644 --- a/Max Avatar/src/main/index.ts +++ b/Max Avatar/src/main/index.ts @@ -1,5 +1,5 @@ import 'dotenv/config' -import { app, session, shell, BrowserWindow, ipcMain, Menu } from 'electron' +import { app, session, shell, BrowserWindow, ipcMain } from 'electron' import { join } from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { transcribeAudio, synthesizeSpeech } from './ai/elevenlabs' @@ -138,43 +138,28 @@ app }) } - ipcMain.on('show-context-menu', (event, listening: boolean) => { - const loggedIn = isLoggedIn() - const menu = Menu.buildFromTemplate([ - // Statut de connexion en premier, en guise de titre du menu (Electron n'a pas de vrai - // titre de menu contextuel independant des items). L'ecoute vocale reste desactivee tant - // qu'aucun compte n'est connecte : elle depend des cles OpenRouter/ElevenLabs, fournies par - // Max API une fois connecte (voir docs/Architecture_Monorepo_Backend.md). - loggedIn - ? { label: `Connecte : ${getCurrentUserEmail()}`, enabled: false } - : { label: 'Me connecter', click: () => openLoginWindow() }, - ...(loggedIn - ? [ - { - label: 'Se deconnecter', - click: (): void => { - clearSession() - event.sender.send('toggle-listening', false) - } - } - ] - : []), - { type: 'separator' }, - { - label: 'Ecoute vocale', - type: 'checkbox', - // Force a decoche/desactive sans compte connecte, quel que soit l'etat transmis par le - // renderer (qui se remet lui-meme a false au demarrage/a la deconnexion, mais ce garde-fou - // cote menu evite tout affichage incoherent si jamais ce n'etait pas encore le cas). - checked: loggedIn && listening, - enabled: loggedIn, - click: () => event.sender.send('toggle-listening', !listening) - }, - { type: 'separator' }, - { label: 'Quitter', click: () => app.quit() } - ]) - const window = BrowserWindow.fromWebContents(event.sender) - if (window) menu.popup({ window }) + // Le menu contextuel lui-meme est rendu cote renderer (ContextMenu.tsx, stylable avec le + // design system) : le main process n'expose plus qu'un menu natif Electron (impossible a + // styliser en CSS), seulement les quelques actions qui doivent rester ici (ouvrir la fenetre + // de connexion, effacer la session en memoire, quitter l'app, redimensionner la fenetre). + ipcMain.on('open-login-window', () => openLoginWindow()) + + ipcMain.on('logout', (event) => { + clearSession() + event.sender.send('toggle-listening', false) + }) + + ipcMain.on('quit-app', () => app.quit()) + + const BASE_WINDOW_WIDTH = 420 + const PIPELINE_PANEL_WIDTH = 200 + + ipcMain.on('set-pipeline-panel-visible', (_event, visible: unknown) => { + if (typeof visible !== 'boolean' || !mainWindow) return + const bounds = mainWindow.getBounds() + const targetWidth = visible ? BASE_WINDOW_WIDTH + PIPELINE_PANEL_WIDTH : BASE_WINDOW_WIDTH + if (bounds.width === targetWidth) return + mainWindow.setBounds({ x: bounds.x, y: bounds.y, width: targetWidth, height: bounds.height }) }) ipcMain.handle( diff --git a/Max Avatar/src/preload/index.d.ts b/Max Avatar/src/preload/index.d.ts index 77af2f6..25ca151 100644 --- a/Max Avatar/src/preload/index.d.ts +++ b/Max Avatar/src/preload/index.d.ts @@ -19,7 +19,10 @@ export interface ForgeAvatarApi { getWindowBounds: () => Promise<{ x: number; y: number; width: number; height: number }> setWindowPosition: (x: number, y: number, width: number, height: number) => void sendVoiceTurn: (audio: ArrayBuffer, mimeType: string) => Promise - showContextMenu: (listening: boolean) => void + openLoginWindow: () => void + logout: () => void + quitApp: () => void + setPipelinePanelVisible: (visible: boolean) => void onToggleListening: (callback: (listening: boolean) => void) => () => void onProactiveSpeech: (callback: (audio: ArrayBuffer) => void) => () => void onUpdateAvailable: (callback: () => void) => () => void diff --git a/Max Avatar/src/preload/index.ts b/Max Avatar/src/preload/index.ts index c1cd9cf..4a3dd7e 100644 --- a/Max Avatar/src/preload/index.ts +++ b/Max Avatar/src/preload/index.ts @@ -19,8 +19,17 @@ const api = { }, sendVoiceTurn: (audio: ArrayBuffer, mimeType: string): Promise => ipcRenderer.invoke('voice-turn', audio, mimeType), - showContextMenu: (listening: boolean): void => { - ipcRenderer.send('show-context-menu', listening) + openLoginWindow: (): void => { + ipcRenderer.send('open-login-window') + }, + logout: (): void => { + ipcRenderer.send('logout') + }, + quitApp: (): void => { + ipcRenderer.send('quit-app') + }, + setPipelinePanelVisible: (visible: boolean): void => { + ipcRenderer.send('set-pipeline-panel-visible', visible) }, onToggleListening: (callback: (listening: boolean) => void): (() => void) => { const handler = (_event: Electron.IpcRendererEvent, listening: boolean): void =>