CI / Build & Test (push) Successful in 2m54s
Add docs/CONTRIBUTING.md covering the build system, dev workflow, all npm scripts, how to add new native host message types, code style, and debugging guidance. Add CHANGELOG.md at the project root documenting all features and fixes across the 1.0.0 release. Add JSDoc (@param, @returns) to all previously undocumented exported functions across 35 JS files: - native-host/holesail-manager/ (index, virtual-hosts, service-tunnels, servers, port-allocator) - native-host top-level managers (startup, connect-proxy, https-proxy, certificate-authority, ssh-manager, rdp-manager) - extension/background/ (logs, native-messaging, proxy, message-router) - extension/dashboard/core/ (utils, navigation, init) - extension/dashboard/ui/ (modal, toast, state-tag) - extension/dashboard/pages/ (all 10 page files) - extension/dashboard/refresh.js, events.js - extension/dashboard/data/hostname-validator.js - scripts/ (build-host, run-install)
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
/**
|
|
* In-memory log buffer (capped at MAX_LOGS entries) and batched broadcast to
|
|
* open dashboard tabs. Provides log() and debugLog() used by all background modules.
|
|
* Depends on: (none — loaded first)
|
|
*/
|
|
|
|
const logs = [];
|
|
const MAX_LOGS = 500;
|
|
|
|
// Track dashboard tabs
|
|
const dashboardTabs = new Set();
|
|
|
|
/**
|
|
* Append a log entry to the in-memory buffer and broadcast to dashboard tabs.
|
|
* Automatically classifies the entry as 'error', 'warn', or 'info' based on keywords.
|
|
* @param {...*} args - Values to log; objects are JSON-stringified.
|
|
*/
|
|
function log(...args) {
|
|
console.log('[Holesail-bg]', ...args);
|
|
const timestamp = Date.now();
|
|
const message = args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' ');
|
|
const lower = message.toLowerCase();
|
|
const level = (lower.includes('error') || lower.includes('fail') || lower.includes('err:'))
|
|
? 'error'
|
|
: (lower.includes('warn') || lower.includes('warning'))
|
|
? 'warn'
|
|
: 'info';
|
|
logs.push({ timestamp, message, level });
|
|
if (logs.length > MAX_LOGS) logs.shift();
|
|
broadcastLogs();
|
|
}
|
|
|
|
/**
|
|
* Log a debug-level entry. No-op unless `DEBUG_VERBOSE` is true.
|
|
* @param {...*} args - Values to log.
|
|
*/
|
|
function debugLog(...args) {
|
|
if (!DEBUG_VERBOSE) return;
|
|
log('[debug]', ...args);
|
|
}
|
|
|
|
let _broadcastPending = false;
|
|
function broadcastLogs() {
|
|
if (_broadcastPending) return;
|
|
_broadcastPending = true;
|
|
// Batch rapid log calls into a single IPC message to avoid sending a full
|
|
// copy of the 500-entry array on every individual log() call.
|
|
setTimeout(() => {
|
|
_broadcastPending = false;
|
|
const snapshot = logs.slice(0);
|
|
for (const tabId of dashboardTabs) {
|
|
browser.tabs.sendMessage(tabId, { type: 'holesail-logs', logs: snapshot }).catch(() => {});
|
|
}
|
|
}, 100);
|
|
}
|