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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
242aa1d708
commit
cb9b4177e4
@@ -1,5 +1,5 @@
|
|||||||
import 'dotenv/config'
|
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 { join } from 'path'
|
||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import { transcribeAudio, synthesizeSpeech } from './ai/elevenlabs'
|
import { transcribeAudio, synthesizeSpeech } from './ai/elevenlabs'
|
||||||
@@ -138,43 +138,28 @@ app
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('show-context-menu', (event, listening: boolean) => {
|
// Le menu contextuel lui-meme est rendu cote renderer (ContextMenu.tsx, stylable avec le
|
||||||
const loggedIn = isLoggedIn()
|
// design system) : le main process n'expose plus qu'un menu natif Electron (impossible a
|
||||||
const menu = Menu.buildFromTemplate([
|
// styliser en CSS), seulement les quelques actions qui doivent rester ici (ouvrir la fenetre
|
||||||
// Statut de connexion en premier, en guise de titre du menu (Electron n'a pas de vrai
|
// de connexion, effacer la session en memoire, quitter l'app, redimensionner la fenetre).
|
||||||
// titre de menu contextuel independant des items). L'ecoute vocale reste desactivee tant
|
ipcMain.on('open-login-window', () => openLoginWindow())
|
||||||
// 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).
|
ipcMain.on('logout', (event) => {
|
||||||
loggedIn
|
clearSession()
|
||||||
? { label: `Connecte : ${getCurrentUserEmail()}`, enabled: false }
|
event.sender.send('toggle-listening', false)
|
||||||
: { label: 'Me connecter', click: () => openLoginWindow() },
|
})
|
||||||
...(loggedIn
|
|
||||||
? [
|
ipcMain.on('quit-app', () => app.quit())
|
||||||
{
|
|
||||||
label: 'Se deconnecter',
|
const BASE_WINDOW_WIDTH = 420
|
||||||
click: (): void => {
|
const PIPELINE_PANEL_WIDTH = 200
|
||||||
clearSession()
|
|
||||||
event.sender.send('toggle-listening', false)
|
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
|
||||||
{ type: 'separator' },
|
mainWindow.setBounds({ x: bounds.x, y: bounds.y, width: targetWidth, height: bounds.height })
|
||||||
{
|
|
||||||
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 })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.handle(
|
ipcMain.handle(
|
||||||
|
|||||||
Vendored
+4
-1
@@ -19,7 +19,10 @@ export interface ForgeAvatarApi {
|
|||||||
getWindowBounds: () => Promise<{ x: number; y: number; width: number; height: number }>
|
getWindowBounds: () => Promise<{ x: number; y: number; width: number; height: number }>
|
||||||
setWindowPosition: (x: number, y: number, width: number, height: number) => void
|
setWindowPosition: (x: number, y: number, width: number, height: number) => void
|
||||||
sendVoiceTurn: (audio: ArrayBuffer, mimeType: string) => Promise<VoiceTurnResult>
|
sendVoiceTurn: (audio: ArrayBuffer, mimeType: string) => Promise<VoiceTurnResult>
|
||||||
showContextMenu: (listening: boolean) => void
|
openLoginWindow: () => void
|
||||||
|
logout: () => void
|
||||||
|
quitApp: () => void
|
||||||
|
setPipelinePanelVisible: (visible: boolean) => void
|
||||||
onToggleListening: (callback: (listening: boolean) => void) => () => void
|
onToggleListening: (callback: (listening: boolean) => void) => () => void
|
||||||
onProactiveSpeech: (callback: (audio: ArrayBuffer) => void) => () => void
|
onProactiveSpeech: (callback: (audio: ArrayBuffer) => void) => () => void
|
||||||
onUpdateAvailable: (callback: () => void) => () => void
|
onUpdateAvailable: (callback: () => void) => () => void
|
||||||
|
|||||||
@@ -19,8 +19,17 @@ const api = {
|
|||||||
},
|
},
|
||||||
sendVoiceTurn: (audio: ArrayBuffer, mimeType: string): Promise<VoiceTurnResult> =>
|
sendVoiceTurn: (audio: ArrayBuffer, mimeType: string): Promise<VoiceTurnResult> =>
|
||||||
ipcRenderer.invoke('voice-turn', audio, mimeType),
|
ipcRenderer.invoke('voice-turn', audio, mimeType),
|
||||||
showContextMenu: (listening: boolean): void => {
|
openLoginWindow: (): void => {
|
||||||
ipcRenderer.send('show-context-menu', listening)
|
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) => {
|
onToggleListening: (callback: (listening: boolean) => void): (() => void) => {
|
||||||
const handler = (_event: Electron.IpcRendererEvent, listening: boolean): void =>
|
const handler = (_event: Electron.IpcRendererEvent, listening: boolean): void =>
|
||||||
|
|||||||
Reference in New Issue
Block a user