diff --git a/public/appupdate.js b/public/appupdate.js index b8b89fd..1e22551 100644 --- a/public/appupdate.js +++ b/public/appupdate.js @@ -176,6 +176,35 @@ const getMacAppPath = (app) => { const quoteShellArg = (value) => `'${String(value).replaceAll("'", "'\\''")}'` +const writeInstallerLog = async (app, { installerPath, stdout, stderr, error }) => { + const downloadsDir = app.getPath('downloads') + const timestamp = new Date().toISOString().replaceAll(':', '-').replaceAll('.', '-') + const logPath = path.join( + downloadsDir, + `farmcontrol-update-install-${timestamp}.log` + ) + + const sections = [ + `Timestamp: ${new Date().toISOString()}`, + `Installer: ${installerPath}`, + `Status: ${error ? 'failed' : 'success'}`, + '', + '--- stdout ---', + stdout || '(empty)', + '', + '--- stderr ---', + stderr || '(empty)' + ] + + if (error) { + sections.push('', '--- error ---', error.stack || error.message || String(error)) + } + + await fs.writeFile(logPath, `${sections.join('\n')}\n`, 'utf8') + console.log('[app-update] installer log written to:', logPath) + return logPath +} + const getInstallErrorMessage = (error, output = '') => { const combined = `${output}\n${error?.message || ''}`.trim() @@ -244,6 +273,15 @@ const launchMacInstaller = (app, installerPath, webContents) => { if (stdout) console.log('[app-update] installer stdout:', stdout) if (stderr) console.error('[app-update] installer stderr:', stderr) + void writeInstallerLog(app, { + installerPath, + stdout, + stderr, + error + }).catch((logError) => { + console.error('[app-update] failed to write installer log:', logError) + }) + if (error) { console.error('[app-update] installer error:', error) const message = getInstallErrorMessage(error, output)