SonarQube dev scan (localhost:9000, project max-app) flagged 2 bugs, 6 vulnerabilities and 3 code smells; quality gate now passes. - visionCapture.ts: .sort() without a compare function relied on locale- dependent default ordering — fixed with localeCompare. - index.html: added missing lang="fr" on <html>; documented why style-src keeps 'unsafe-inline' (React/mermaid inline styles) while script-src stays strictly 'self'. - drawingWindow.ts/exerciseWindow.ts/windowBridge.ts: replaced Math.random() with crypto.randomUUID() for IPC correlation ids (flagged as insecure PRNG, even though these ids are never security-sensitive). - translate.ts/deleteFileOrFolder.ts: replaced two regexes flagged for superlinear backtracking with plain indexOf/loop-based equivalents. - App.tsx: documented with NOSONAR why the whole-window drag surface isn't given fake keyboard interactivity (no keyboard gesture equivalent to "drag the window"; would also break tab order). - drawingWindow.ts: extracted the near-identical request/ack/timeout boilerplate shared by revealShape() and playCaption() into waitForAck(), fixing a new-code duplication-density quality gate failure surfaced once these lines were touched. Also fixes the Gitea CI "Security audit" step (npm audit --audit-level=high): pptxgenjs@4.0.1 pinned image-size to ^1.2.1, within the high-severity DoS range (GHSA-5p2g-fcmc-qvqq / GHSA-w3rx-r6r6-pgpr, affects <=2.0.2). Added an npm "overrides" entry forcing image-size to ^2.0.4 under pptxgenjs. The affected code path (image embedding) isn't even used by createPowerpoint.ts, and existing tests still pass. Remaining audit findings are all moderate, dev-tooling-only (eslint/electron-builder's minimatch/glob chain). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
107 lines
3.7 KiB
TypeScript
107 lines
3.7 KiB
TypeScript
import { randomUUID } from 'crypto'
|
|
import { BrowserWindow, ipcMain, type IpcMainEvent } from 'electron'
|
|
import { join } from 'path'
|
|
import { is } from '@electron-toolkit/utils'
|
|
import type { ExerciseFormAnswer, ExerciseFormItem } from '../../shared/coach'
|
|
import { SECURE_WEB_PREFERENCES, blockExternalNavigation } from '../utils/windowSecurity'
|
|
|
|
let win: BrowserWindow | null = null
|
|
|
|
// Delai avant fermeture automatique de la fenetre une fois le formulaire soumis (demande
|
|
// utilisateur explicite : la fenetre ne doit pas rester ouverte indefiniment apres soumission).
|
|
const AUTO_CLOSE_DELAY_MS = 2000
|
|
|
|
// Fenetre normale et independante de l'avatar et de la courbe d'apprentissage, meme pattern
|
|
// singleton que progressWindow.ts.
|
|
function ensureWindow(): BrowserWindow {
|
|
if (win && !win.isDestroyed()) return win
|
|
|
|
win = new BrowserWindow({
|
|
width: 520,
|
|
height: 480,
|
|
title: 'Max — exercice',
|
|
alwaysOnTop: true,
|
|
webPreferences: {
|
|
preload: join(__dirname, '../preload/index.js'),
|
|
...SECURE_WEB_PREFERENCES
|
|
}
|
|
})
|
|
blockExternalNavigation(win)
|
|
// Niveau en dessous de l'avatar ('screen-saver') mais au-dessus de tout le reste, y compris une
|
|
// appli en plein ecran : sans ca, la fenetre pouvait s'ouvrir derriere le premier plan actuel et
|
|
// l'utilisateur devait la retrouver via la barre des taches (constate en test reel).
|
|
win.setAlwaysOnTop(true, 'floating')
|
|
win.maximize()
|
|
win.on('closed', () => {
|
|
win = null
|
|
})
|
|
|
|
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
|
void win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}#coach-exercise`)
|
|
} else {
|
|
void win.loadFile(join(__dirname, '../renderer/index.html'), { hash: 'coach-exercise' })
|
|
}
|
|
return win
|
|
}
|
|
|
|
export interface QuestionInput {
|
|
question: string
|
|
type: ExerciseFormItem['type']
|
|
options: string[] | null
|
|
}
|
|
|
|
/**
|
|
* Ouvre la fenetre d'exercice, pose TOUTES les questions en une seule fois (formulaire groupe, pas
|
|
* une par une : demande utilisateur explicite) et attend la soumission de l'utilisateur. Renvoie un
|
|
* tableau de reponses (meme ordre que `questions`), `null` par entree si la fenetre est fermee sans
|
|
* soumission ou si le delai est depasse. La fenetre se ferme automatiquement 2 secondes apres
|
|
* soumission.
|
|
*/
|
|
export function requestWrittenAnswers(
|
|
questions: QuestionInput[],
|
|
timeoutMs = 30 * 60 * 1000
|
|
): Promise<(string | null)[]> {
|
|
return new Promise((resolve) => {
|
|
const window = ensureWindow()
|
|
window.show()
|
|
window.moveTop()
|
|
window.focus()
|
|
const requestId = randomUUID()
|
|
const items: ExerciseFormItem[] = questions.map((q, index) => ({
|
|
id: String(index),
|
|
question: q.question,
|
|
type: q.type,
|
|
options: q.options
|
|
}))
|
|
|
|
let settled = false
|
|
const finish = (answers: (string | null)[]): void => {
|
|
if (settled) return
|
|
settled = true
|
|
clearTimeout(timeout)
|
|
ipcMain.removeListener('written-form-result', handler)
|
|
resolve(answers)
|
|
}
|
|
|
|
const timeout = setTimeout(() => finish(items.map(() => null)), timeoutMs)
|
|
|
|
function handler(_event: IpcMainEvent, id: string, answers: ExerciseFormAnswer[]): void {
|
|
if (id !== requestId) return
|
|
const byId = new Map(answers.map((a) => [a.id, a.answer]))
|
|
finish(items.map((item) => byId.get(item.id) ?? null))
|
|
setTimeout(() => {
|
|
if (win && !win.isDestroyed()) win.close()
|
|
}, AUTO_CLOSE_DELAY_MS)
|
|
}
|
|
ipcMain.on('written-form-result', handler)
|
|
window.once('closed', () => finish(items.map(() => null)))
|
|
|
|
const send = (): void => window.webContents.send('ask-written-form', { requestId, items })
|
|
if (window.webContents.isLoading()) {
|
|
window.webContents.once('did-finish-load', send)
|
|
} else {
|
|
send()
|
|
}
|
|
})
|
|
}
|