Dawnline 0.4.2
Build packages / Version (push) Waiting to run

- Connections show up at once: the agent looks at the tunnels every
  second and, the moment a device connects or roams, writes it to the
  activity log, updates traffic and the map, and locates the new address
- A device counts as gone when its WireGuard session expires (1-3 min
  after it leaves), so a phone asleep no longer flaps between
  disconnect and connect
- The admin pages follow along within seconds: Overview, People, the
  person page and the device panel refresh when something happens, with
  a light check every 2 s instead of reloading everything every 10 s
- The personal portal no longer refreshes itself in the background:
  every request costs the router a CGI process, so it loads once and
  after the visitor's own changes
- Agent guidance and code standards (backend, frontend, shell, UI) now
  live in the repository: AGENTS.md and rules/
This commit is contained in:
Aemeath committed 2026-10-16 03:52:21 +03:00
1 parent 6444722d14
commit 29b1d7dfd7
26 files changed
+419 -104

No files matched your search

+1
View File
@@ -393,6 +393,7 @@ export interface ServiceLog {
export type Health = { checks: HealthCheck[] } & ServiceLog;
export const api = {
rev: call<{ rev: number }>('rev'),
personUpdate,
settingsGet: call<SettingsData>('settings_get'),
portalInfo: call<PortalInfo>('portal_info'),
+11 -6
View File
@@ -20,6 +20,7 @@ import { eventBy } from './events/model';
import { spark } from './widgets/spark';
import { clearLogDialog, exportEvents, resetUsageDialog } from './logs';
import { coreFor, coreOf, type Core } from './cores';
import { onLiveChange } from './state/live';
/** What the page that opens a device hands over. */
export interface DeviceOpts {
@@ -347,13 +348,17 @@ export async function openDevice(person: Person, dev: Device, o: DeviceOpts) {
setUp ? [stats, connectSec, detailsSec, activitySec] : [stats, detailsSec, activitySec, connectSec],
);
void loadLog();
// Live status every 8 s. The log follows the page's events, or is fetched every 32 s on its own.
let ticks = 0;
const watch = window.setInterval(() => {
// Live status and log: at once when something happens (state/live.ts), and every 30 s anyway.
const live = () => {
void reload();
if (o.events || ++ticks % 4 === 0) void loadLog();
}, 8000);
const handle = drawer(titleEl, body, foot, () => clearInterval(watch));
void loadLog();
};
const off = onLiveChange(live);
const watch = window.setInterval(live, 30000);
const handle = drawer(titleEl, body, foot, () => {
clearInterval(watch);
off();
});
paint();
}
+2 -1
View File
@@ -240,7 +240,8 @@ export class PeoplePage {
// Only while visible (a server section may be swapped out).
this.poller ??= createPoller({
fetch: () => api.status(30),
every: 10,
every: 30,
live: true,
active: () => !!page.el?.isConnected,
apply: (st, quiet) => page.take(st, quiet),
});
+4 -2
View File
@@ -91,12 +91,14 @@ export class PersonPage {
if (dev) setTimeout(() => openDevice(this.p, dev, this.deviceOpts()), 50);
else if (q.get('add')) setTimeout(() => addDevice(this.p, this.deviceOpts()), 50);
this.poller = createPoller({
fetch: () => {
const full = this.fullNext || ++this.ticks % 4 === 0;
// The activity log comes with every fourth tick, and whenever something just happened.
fetch: (live) => {
const full = live || this.fullNext || ++this.ticks % 4 === 0;
this.fullNext = false;
return this.fetch(full);
},
every: 15,
live: true,
active: () => root.isConnected,
apply: (data, quiet) => this.apply(data, quiet),
});
+2 -1
View File
@@ -89,7 +89,8 @@ export class ServerPage {
// and so is anything that has the keyboard focus.
this.poller = createPoller({
fetch: () => api.status(31),
every: 10,
every: 30,
live: true,
active: () => this.section === 'overview' && this.root.isConnected,
apply: (n, quiet) => {
if (!n.servers.length) return;
+31
View File
@@ -0,0 +1,31 @@
// The live revision: one small `rev` call every 2 s while the page is visible.
// The agent moves it the moment a device connects, goes away or roams, or
// something is logged; pollers that opt in refresh then, so pages follow the
// router within seconds without fetching the full status that often.
import { api } from '../api';
const EVERY = 2;
const listeners = new Set<() => void>();
let last: number | null = null;
let started = false;
async function tick(): Promise<void> {
if (document.visibilityState !== 'visible' || !listeners.size) return;
const r = await api.rev().catch(() => null);
if (!r) return;
const moved = last != null && r.rev !== last;
last = r.rev;
if (moved) listeners.forEach((f) => f());
}
/** Call `f` whenever the revision moves; returns the unsubscribe. */
export function onLiveChange(f: () => void): () => void {
listeners.add(f);
if (!started) {
started = true;
poll.add(tick, EVERY);
}
return () => listeners.delete(f);
}
+19 -6
View File
@@ -2,6 +2,8 @@
// region alone while the keyboard focus is inside it (typing, a picker, a
// focused button), so a background refresh never takes it away.
import { onLiveChange } from './live';
/**
* Request tickets: an answer is shown only if nothing newer was shown before
* it. `claim()` invalidates everything in flight (an edit's own answer wins).
@@ -24,14 +26,16 @@ export class Sequence {
}
export interface PollerOptions<T> {
/** One request; rejections and null count as "no answer". */
fetch: () => Promise<T | null>;
/** One request (`live`: the live revision moved); rejections and null count as "no answer". */
fetch: (live: boolean) => Promise<T | null>;
/** Paint an answer; `quiet` for the periodic ones. */
apply: (data: T, quiet: boolean) => void;
/** Seconds between ticks. */
every: number;
/** Ticks are skipped while this is false (e.g. the page is not on screen). */
active?: () => boolean;
/** Also refresh as soon as the live revision moves (state/live.ts); `every` is then the fallback. */
live?: boolean;
}
export interface Poller<T> {
@@ -44,16 +48,25 @@ export interface Poller<T> {
export function createPoller<T>(o: PollerOptions<T>): Poller<T> {
const seq = new Sequence();
const refresh = async (quiet = false): Promise<T | null> => {
const load = async (quiet: boolean, live: boolean): Promise<T | null> => {
const t = seq.next();
const d = await o.fetch().catch(() => null);
const d = await o.fetch(live).catch(() => null);
if (d == null || !seq.take(t)) return null;
o.apply(d, quiet);
return d;
};
const tick = () => ((o.active?.() ?? true) ? refresh(true) : Promise.resolve(null));
const refresh = (quiet = false) => load(quiet, false);
const tick = () => ((o.active?.() ?? true) ? load(true, false) : Promise.resolve(null));
poll.add(tick, o.every);
return { refresh, claim: () => seq.claim(), stop: () => poll.remove(tick) };
const off = o.live ? onLiveChange(() => void ((o.active?.() ?? true) && load(true, true))) : null;
return {
refresh,
claim: () => seq.claim(),
stop: () => {
poll.remove(tick);
off?.();
},
};
}
/** The keyboard focus (or an open native picker's input) is inside `el`. */