chore: sprint D — sandbox, self-hosted fonts, logger с ротацией

#6  sandbox: true на обоих BrowserWindow (раньше false). Preload
    использует только contextBridge + ipcRenderer (оба sandbox-safe),
    никаких Node-built-ins. OS-уровневый sandbox изолирует renderer
    от GPU/IPC процессов; даже RCE в зависимости renderer'а не
    получит Node-доступа через preload.

#17 self-host шрифтов через @fontsource/* пакеты. Раньше тянулись
    с fonts.googleapis.com — внешняя CSP-зависимость + отсутствие
    интернета = шрифты не загружались. Теперь .woff/.woff2 в bundle
    (22 файла × 15-30KB = ~500KB).
    Подкрутили CSP: убрали https://fonts.* origins, добавили
    connect-src 'self', base-uri 'self', frame-ancestors 'none'.

#22 src/main/logger.ts — структурный лог с уровнями
    (debug/info/warn/error) и ротацией. Пишет в
    %APPDATA%/Exercise Reminder/logs/latest.log (≤1MB) и
    дублирует в console. При 1MB latest.log → prev.log
    (предыдущий prev.log удаляется). LAUDE_DEBUG=1 включает
    debug-уровень.

    Подключён в hot paths: store (corrupt/atomic write fails),
    updater (silent check errors), gsi-server (bad requests,
    handler throws), games/registry (GSI start, reconcile, match_end
    summary), games/dota2 (rejected token, POST_GAME detection).

    Особенно полезно для диагностики «челленджи не срабатывают»:
    лог покажет (а) пришёл ли вообще GSI payload (token verify),
    (б) детектировался ли POST_GAME, (в) сколько challenges были
    enabled и которые из них дали 0 reps.

    Logger — единственный файл с `eslint-disable no-console` (он
    намеренно дублирует в stderr).
This commit is contained in:
AnRil
2026-05-22 01:24:30 +07:00
parent e7ccca98e7
commit 34fb03b265
11 changed files with 254 additions and 27 deletions

View File

@@ -13,6 +13,7 @@ import type {
import { STAT_LABELS } from '@shared/types'
import { getChallenges, getGamesEnabled } from '../store'
import { fireMatchSummary } from '../notifications'
import { log } from '../logger'
const providers: Record<GameId, GameProvider> = {
dota2: new Dota2Provider()
@@ -25,14 +26,23 @@ async function onMatchEnd(
payload: MatchEndPayload
): Promise<void> {
const provider = providers[gameId]
const challenges = getChallenges().filter(
(c) => c.gameId === gameId && c.enabled
const allChallenges = getChallenges().filter((c) => c.gameId === gameId)
const enabledChallenges = allChallenges.filter((c) => c.enabled)
log.info(
`[games] match_end gameId=${gameId} stats=${JSON.stringify(
payload.stats
)} challenges=${enabledChallenges.length}/${allChallenges.length} (enabled/total)`
)
const results: ChallengeResult[] = []
for (const ch of challenges) {
for (const ch of enabledChallenges) {
const statValue = payload.stats[ch.stat] ?? 0
const reps = Math.round(statValue * ch.multiplier)
if (reps <= 0) continue
if (reps <= 0) {
log.debug(
`[games] skip challenge "${ch.name}": ${ch.stat}=${statValue} × ${ch.multiplier} = ${reps}`
)
continue
}
results.push({
challengeId: ch.id,
name: ch.name,
@@ -44,7 +54,21 @@ async function onMatchEnd(
stat: ch.stat
})
}
if (results.length === 0) return
if (results.length === 0) {
log.warn(
`[games] match_end produced no reps (no enabled challenges matched stats). ` +
`Enabled challenges: ${enabledChallenges.length}, stats keys: ${Object.keys(
payload.stats
).join(',')}`
)
return
}
log.info(
`[games] firing match summary: ${results.length} challenges, total reps ${results.reduce(
(s, r) => s + r.reps,
0
)}`
)
const summary: MatchSummary = {
gameId,
@@ -61,8 +85,9 @@ export async function startGamesRegistry(): Promise<void> {
running = true
try {
await startGsiServer()
log.info('[games] GSI server started on port 4701')
} catch (err) {
console.error('GSI server failed to start:', err)
log.error('[games] GSI server failed to start', err)
return
}
@@ -79,7 +104,7 @@ export async function startGamesRegistry(): Promise<void> {
try {
await provider.reconcile?.()
} catch (err) {
console.error('reconcile failed for', id, err)
log.error(`[games] reconcile failed for ${id}`, err)
}
if (!enabled[id]) continue
await provider.start((e) => {