-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrash.js
More file actions
94 lines (78 loc) · 2.67 KB
/
Copy pathcrash.js
File metadata and controls
94 lines (78 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
let currentCrashReport = null;
let currentLogPath = "";
function formatCrashTime(value) {
if (!value) {
return "Unknown";
}
const date = new Date(value);
return Number.isNaN(date.getTime()) ? String(value) : date.toLocaleString();
}
function setText(id, value) {
const element = document.getElementById(id);
if (element) {
element.textContent = value || "";
}
}
function formatCrashDetails(report) {
if (!report) {
return "No crash details were provided.";
}
const parts = [
`${report.name || "Error"}: ${report.message || "Unknown error"}`,
report.stack || "",
report.details ? JSON.stringify(report.details, null, 2) : ""
].filter(Boolean);
return parts.join("\n\n");
}
function renderCrashReport(payload) {
currentCrashReport = payload?.report || null;
currentLogPath = payload?.logPath || currentCrashReport?.logPath || "";
setText("crashId", currentCrashReport?.id || "Unavailable");
setText("crashTime", formatCrashTime(currentCrashReport?.timestamp));
setText("crashLogPath", currentLogPath || "Crash log path unavailable");
setText("crashMessage", currentCrashReport?.message || "freqx stopped unexpectedly.");
setText("crashStack", formatCrashDetails(currentCrashReport));
}
async function loadCrashReport() {
if (!window.soundmuncher?.getCrashReport) {
renderCrashReport(null);
return;
}
try {
renderCrashReport(await window.soundmuncher.getCrashReport());
} catch (error) {
renderCrashReport({
report: {
message: error?.message || "Could not load crash details.",
stack: error?.stack || ""
}
});
}
}
function bindCrashActions() {
document.getElementById("reloadAfterCrash")?.addEventListener("click", () => {
window.soundmuncher?.reloadAfterCrash?.();
});
document.getElementById("openCrashLog")?.addEventListener("click", () => {
window.soundmuncher?.openCrashLog?.();
});
document.getElementById("quitAfterCrash")?.addEventListener("click", () => {
window.soundmuncher?.quitAfterCrash?.();
});
document.getElementById("copyCrashDetails")?.addEventListener("click", async () => {
const text = [
`Crash ID: ${currentCrashReport?.id || "Unavailable"}`,
`Time: ${currentCrashReport?.timestamp || "Unavailable"}`,
`Log: ${currentLogPath || "Unavailable"}`,
formatCrashDetails(currentCrashReport)
].join("\n\n");
try {
await navigator.clipboard.writeText(text);
setText("crashLogPath", currentLogPath ? `${currentLogPath} (details copied)` : "Details copied");
} catch (error) {
setText("crashLogPath", currentLogPath || "Could not copy crash details");
}
});
}
bindCrashActions();
loadCrashReport();