feat: add diagnostics report to Firefox torrent extension
check / check (macos-latest) (push) Failing after 26s
check / check (windows-latest) (push) Failing after 26s
check / check (ubuntu-latest) (push) Failing after 29s

- Add a Diagnostics panel to the extension popup and manager page with copy and refresh actions
- Collect extension settings, router API status, torrents, DHT nodes, and a tail of the router log into one report
- Add a native host `diagnostics` command that reports router PID, active ports, log path, and log summary counters
- Export data dir, log file, router PID, and SAM port from the AppImage launcher
- Start the router with `--debug` so the log tail has detailed output
- Bump extension version to 0.1.4 and request clipboardWrite permission
This commit is contained in:
nandi committed 2026-11-28 19:28:39 -08:00
1 parent 9aa15f9ae8
commit 4bb81f1b80
9 files changed
+486 -1

No files matched your search

+145
View File
@@ -55,6 +55,96 @@ const dirtyFields = new Set();
let refreshInFlight = false;
let refreshPending = false;
let initialSettingsPromise = null;
let latestDiagnosticsReport = "";
let diagInFlight = false;
let diagPromise = null;
let copyBtnTimer = null;
function setDiagMsg(text, isErr = false) {
const el = $("diag-status");
if (!el) return;
el.textContent = text;
el.className = isErr ? "msg err" : "msg";
}
async function copyTextToClipboard(text) {
if (navigator.clipboard && navigator.clipboard.writeText) {
try {
await navigator.clipboard.writeText(text);
return true;
} catch (_e) {
// Fall through to textarea + execCommand fallback
}
}
const ta = document.createElement("textarea");
ta.value = text;
ta.setAttribute("readonly", "");
ta.style.position = "fixed";
ta.style.top = "-9999px";
ta.style.left = "-9999px";
document.body.appendChild(ta);
ta.select();
let ok = false;
try {
ok = document.execCommand("copy");
} finally {
document.body.removeChild(ta);
}
return ok;
}
async function loadDiagnostics(showStatus = false) {
const logEl = $("diagnostics-log");
if (!logEl) return latestDiagnosticsReport;
if (diagInFlight && diagPromise) {
return diagPromise;
}
diagInFlight = true;
if (showStatus) {
setDiagMsg("Collecting diagnostics...");
}
diagPromise = (async () => {
try {
const res = await browser.runtime.sendMessage({ type: "getDiagnostics" });
if (res && res.ok && res.report) {
latestDiagnosticsReport = res.report;
logEl.textContent = res.report;
if (showStatus) {
const meta = res.meta || {};
if (!meta.nativeAvailable) {
setDiagMsg(
`Diagnostics refreshed (native host unavailable: ${meta.nativeError || "log tail skipped"}).`,
true
);
} else if (meta.logPath) {
setDiagMsg(`Diagnostics refreshed (${meta.logPath}).`);
} else {
setDiagMsg("Diagnostics refreshed.");
}
} else {
setDiagMsg("");
}
return res.report;
}
const errMsg = (res && res.error) || "failed to collect diagnostics";
if (!latestDiagnosticsReport) {
logEl.textContent = `Error loading diagnostics: ${errMsg}`;
}
setDiagMsg(`Diagnostics failed: ${errMsg}`, true);
return latestDiagnosticsReport;
} catch (err) {
if (!latestDiagnosticsReport) {
logEl.textContent = `Error loading diagnostics: ${err}`;
}
setDiagMsg(`Diagnostics failed: ${err}`, true);
return latestDiagnosticsReport;
} finally {
diagInFlight = false;
diagPromise = null;
}
})();
return diagPromise;
}
function parsePort(raw, fallback) {
const s = String(raw ?? "").trim();
@@ -364,7 +454,62 @@ document.addEventListener("DOMContentLoaded", () => {
}
});
const headerDiagBtn = $("header-diag-btn");
if (headerDiagBtn) {
headerDiagBtn.addEventListener("click", () => {
const card = $("diagnostics-card");
if (card) {
card.scrollIntoView({ behavior: "smooth", block: "start" });
}
loadDiagnostics(true);
});
}
const refreshDiagBtn = $("refresh-diag-btn");
if (refreshDiagBtn) {
refreshDiagBtn.addEventListener("click", () => loadDiagnostics(true));
}
const copyDiagBtn = $("copy-diag-btn");
if (copyDiagBtn) {
copyDiagBtn.addEventListener("click", async () => {
const report = (await loadDiagnostics(false)) || latestDiagnosticsReport;
if (!report) {
setDiagMsg("No diagnostics available to copy.", true);
return;
}
try {
const copied = await copyTextToClipboard(report);
if (copied) {
setDiagMsg("Copied diagnostics report to clipboard.");
copyDiagBtn.textContent = "Copied!";
if (copyBtnTimer) clearTimeout(copyBtnTimer);
copyBtnTimer = setTimeout(() => {
copyDiagBtn.textContent = "Copy Diagnostics";
copyBtnTimer = null;
}, 1500);
} else {
setDiagMsg("Clipboard copy blocked by browser; select text below to copy.", true);
}
} catch (err) {
setDiagMsg(`Clipboard copy failed: ${err}`, true);
}
});
}
const diagDetails = $("diagnostics-details");
if (diagDetails) {
diagDetails.addEventListener("toggle", () => {
if (diagDetails.open) {
loadDiagnostics(false);
}
});
}
initialSettingsPromise = loadSettingsFast();
refresh(false);
if (document.body && document.body.classList.contains("manager")) {
loadDiagnostics(false);
}
setInterval(() => refresh(false), 2000);
});