|
1 | 1 | import fs from "node:fs/promises"; |
2 | 2 | import { createRequire } from "node:module"; |
| 3 | +import os from "node:os"; |
3 | 4 | import path from "node:path"; |
4 | 5 | import { fileURLToPath } from "node:url"; |
5 | 6 |
|
@@ -1317,4 +1318,45 @@ export function registerIpcHandlers( |
1317 | 1318 | return { success: false, error: String(error) }; |
1318 | 1319 | } |
1319 | 1320 | }); |
| 1321 | + |
| 1322 | + ipcMain.handle( |
| 1323 | + "save-diagnostic", |
| 1324 | + async ( |
| 1325 | + _, |
| 1326 | + payload: { error: string; stack?: string; projectState: unknown; logs: string[] }, |
| 1327 | + ) => { |
| 1328 | + const { filePath, canceled } = await dialog.showSaveDialog({ |
| 1329 | + title: "Save Diagnostic File", |
| 1330 | + defaultPath: `openscreen-diagnostic-${Date.now()}.json`, |
| 1331 | + filters: [{ name: "JSON", extensions: ["json"] }], |
| 1332 | + }); |
| 1333 | + |
| 1334 | + if (canceled || !filePath) return { success: false, canceled: true }; |
| 1335 | + |
| 1336 | + const diagnostic = { |
| 1337 | + timestamp: new Date().toISOString(), |
| 1338 | + appVersion: app.getVersion(), |
| 1339 | + platform: process.platform, |
| 1340 | + arch: process.arch, |
| 1341 | + osRelease: os.release(), |
| 1342 | + osVersion: os.version(), |
| 1343 | + totalMemoryMB: Math.round(os.totalmem() / 1024 / 1024), |
| 1344 | + nodeVersion: process.versions.node, |
| 1345 | + electronVersion: process.versions.electron, |
| 1346 | + chromeVersion: process.versions.chrome, |
| 1347 | + error: payload.error, |
| 1348 | + stack: payload.stack, |
| 1349 | + projectState: payload.projectState, |
| 1350 | + recentLogs: payload.logs, |
| 1351 | + }; |
| 1352 | + |
| 1353 | + try { |
| 1354 | + await fs.writeFile(filePath, JSON.stringify(diagnostic, null, 2), "utf-8"); |
| 1355 | + return { success: true, path: filePath }; |
| 1356 | + } catch (error) { |
| 1357 | + console.error("Failed to write diagnostic file:", error); |
| 1358 | + return { success: false, error: String(error) }; |
| 1359 | + } |
| 1360 | + }, |
| 1361 | + ); |
1320 | 1362 | } |
0 commit comments