fix(plugin): safe recording start — no mid-game config rewrite, scoped log clear

This commit is contained in:
2026-07-13 04:45:37 +08:00
parent fd47803127
commit 61154dbda3
5 changed files with 165 additions and 15 deletions
+14 -7
View File
@@ -12,7 +12,8 @@ import { useSettings, useSession, useGameDetection } from "./lib/store"
import {
readAndParseMangohudLog,
clearMangohudLog,
writeMangohudConfig,
deleteLogFile,
findMangohudLog,
startMangohudLogging,
stopMangohudLogging,
getHardwareInfo,
@@ -37,6 +38,7 @@ function Content() {
onGameStart,
onGameStop,
setGameName,
setLastLogPath,
} = useSession()
// ── Game detection via polling ────────────────────────────────
@@ -44,10 +46,13 @@ function Content() {
// ── Handle start recording ────────────────────────────────────
async function handleStart() {
// Write MangoHud config with logging settings
await writeMangohudConfig()
// Clear any previous log file
await clearMangohudLog()
// Clear the previous session's specific log if we know it; else safe-clear.
const prev = session.lastLogPath
if (prev) {
await deleteLogFile(prev)
} else {
await clearMangohudLog()
}
// Fire-and-forget: try to start MangoHud logging (retries until game launches)
startMangohudLogging()
startRecording()
@@ -60,12 +65,14 @@ function Content() {
await stopMangohudLogging()
stopRecording()
// Parse the MangoHud log
const logResult = await readAndParseMangohudLog()
// Find the most recent MangoHud log, parse it, remember its path
const logPath = await findMangohudLog()
const logResult = await readAndParseMangohudLog(logPath.path ?? undefined)
if (logResult.error) {
setError(logResult.error)
return
}
setLastLogPath(logPath.path ?? null)
// Read system info in parallel
const [hwInfo, osVersion] = await Promise.all([
+12
View File
@@ -36,9 +36,21 @@ export const readAndParseMangohudLog = callable<[logPath?: string], {
export const clearMangohudLog = callable<[], {
success: boolean
deleted?: Array<{ name: string }>
skipped?: Array<{ name: string; reason: string }>
error?: string
}>("clear_mangohud_log")
export const deleteLogFile = callable<[path: string], {
success: boolean
deleted?: boolean
error?: string
}>("delete_log_file")
export const findMangohudLog = callable<[], {
path: string | null
}>("find_mangohud_log")
export const startMangohudLogging = callable<[], {
success: boolean
error?: string
+8
View File
@@ -36,6 +36,8 @@ export interface SessionData {
protonVersion: string
versionString: string
buildId: string
// Path of the MangoHud log captured for this session (for targeted cleanup on restart)
lastLogPath: string | null
// Manual inputs (filled by user in the form)
upscalerType: string
upscalerVersion: string
@@ -70,6 +72,7 @@ function createEmptySession(): SessionData {
protonVersion: "",
versionString: "",
buildId: "",
lastLogPath: null,
upscalerType: "none",
upscalerVersion: "",
frameGenMethod: "none",
@@ -182,6 +185,10 @@ export function useSession() {
setSession((prev) => ({ ...prev, gameName: name, appId: appId ?? prev.appId }))
}, [])
const setLastLogPath = useCallback((p: string | null) => {
setSession((prev) => ({ ...prev, lastLogPath: p }))
}, [])
return {
recordingState,
session,
@@ -196,6 +203,7 @@ export function useSession() {
onGameStart,
onGameStop,
setGameName,
setLastLogPath,
}
}