Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions extension/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: MPL-2.0
// (PMPL-1.0-or-later preferred; MPL-2.0 required for browser extension stores)

/// Background service worker — polls boj-server health and updates
/// the extension badge to reflect current server status.

const SERVER_URL = "http://localhost:7700";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Read server URL from storage in background poller

The background worker hardcodes http://localhost:7700, but the popup allows saving a custom serverUrl in chrome.storage.local; after users change the URL, badge polling and poll-now still hit localhost, so the toolbar status can disagree with the popup and report the wrong node health whenever the server is not on the default address.

Useful? React with 👍 / 👎.

const POLL_INTERVAL_MINUTES = 1;

/// Fetch server health and update the badge icon/text.
async function pollHealth() {
try {
const resp = await fetch(`${SERVER_URL}/health`, {
signal: AbortSignal.timeout(3000),
});

if (resp.ok) {
const status = await resp.json();
await chrome.action.setBadgeBackgroundColor({ color: "#4ecca3" });
await chrome.action.setBadgeText({ text: "ON" });
// Store latest status for the popup to read immediately
await chrome.storage.local.set({ lastStatus: status, lastPoll: Date.now() });
} else {
await setOfflineBadge();
}
} catch (_err) {
await setOfflineBadge();
}
}

async function setOfflineBadge() {
await chrome.action.setBadgeBackgroundColor({ color: "#e74c3c" });
await chrome.action.setBadgeText({ text: "OFF" });
await chrome.storage.local.set({
lastStatus: {
healthy: false,
uptime_secs: 0,
cartridges_loaded: 0,
peers_connected: 0,
requests_served: 0,
},
lastPoll: Date.now(),
});
}

// Poll on alarm
chrome.alarms.create("health-poll", { periodInMinutes: POLL_INTERVAL_MINUTES });
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === "health-poll") {
pollHealth();
}
});

// Poll immediately on install/startup
chrome.runtime.onInstalled.addListener(() => pollHealth());
chrome.runtime.onStartup.addListener(() => pollHealth());

// Allow popup to request an immediate refresh
chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
if (msg.type === "poll-now") {
pollHealth().then(() => sendResponse({ ok: true }));
return true; // async response
}
});
Binary file added extension/icons/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/icons/icon-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/icons/icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extension/icons/icon-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"manifest_version": 3,
"name": "BoJ Node Monitor",
"version": "0.1.0",
"description": "Dashboard for monitoring your local Bundle of Joy (BoJ) server instance.",
"author": "Jonathan D.A. Jewell",
"permissions": ["storage", "alarms"],
"host_permissions": [
"http://localhost:7700/*",
"http://[::1]:7700/*"
Comment on lines +9 to +10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Grant host permissions for configurable server URL

The settings UI advertises changing host/port, but host_permissions only allow requests to localhost:7700 and [::1]:7700; in MV3 this blocks fetches to any other configured host or port, so saved non-default server URLs in the popup will fail due to permission denial rather than connectivity.

Useful? React with 👍 / 👎.

],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icons/icon-16.png",
"32": "icons/icon-32.png",
"48": "icons/icon-48.png",
"128": "icons/icon-128.png"
}
},
"icons": {
"16": "icons/icon-16.png",
"32": "icons/icon-32.png",
"48": "icons/icon-48.png",
"128": "icons/icon-128.png"
},
"background": {
"service_worker": "background.js"
}
}
Loading
Loading