Step 1 of adding a backend proxy server (API keys held server-side instead of shipped in the installer). Moves everything app-specific into "Max Avatar/" via git mv (preserves history): src/, tests/, scripts/, assets/, build/, resources/, package.json/-lock.json, electron-builder.yml, electron.vite.config.ts, eslint.config.mjs, playwright.config.ts, vitest.config.mts, sonar-project.properties, tsconfig*.json, Dockerfile, .editorconfig/.env*/.gitignore/.prettier*. CLAUDE.md, README.md, docs/, .claude/, .gitea/, .husky/, .vscode/, and the docker-compose files stay at the repo root, since they'll apply to both the app and the future backend. No application code needed changes (all its internal paths are relative to its own tree). Adjusted what referenced the old root from outside: - .husky/pre-commit: cd into "Max Avatar" before lint-staged - .gitea/workflows/*.yml: working-directory + cache-dependency-path + artifact paths + SonarQube projectBaseDir - docker-compose.yml: build context -> ./Max Avatar - Max Avatar/Dockerfile: node:20-alpine -> node:24-alpine (same node:sqlite issue already fixed elsewhere, never applied here before) - .vscode/launch.json, README.md: updated paths/instructions Verified from Max Avatar/ after the move: npm ci, typecheck, lint, test:coverage (473/473, same coverage numbers), build, and dev all work unchanged. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { app, desktopCapturer, screen } from 'electron'
|
|
import { Worker } from 'node:worker_threads'
|
|
import { existsSync, mkdirSync, readdirSync } from 'fs'
|
|
import { join } from 'path'
|
|
|
|
const CAPTURE_INTERVAL_MS = 1000
|
|
const ROLLING_WINDOW_MS = 7 * 60 * 60 * 1000
|
|
|
|
let worker: Worker | null = null
|
|
let intervalHandle: ReturnType<typeof setInterval> | null = null
|
|
|
|
function captureDir(): string {
|
|
const dir = join(app.getPath('userData'), 'coach-captures')
|
|
if (!existsSync(dir)) mkdirSync(dir, { recursive: true })
|
|
return dir
|
|
}
|
|
|
|
function ensureWorker(): Worker {
|
|
if (worker) return worker
|
|
worker = new Worker(join(__dirname, 'captureWorker.js'))
|
|
worker.on('error', (error) => console.error('[coach] erreur worker de capture', error))
|
|
return worker
|
|
}
|
|
|
|
async function captureOnce(): Promise<void> {
|
|
const display = screen.getPrimaryDisplay()
|
|
const sources = await desktopCapturer.getSources({
|
|
types: ['screen'],
|
|
thumbnailSize: display.size
|
|
})
|
|
const source = sources[0]
|
|
if (!source) return
|
|
|
|
const png = source.thumbnail.toPNG()
|
|
const filePath = join(captureDir(), `capture-${Date.now()}.png`)
|
|
ensureWorker().postMessage({ filePath, png })
|
|
}
|
|
|
|
function purgeOldCaptures(): void {
|
|
const cutoff = Date.now() - ROLLING_WINDOW_MS
|
|
ensureWorker().postMessage({ purgeDir: captureDir(), cutoff })
|
|
}
|
|
|
|
let tickCount = 0
|
|
|
|
export function startVisionCapture(): void {
|
|
if (intervalHandle) return
|
|
intervalHandle = setInterval(() => {
|
|
tickCount += 1
|
|
captureOnce().catch((error) => console.error('[coach] echec capture ecran', error))
|
|
if (tickCount % 60 === 0) purgeOldCaptures()
|
|
}, CAPTURE_INTERVAL_MS)
|
|
}
|
|
|
|
export function stopVisionCapture(): void {
|
|
if (intervalHandle) {
|
|
clearInterval(intervalHandle)
|
|
intervalHandle = null
|
|
}
|
|
}
|
|
|
|
export function getRecentCaptures(count: number): string[] {
|
|
const dir = captureDir()
|
|
if (!existsSync(dir)) return []
|
|
return readdirSync(dir)
|
|
.filter((f: string) => f.endsWith('.png'))
|
|
.sort((a, b) => a.localeCompare(b))
|
|
.slice(-count)
|
|
.map((f: string) => join(dir, f))
|
|
}
|