mirror of
https://github.com/efiten/coredrive-rx.git
synced 2026-12-03 17:54:09 +00:00
Home becomes a pure monitor and a new Settings tab holds config/diagnostics. - Discover now runs automatically while connected with a 15 s traffic backoff (an overheard 2-byte forwarder/advert means a busy channel — don't poll on top of it); standstill still suspends it. The Flood probe is removed entirely. - New Settings tab: CoreScope broker status + "Push pending now", companion info, diagnostics (verbose, debug log, share/mail the log via Web Share API). - Home enriched: nodes/hex/rx counters, status strip (GPS accuracy, pending, upload health + last-upload age, capture rate), last-reception SNR peak-hold meter, discover status line. - Fix the +60-pending-on-WiFi bug: publish() now times out instead of hanging on a dead socket, drainLoop re-arms in finally so it can never die, MQTT keepalive lowered, and a drain is kicked on broker reconnect / window online. Pure logic in src/monitor.js + src/sharelog.js with tests. SW cache v7→v8. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
2.2 KiB
JavaScript
49 lines
2.2 KiB
JavaScript
// Share/export the debug log. A mobile PWA can't attach a file to a mailto: link,
|
|
// so the primary path is the Web Share API (opens the share sheet → Mail with a real
|
|
// .txt attachment). Falls back to a file download, then a truncated mailto: body.
|
|
//
|
|
// The capability probe is injected so the fallback selection is unit-testable without
|
|
// a DOM/navigator. pickShareMethod is pure; shareLog wires it to the real platform.
|
|
|
|
const MAILTO_BODY_MAX = 1800; // most clients/OS truncate long mailto bodies
|
|
|
|
// pickShareMethod chooses the export path from the available capabilities.
|
|
// caps = { canShareFiles: bool, canDownload: bool }
|
|
// Returns 'share' | 'download' | 'mailto'.
|
|
export function pickShareMethod(caps) {
|
|
if (caps.canShareFiles) return 'share';
|
|
if (caps.canDownload) return 'download';
|
|
return 'mailto';
|
|
}
|
|
|
|
// buildMailto returns a mailto: URL with a (truncated) log body — last-resort path.
|
|
export function buildMailto(text, subject = 'coredrive-rx debug log') {
|
|
const body = text.length > MAILTO_BODY_MAX ? text.slice(0, MAILTO_BODY_MAX) + '\n…(truncated)' : text;
|
|
return 'mailto:?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body);
|
|
}
|
|
|
|
// shareLog exports `text` using the best available method. Browser-only (touches
|
|
// navigator/document); the pure decision lives in pickShareMethod above.
|
|
export async function shareLog(text, filename = 'coredrive-rx-debug.txt') {
|
|
const file = typeof File !== 'undefined' ? new File([text], filename, { type: 'text/plain' }) : null;
|
|
const canShareFiles = !!(file && navigator.canShare && navigator.canShare({ files: [file] }));
|
|
const caps = { canShareFiles, canDownload: typeof document !== 'undefined' };
|
|
const method = pickShareMethod(caps);
|
|
|
|
if (method === 'share') {
|
|
await navigator.share({ files: [file], title: filename, text: 'coredrive-rx debug log' });
|
|
return 'share';
|
|
}
|
|
if (method === 'download') {
|
|
const url = URL.createObjectURL(new Blob([text], { type: 'text/plain' }));
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = filename;
|
|
a.click();
|
|
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
return 'download';
|
|
}
|
|
location.href = buildMailto(text);
|
|
return 'mailto';
|
|
}
|