Dawnline 0.8.1
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions

- Fixed: the Overview's map stayed empty after leaving the page and coming
  back (the map freed on leaving was never made again); a map still loading
  when freed no longer draws into a dropped element
- A new connection's city shows within seconds: the agent looks its address
  up the moment the device connects or roams, in a child process so the
  watcher never waits, and open pages refresh once the place is known; the
  connection's entry in the activity log gets its place too. Since 0.7.0 the
  lookup waited for the minute tick and the pages for their 30-second poll
- Device window: each place has a strip of when the device was there (from
  the log's connections) and its share of the time; ▶ replays the period on
  the map: the place it leaves goes gray, a blue shimmer runs along a dotted
  arc to the next one, which lights up. A click or a drag on a strip goes to
  that moment; short visits are folded only past 24 moves. The fixed trail
  line is gone, and place names are no longer cut off at the map's edges
- Overview: the disguise tile's icon is gray when the disguise is Off
- People: "Add device" is a dashed chip with its label; "Send invite" is gone
  from the card (the invite card stays in its ⋯ menu)
This commit is contained in:
Aemeath committed 2026-10-19 00:48:09 +03:00
1 parent 466ca6c7b0
commit 7a6370aa9e
21 files changed
+1241 -193

No files matched your search

+245
View File
@@ -0,0 +1,245 @@
// Where a device went: its stretches on each client address from the activity log
// (connect, roam, disconnect), as visits to the places the map shows, folded into
// stays for the replay, and the replay's timeline and shimmer. No DOM here (see ./render).
import type { GeoPoint, LogEvent } from '../../shared/types';
/** On one client address: from a connect or a roam to the next one, a disconnect or now. */
export interface Stretch {
ip: string;
from: number;
to: number;
live: boolean;
}
/**
* A device's stretches in time order, from the activity log. A stretch the log leaves open
* goes on until now while the device is online, and ends at `seen` (its latest handshake)
* when it is not. Empty when the log has no connections (the category is off or cleared).
*/
export function stretches(events: LogEvent[], device: string, now: number, online: boolean, seen = 0): Stretch[] {
const out: Stretch[] = [];
let cur: Stretch | null = null;
const close = (t: number) => {
if (cur && t > cur.from) out.push({ ...cur, to: t });
cur = null;
};
const mine = events.filter((e) => e.device === device).sort((a, b) => a.ts - b.ts);
for (const e of mine) {
if (e.type === 'connect') {
close(e.ts);
if (e.detail) cur = { ip: e.detail, from: e.ts, to: e.ts, live: false };
} else if (e.type === 'roam') {
// "old → new"
const ip = e.detail?.split('→')[1]?.trim();
close(e.ts);
if (ip) cur = { ip, from: e.ts, to: e.ts, live: false };
} else if (e.type === 'disconnect') close(e.ts);
}
const open = cur as Stretch | null;
if (open && online) out.push({ ...open, to: Math.max(now, open.from), live: true });
else close(Math.min(now, seen));
return out;
}
/** A place as the map groups them: the city (or rounded coordinates where there is none) and the country. */
export function placeKey(p: Pick<GeoPoint, 'city' | 'lat' | 'lon' | 'cc'>): string {
return `${p.city || `${p.lat.toFixed(1)},${p.lon.toFixed(1)}`}|${p.cc}`;
}
/** A stretch at a located address: the place it was at. */
export interface Visit {
key: string;
point: GeoPoint;
from: number;
to: number;
live: boolean;
}
/**
* The stretches since `from` whose address has a location (the device's own point first, then
* anyone's at that address), clipped to `from`. Addresses without one are left out, as on the map.
*/
export function visits(list: Stretch[], points: GeoPoint[], device: string, from: number): Visit[] {
const at = new Map<string, GeoPoint>();
for (const p of points) if (p.device === device || !at.has(p.ip)) at.set(p.ip, p);
const out: Visit[] = [];
for (const s of list) {
const p = at.get(s.ip);
if (!p || s.to <= from) continue;
out.push({ key: placeKey(p), point: p, from: Math.max(s.from, from), to: s.to, live: s.live });
}
return out;
}
/** Each place's share of the time the visits cover (0–1), by place key. */
export function shares(v: Visit[]): Map<string, number> {
const time = new Map<string, number>();
let total = 0;
for (const x of v) {
time.set(x.key, (time.get(x.key) ?? 0) + (x.to - x.from));
total += x.to - x.from;
}
return new Map([...time].map(([k, t]) => [k, total ? t / total : 0]));
}
/** Visits in a row at one place, with `short` visits elsewhere folded in. */
export interface Stay {
key: string;
point: GeoPoint;
from: number;
to: number;
live: boolean;
/** Visits elsewhere shorter than the fold (a phone flipping to mobile data and back), folded into this stay. */
short: number;
}
/** Visits as stays: a place's visits in a row are one, and a visit elsewhere shorter than `fold` seconds joins the stay around it. */
export function stays(v: Visit[], fold = 45 * 60): Stay[] {
const out: Stay[] = [];
for (const x of v) {
const last = out[out.length - 1];
if (last && x.key !== last.key && !x.live && x.to - x.from < fold) {
last.short++;
last.to = x.to;
continue;
}
if (last && last.key === x.key) {
last.to = x.to;
last.live = x.live;
continue;
}
out.push({ key: x.key, point: x.point, from: x.from, to: x.to, live: x.live, short: 0 });
}
return out;
}
/**
* Stays for a replay of at most `max` moves: every move while there are few, folding the
* shortest visits (minutes on mobile data, then longer) only as far as needed.
*/
export function replayStays(v: Visit[], max = 24): Stay[] {
for (const fold of [0, 5 * 60, 15 * 60, 45 * 60, 2 * 3600, 6 * 3600]) {
const st = stays(v, fold);
if (st.length - 1 <= max) return st;
}
return stays(v, 24 * 3600);
}
/* ---------- the replay ---------- */
/** One move (ms): the place it leaves lets go, the shimmer runs along the arc, the next place lights up. */
export const MOVE_MS = 1600;
/** The shimmer sets off once the place it leaves has started to go gray (a share of the move). */
const LEAVE = 0.12;
/** The shimmer's length, a share of the arc: longer than the arc, so most of it is lit mid-move. */
export const BAND = 1.3;
/** ± this around the shimmer's middle is fully lit; it fades out to ±BAND/2. */
export const FLAT = 0.32;
/** A move into stay `k` (from stay k − 1), or stay `k` itself, `ms` long from `start`. */
export interface Step {
kind: 'move' | 'stay';
k: number;
start: number;
ms: number;
}
/** The replay's steps: each stay held in proportion to how long it lasted (within bounds), a move before each but the first. */
export function timeline(st: Stay[], move = MOVE_MS): { steps: Step[]; total: number } {
const steps: Step[] = [];
let t = 0;
st.forEach((s, k) => {
if (k) {
steps.push({ kind: 'move', k, start: t, ms: move });
t += move;
}
const ms = Math.min(1100, Math.max(350, ((s.to - s.from) / 3600) * 45));
steps.push({ kind: 'stay', k, start: t, ms });
t += ms;
});
return { steps, total: t };
}
/** Where the replay is at `ms`: the step (its index), how far into it (0–1) and the moment shown. */
export function moment(st: Stay[], steps: Step[], ms: number): { i: number; step: Step; q: number; t: number } {
let i = steps.findIndex((s) => ms >= s.start && ms < s.start + s.ms);
if (i < 0) i = steps.length - 1;
const step = steps[i];
const q = Math.min(1, Math.max(0, (ms - step.start) / step.ms));
const s = st[step.k];
return { i, step, q, t: step.kind === 'move' ? s.from : s.from + (s.to - s.from) * q };
}
/** The replay's `ms` for moment `t` (a click on a strip): inside the stay it falls in. */
export function msAt(st: Stay[], steps: Step[], t: number): number {
let k = st.findIndex((s) => t >= s.from && t < s.to);
if (k < 0) k = t < (st[0]?.from ?? 0) ? 0 : st.length - 1;
const step = steps.find((s) => s.kind === 'stay' && s.k === k)!;
const s = st[k];
return step.start + step.ms * Math.min(0.999, Math.max(0, (t - s.from) / Math.max(1, s.to - s.from)));
}
export const ease = (x: number) => (x <= 0 ? 0 : x >= 1 ? 1 : x < 0.5 ? 2 * x * x : 1 - (-2 * x + 2) ** 2 / 2);
/** The shimmer's middle (a share of the arc) `q` into a move: it enters before the place it leaves and runs out past the next. */
export function bandMiddle(q: number): number {
return -BAND / 2 + (1 + BAND) * ease((q - LEAVE) / (1 - LEAVE));
}
/** The next place lights up once the shimmer's bright part reaches it. */
export const arrived = (middle: number) => middle + FLAT >= 1;
/**
* The opacity of the arc's dots (each has its `pos` along the arc, 0–1) with the shimmer's middle
* at `c`: beui's text shimmer along a line, the arc itself transparent. A MapLibre expression.
*/
export function shimmerOpacity(c: number): unknown[] {
return ['interpolate', ['linear'], ['abs', ['-', ['get', 'pos'], c]], 0, 1, FLAT, 1, BAND / 2, 0];
}
/* ---------- labels ---------- */
/** Labels under the strips for a range ending `now`: [share of the range, label], in local time. */
export function ticks(range: '24h' | '7d' | '30d', now: number): [number, string][] {
const span = range === '24h' ? 86400 : range === '7d' ? 7 * 86400 : 30 * 86400;
const from = now - span;
const out: [number, string][] = [];
const put = (ts: number, label: string) => {
const f = (ts - from) / span;
if (f > 0.02 && f < 0.98) out.push([f, label]);
};
const d = new Date(from * 1000);
if (range === '24h') {
d.setMinutes(0, 0, 0);
while (d.getTime() / 1000 <= now) {
if (d.getHours() % 6 === 0) put(d.getTime() / 1000, `${String(d.getHours()).padStart(2, '0')}:00`);
d.setHours(d.getHours() + 1);
}
} else if (range === '7d') {
d.setHours(12, 0, 0, 0);
for (; d.getTime() / 1000 <= now; d.setDate(d.getDate() + 1))
put(d.getTime() / 1000, d.toLocaleDateString('en-GB', { weekday: 'short' }));
} else {
const end = new Date(now * 1000);
end.setHours(0, 0, 0, 0);
for (let i = 0; i < 5; i++) {
const w = new Date(end);
w.setDate(end.getDate() - 7 * i);
put(w.getTime() / 1000, w.toLocaleDateString('en-GB', { day: 'numeric', month: 'short' }));
}
out.reverse();
}
return out;
}
/** "14:05", local. */
export const clock = (ts: number) => new Date(ts * 1000).toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' });
/** "Today", "Yesterday" or "Wed 14 Oct" for a moment, against the router's `now`. */
export function dayName(ts: number, now: number): string {
const day = (x: number) => new Date(x * 1000).toDateString();
if (day(ts) === day(now)) return 'Today';
if (day(ts) === day(now - 86400)) return 'Yesterday';
return new Date(ts * 1000).toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short' });
}
+288
View File
@@ -0,0 +1,288 @@
// Where a device went, under its map (the device window): a row per place with a strip of
// when it was there, and a replay of the period: the place it leaves goes gray, a blue
// shimmer runs along the dotted arc to the next place, which lights up. The model is
// ./model; the map draws (ConnectionMap.replay, band, bandAt).
import type { Device, Geo, LogEvent, Person } from '../../shared/types';
import { E } from '../e';
import { icon } from '../../shared/icons';
import { ago } from '../../shared/format';
import { devicePlaces, type ConnectionMap, type MapData, type Range } from '../map';
import {
MOVE_MS,
arrived,
bandMiddle,
clock,
dayName,
moment,
msAt,
placeKey,
shares,
replayStays,
stretches,
ticks,
timeline,
visits,
type Stay,
type Step,
} from './model';
export interface PlacesData {
geo: Geo;
/** The router's clock (seconds). */
now: number;
person: Person;
device: Device;
/** The person's activity log (the device's connects and roams in it); null until loaded. */
events: LogEvent[] | null;
}
const SPAN: Record<Exclude<Range, 'online'>, number> = { '24h': 86400, '7d': 7 * 86400, '30d': 30 * 86400 };
const pct = (part: number, whole: number) => `${((part / whole) * 100).toFixed(3)}%`;
export class PlacesView {
/** The rows under the map. */
readonly el = E('div', { class: 'dl-dplaces' });
/** The replay's controls, for the map's top corner. */
readonly controls = E('div', { class: 'dl-map-replay' });
private data: PlacesData;
/** What came while the replay ran: shown once it ends (the replay plays what it started with). */
private pending: PlacesData | null = null;
private rows = new Map<string, HTMLElement>();
private st: Stay[] = [];
private steps: Step[] = [];
private total = 0;
/** Where the replay is (ms into it) and the step it showed last. */
private ms = 0;
private stepI = -1;
/** In the replay (playing or paused), and playing. */
private on = false;
private playing = false;
private raf = 0;
private last = 0;
private endTimer = 0;
private play = E('button', { type: 'button', class: 'dl-map-btn' });
private chip = E('span', { class: 'dl-map-chip' });
private stop = E('button', { type: 'button', class: 'dl-map-btn', title: 'Back to now', 'aria-label': 'Back to now' }, icon('x'));
private reduced = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
constructor(
private map: ConnectionMap,
private range: Range,
data: PlacesData,
) {
this.data = data;
this.play.addEventListener('click', () => this.toggle());
this.stop.addEventListener('click', () => this.end());
this.paint();
}
mapData(): MapData {
const d = this.data;
return { geo: d.geo, people: [d.person], now: d.now, person: d.person.id, device: d.device.id };
}
/** New status or log: shown at once, or after the replay. */
update(data: Partial<PlacesData>) {
const next = { ...(this.pending ?? this.data), ...data };
if (this.on) {
this.pending = next;
return;
}
this.data = next;
this.map.update(this.mapData());
this.paint();
}
setRange(r: Range) {
this.end();
this.range = r;
this.map.setRange(r);
this.paint();
}
destroy() {
cancelAnimationFrame(this.raf);
clearTimeout(this.endTimer);
}
private paint() {
const d = this.data;
const span = SPAN[this.range as keyof typeof SPAN];
const from = d.now - span;
const v = visits(stretches(d.events ?? [], d.device.id, d.now, d.device.online, d.device.handshake), d.geo.points, d.device.id, from);
const share = shares(v);
this.st = replayStays(v);
const list = devicePlaces(this.mapData(), this.range);
const strips = v.length > 0;
this.el.classList.toggle('strips', strips);
this.el.classList.toggle('can-replay', this.st.length > 1);
this.rows.clear();
dom.content(
this.el,
list.length
? [
...list.map((x) => {
const key = placeKey(x);
const sh = share.get(key);
const strip = strips
? E(
'div',
{ class: `dl-dplace-strip${x.online ? ' live' : ''}` },
v
.filter((y) => y.key === key)
.map((y) => E('i', { style: `left:${pct(y.from - from, span)};width:${pct(y.to - y.from, span)}` })),
)
: '';
const row = E('div', { class: 'dl-dplace-row' }, [
E('span', { class: `dl-dplace-n${x.online ? ' live' : ''}` }, x.online ? icon(d.device.kind) : String(x.n)),
E('span', { class: 'dl-row-main dl-stack' }, [
E('span', {}, [x.city || x.cc || 'Unknown city', x.org ? E('span', { class: 'dl-muted' }, ` · ${x.org}`) : '']),
E('span', { class: 'dl-faint' }, [
E('span', { class: 'dl-mono' }, x.ip),
sh != null ? ` · ${sh > 0 && sh < 0.005 ? '<1' : Math.round(sh * 100)}% of the time` : '',
]),
]),
E('span', { class: x.online ? 'dl-dplace-now' : 'dl-faint dl-nowrap' }, x.online ? 'now' : ago(x.ts, d.now)),
strip,
]);
row.addEventListener('mouseenter', () => this.map.hoverPlace(key));
row.addEventListener('mouseleave', () => this.map.hoverPlace(null));
// The strips are the replay's timeline: a click or a drag on one goes to that moment.
if (strip) {
const seek = (ev: PointerEvent) => {
const r = strip.getBoundingClientRect();
this.seek(from + span * Math.min(1, Math.max(0, (ev.clientX - r.left) / r.width)));
};
strip.addEventListener('pointerdown', (ev) => {
strip.setPointerCapture(ev.pointerId);
seek(ev);
});
strip.addEventListener('pointermove', (ev) => ev.buttons && seek(ev));
}
this.rows.set(key, row);
return row;
}),
strips
? E(
'div',
{ class: 'dl-dplace-axis' },
ticks(this.range as keyof typeof SPAN, d.now).map(([f, label]) =>
E('span', { style: `left:${(f * 100).toFixed(2)}%` }, label),
),
)
: '',
]
: E('div', { class: 'dl-sub' }, 'No locations in this period.'),
);
this.paintControls();
}
private paintControls() {
dom.content(this.play, icon(this.playing ? 'pause' : 'play'));
this.play.title = this.playing ? 'Pause' : 'Replay this period';
this.play.setAttribute('aria-label', this.play.title);
// LuCI's dom.content takes one level of children: no nested arrays.
dom.content(this.controls, this.on ? [this.play, this.chip, this.stop] : this.st.length > 1 ? [this.play] : []);
}
/* ---------- the replay ---------- */
private begin() {
this.on = true;
({ steps: this.steps, total: this.total } = timeline(this.st, this.reduced ? 400 : MOVE_MS));
this.ms = 0;
this.stepI = -1;
// The live place lets go; the first stay lights up on the first frame.
this.map.replay({ active: null, when: '' }, true);
}
private toggle() {
if (this.playing) {
this.playing = false;
cancelAnimationFrame(this.raf);
this.paintControls();
return;
}
clearTimeout(this.endTimer);
if (!this.on || this.ms >= this.total) this.begin();
this.playing = true;
this.last = performance.now();
this.paintControls();
this.raf = requestAnimationFrame((t) => this.frame(t));
}
private frame(now: number) {
if (!this.playing) return;
this.ms = Math.min(this.total, this.ms + (now - this.last));
this.last = now;
this.show(true);
if (this.ms < this.total) {
this.raf = requestAnimationFrame((t) => this.frame(t));
return;
}
// At the end: a moment on the last place, then back to now.
this.playing = false;
this.paintControls();
this.endTimer = window.setTimeout(() => this.end(), 1500);
}
/** Moment `t` (a click on a strip): its place at once, paused there. */
private seek(t: number) {
if (this.st.length < 2) return;
clearTimeout(this.endTimer);
if (!this.on) this.begin();
this.ms = msAt(this.st, this.steps, t);
this.stepI = -1;
this.show(false);
this.paintControls();
}
/** The replay at `this.ms`: the map's light and shimmer, the strips' tick, the chip. */
private show(animate: boolean) {
const m = moment(this.st, this.steps, this.ms);
const s = this.st[m.step.k];
if (m.step.kind === 'move') {
const prev = this.st[m.step.k - 1];
if (m.i !== this.stepI) {
// The place it leaves goes gray; the shimmer sets off from it.
this.map.replay({ active: null, when: '' }, animate);
this.map.band([prev.point.lon, prev.point.lat], [s.point.lon, s.point.lat]);
}
const c = bandMiddle(m.q);
if (!this.reduced) this.map.bandAt(c);
if (this.reduced ? m.q >= 0.5 : arrived(c)) this.map.replay({ active: s.key, when: clock(m.t) }, animate);
} else {
if (m.i !== this.stepI) this.map.band();
this.map.replay({ active: s.key, when: clock(m.t) }, animate);
}
this.stepI = m.i;
const d = this.data;
const from = d.now - SPAN[this.range as keyof typeof SPAN];
this.el.classList.add('replay');
this.el.style.setProperty('--at', pct(m.t - from, d.now - from));
for (const [k, r] of this.rows) r.classList.toggle('cur', k === s.key);
this.chip.textContent = `${dayName(m.t, d.now)}, ${clock(m.t)} · ${s.point.city || s.point.cc || '?'}`;
}
/** Back to now: the map as it is, and whatever came while the replay ran. */
private end() {
cancelAnimationFrame(this.raf);
clearTimeout(this.endTimer);
if (!this.on) return;
this.on = false;
this.playing = false;
this.ms = 0;
this.stepI = -1;
this.map.band();
this.map.replay(null, false);
this.el.classList.remove('replay');
for (const r of this.rows.values()) r.classList.remove('cur');
if (this.pending) {
this.data = this.pending;
this.pending = null;
this.map.update(this.mapData());
this.paint();
} else this.paintControls();
}
}