mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
feat: add PTP UI and switch to default styling for Hachi-TimeTransformer
Co-authored-by: aider (openai/gpt-5) <aider@aider.chat>
This commit is contained in:
parent
8eb4c6f2da
commit
646e927e46
2 changed files with 113 additions and 3 deletions
83
static/ptp.js
Normal file
83
static/ptp.js
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
(function () {
|
||||
function $(id) { return document.getElementById(id); }
|
||||
function setText(id, val) {
|
||||
var el = $(id);
|
||||
if (el) el.textContent = val;
|
||||
}
|
||||
|
||||
async function fetchPtpStatus() {
|
||||
try {
|
||||
const res = await fetch('/api/status');
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
|
||||
const supported = data.ptp_supported;
|
||||
const iface = data.ptp_interface;
|
||||
const running = data.ptp_daemon_running;
|
||||
const offset = data.ptp_offset_ns;
|
||||
|
||||
if (typeof supported !== 'undefined') setText('ptp-supported', supported ? 'Yes' : 'No');
|
||||
if (typeof iface !== 'undefined' && iface !== null) setText('ptp-interface', iface);
|
||||
if (typeof running !== 'undefined') setText('ptp-daemon', running ? 'Running' : 'Stopped');
|
||||
if (typeof offset !== 'undefined' && offset !== null) setText('ptp-offset', String(offset));
|
||||
} catch (_) {
|
||||
// ignore fetch errors; UI will show last known values
|
||||
}
|
||||
}
|
||||
|
||||
async function startPtp() {
|
||||
const ifaceVal = $('ptp-interface-input')?.value.trim();
|
||||
const phcIdxStr = $('ptp-phc-index')?.value;
|
||||
const extraArgsStr = $('ptp-extra-args')?.value.trim();
|
||||
|
||||
const body = {};
|
||||
if (ifaceVal) body.interface = ifaceVal;
|
||||
if (phcIdxStr !== '' && phcIdxStr != null) {
|
||||
const n = Number(phcIdxStr);
|
||||
if (!Number.isNaN(n)) body.phcIndex = n;
|
||||
}
|
||||
if (extraArgsStr) {
|
||||
body.args = extraArgsStr.split(/\s+/).filter(Boolean);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/ptp/start', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const j = await res.json().catch(() => ({}));
|
||||
setText('ptp-message', j.message || (res.ok ? 'PTP start requested' : 'Failed to start PTP'));
|
||||
} catch (_) {
|
||||
setText('ptp-message', 'Failed to start PTP');
|
||||
}
|
||||
fetchPtpStatus();
|
||||
}
|
||||
|
||||
async function stopPtp() {
|
||||
try {
|
||||
const res = await fetch('/api/ptp/stop', { method: 'POST' });
|
||||
const j = await res.json().catch(() => ({}));
|
||||
setText('ptp-message', j.message || (res.ok ? 'PTP stop requested' : 'Failed to stop PTP'));
|
||||
} catch (_) {
|
||||
setText('ptp-message', 'Failed to stop PTP');
|
||||
}
|
||||
fetchPtpStatus();
|
||||
}
|
||||
|
||||
function init() {
|
||||
const startBtn = $('start-ptp');
|
||||
const stopBtn = $('stop-ptp');
|
||||
if (startBtn) startBtn.addEventListener('click', startPtp);
|
||||
if (stopBtn) stopBtn.addEventListener('click', stopPtp);
|
||||
|
||||
fetchPtpStatus();
|
||||
setInterval(fetchPtpStatus, 2000);
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue