Files
dawnline/web/src/admin/pkgs.ts
T
Aemeath 70a932b8ea
Build packages / Version (push) Waiting to run
Dawnline 0.3.1
- Find home devices (Bonjour) removed: iOS looks for services over the
  tunnel only under a search domain, and Android and Chromecast only over
  multicast, which WireGuard does not carry. Upgrading removes its server
  option and dnsmasq records
- Home services still show the ports devices announce when umdns runs
2026-10-15 19:01:15 +03:00

52 lines
2.1 KiB
TypeScript

// Installing a missing package from wherever a feature is turned on: runs the
// updater job and follows it with toasts.
import { api, type Needs } from './api';
import { attempt, confirmDialog, notify } from './ui';
const WHAT: Record<keyof Needs, string> = {
https: 'HTTPS for the portal',
acme: 'ACME certificates',
home: 'the home-like link',
};
const WAIT_MS = 5 * 60 * 1000;
/** Install `names` for `feature`; resolves true when the job finished, then calls `done`. */
export async function installMissing(feature: keyof Needs, names: string[], done?: () => void): Promise<boolean> {
if (!names.length) return true;
const ok = await confirmDialog(
`Install ${WHAT[feature]}?`,
`${names.join(', ')} from the OpenWrt feeds. Dawnline sets the rest up when they arrive.`,
'Install',
);
if (!ok) return false;
// The previous job stays in the status until the updater starts: wait for a new one.
const before = (await api.updatesStatus().catch(() => null))?.job?.started ?? 0;
if (!(await attempt(() => api.updatesRun(`pkgs:${names.join(',')}`)))) return false;
notify(`Installing ${names.join(', ')}…`, 'info', 4000);
const until = Date.now() + WAIT_MS;
while (Date.now() < until) {
await new Promise((r) => setTimeout(r, 2000));
const st = await api.updatesStatus().catch(() => null);
const job = st?.job;
if (!job || job.started === before || job.state === 'running') continue;
if (job.state === 'done') {
notify(`${names.join(', ')} installed`, 'success');
// The service restarts to pick them up; give it a moment before reloading.
setTimeout(() => done?.(), 4000);
return true;
}
notify(job.error ?? 'Installation failed', 'error');
return false;
}
notify('Still installing: see Updates for the log.', 'warning');
return false;
}
/** Install what a feature is missing, asking the router what that is now. */
export async function installFeature(feature: keyof Needs, done?: () => void) {
const st = await attempt(() => api.updatesStatus());
if (st) return installMissing(feature, st.needs?.[feature] ?? [], done);
return false;
}