-
Notifications
You must be signed in to change notification settings - Fork 1
Add node operator tray app and browser extension #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"; | ||
| 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 | ||
| } | ||
| }); | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The settings UI advertises changing host/port, but 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" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The background worker hardcodes
http://localhost:7700, but the popup allows saving a customserverUrlinchrome.storage.local; after users change the URL, badge polling andpoll-nowstill 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 👍 / 👎.