Compare commits

1 Commits
Author SHA1 Message Date
Aemeath 0fd22b917a Dawnline 0.16.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
- Checking one component for updates in Components no longer fails
  with "XHR request timed out": the check starts at once instead of
  keeping the page waiting twenty seconds
- On a router without curl, updates and the installer download release
  files through GitHub's API: GitHub's own download links can make
  OpenWrt's built-in downloader hang
- Adding a device in the admin offers the same four types as the
  personal page: PC, Mobile, Router and Other (phones and tablets are
  one choice)
2026-10-26 06:41:54 +03:00
20 changed files with 179 additions and 73 deletions

No files matched your search

+30 -12
View File
@@ -487,18 +487,19 @@ check_tools() {
# ---------- downloads ----------
# fetch_once URL FILE [SECONDS]
# fetch_once URL FILE [SECONDS] [ACCEPT]
fetch_once() {
_fu="$1"
_fd="$2"
_ft="${3:-$DOWNLOAD_TIMEOUT}"
_fa="${4:-}"
rm -f "$_fd"
case "$FETCHER" in
curl)
run_logged download curl -fsSL --connect-timeout "$CONNECT_TIMEOUT" --max-time "$_ft" \
--speed-limit 1024 --speed-time 30 -o "$_fd" "$_fu"
--speed-limit 1024 --speed-time 30 ${_fa:+-H "Accept: $_fa"} -o "$_fd" "$_fu"
;;
*) run_logged download "$FETCHER" -q -T "$CONNECT_TIMEOUT" -O "$_fd" "$_fu" ;;
*) run_logged download "$FETCHER" -q -T "$CONNECT_TIMEOUT" ${_fa:+--header="Accept: $_fa"} -O "$_fd" "$_fu" ;;
esac
_frc=$?
[ "$_frc" -eq 0 ] && [ -s "$_fd" ] && return 0
@@ -531,16 +532,29 @@ asset_digest() {
jsonfilter -i "$1" -e "@.assets[@.name='$2'].digest" 2>/dev/null | head -n 1 | sed -n 's/^sha256:\([0-9a-f]\{64\}\)$/\1/p'
}
# download URL FILE LABEL [SHA256]: direct, then (only when the sha256 is
# known) two mirrors, then direct again. A file whose sha256 doesn't match is
# thrown away and the next source is tried; without a sha256 only GitHub
# itself is used.
# A release file's URL in the GitHub API, from release JSON (empty if unknown).
# Asked for application/octet-stream, it answers with the file itself.
asset_api_url() {
[ -s "$1" ] || return 0
jsonfilter -i "$1" -e "@.assets[@.name='$2'].url" 2>/dev/null | head -n 1 |
sed -n 's#^\(https://api\.github\.com/repos/[^/]*/[^/]*/releases/assets/[0-9][0-9]*\)$#\1#p'
}
# download URL FILE LABEL [SHA256] [API_URL]: without curl the API's URL
# first (github.com's redirect carries a Content-Security-Policy header that
# can outgrow uclient-fetch's 4 KB line buffer, and it stalls there), then
# direct, then (only when the sha256 is known) two mirrors, then direct again.
# A file whose sha256 doesn't match is thrown away and the next source is
# tried; without a sha256 only GitHub itself is used.
download() {
_du="$1"
_dd="$2"
_dl="$3"
_dw="${4:-}"
_da="${5:-}"
[ "$FETCHER" != curl ] || _da=""
set -- "$_du"
[ -z "$_da" ] || set -- "$_da" "$_du"
if [ -n "$_dw" ]; then
for _m in $MIRRORS; do set -- "$@" "$_m$_du"; done
fi
@@ -555,7 +569,9 @@ download() {
sleep 2
msg "Downloading $_dl via $(host_of "$_try") (attempt $_n/$_total)"
fi
if fetch_once "$_try" "$_dd"; then
_acc=""
[ "$_try" != "$_da" ] || _acc="application/octet-stream"
if fetch_once "$_try" "$_dd" "" "$_acc"; then
if [ -n "$_dw" ] && [ "$(sha256sum "$_dd" 2>/dev/null | awk '{ print $1 }')" != "$_dw" ]; then
warn "$(host_of "$_try") sent a file that doesn't match GitHub's sha256: discarded"
rm -f "$_dd"
@@ -1118,10 +1134,11 @@ confirm() {
download_release_file() {
_name="$1"
_sums="$TMP_DIR/sha256sums.txt"
# The checksum: GitHub's own (API), else the release's sha256sums.txt straight from github.com.
# The checksum: GitHub's own (API), else the release's sha256sums.txt straight from GitHub.
_want="$(asset_digest "$TMP_DIR/release.json" "$_name")"
if [ -z "$_want" ]; then
[ -s "$_sums" ] || download "$ASSET_BASE/sha256sums.txt" "$_sums" sha256sums.txt || {
[ -s "$_sums" ] || download "$ASSET_BASE/sha256sums.txt" "$_sums" sha256sums.txt "" \
"$(asset_api_url "$TMP_DIR/release.json" sha256sums.txt)" || {
err "Download failed: sha256sums.txt (does release $VERSION exist?)"
return 1
}
@@ -1131,7 +1148,7 @@ download_release_file() {
return 1
}
fi
download "$ASSET_BASE/$_name" "$TMP_DIR/$_name" "$_name" "$_want" || {
download "$ASSET_BASE/$_name" "$TMP_DIR/$_name" "$_name" "$_want" "$(asset_api_url "$TMP_DIR/release.json" "$_name")" || {
err "Download failed: $_name"
return 1
}
@@ -1158,7 +1175,8 @@ download_awg() {
_f="$TMP_DIR/$_p$_pf"
# Verified when GitHub publishes the file's sha256 (then mirrors may serve it).
_want="$(asset_digest "$TMP_DIR/awg-$_s.json" "$_p$_pf")"
if download "https://github.com/$_repo/releases/download/v$OWRT_RELEASE/$_p$_pf" "$_f" "$_p ($_repo)" "$_want" &&
if download "https://github.com/$_repo/releases/download/v$OWRT_RELEASE/$_p$_pf" "$_f" "$_p ($_repo)" "$_want" \
"$(asset_api_url "$TMP_DIR/awg-$_s.json" "$_p$_pf")" &&
verify_archive "$_f"; then
_files="$_files $_f"
else
+1 -1
View File
@@ -6,7 +6,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-dawnline
PKG_VERSION:=0.16.0
PKG_VERSION:=0.16.1
PKG_RELEASE:=1
PKG_LICENSE:=MIT
# po/<lang>/dawnline.po becomes luci-i18n-dawnline-<lang> (luci.mk), released
@@ -4099,6 +4099,10 @@ msgstr "Метод не поддерживается."
msgid "Missing: %s."
msgstr "Не хватает: %s."
#: web/src/shared/format.ts
msgid "Mobile"
msgstr "Мобильный"
#: web/src/admin/pages/person/limits.ts
msgid "Monthly"
msgstr "В месяц"
@@ -4043,6 +4043,10 @@ msgstr ""
msgid "Missing: %s."
msgstr ""
#: web/src/shared/format.ts
msgid "Mobile"
msgstr ""
#: web/src/admin/pages/person/limits.ts
msgid "Monthly"
msgstr ""
@@ -360,7 +360,7 @@ let LOCK = null;
for (let i = 0; i < 10 && !LOCK; i++) {
LOCK = upd.try_lock();
if (!LOCK)
system('usleep 100000 2>/dev/null || sleep 1');
sleep(100);
}
if (!LOCK)
exit(0);
@@ -79,14 +79,17 @@ function cached(key, ttl, fn) {
/* ---------- releases ---------- */
function slim(x) {
let digests = {};
for (let a in x.assets ?? [])
let digests = {}, ids = {};
for (let a in x.assets ?? []) {
if (match(a.digest ?? '', /^sha256:[0-9a-f]{64}$/))
digests[a.name] = substr(a.digest, 7);
if (type(a.id) == 'int' && a.id > 0)
ids[a.name] = a.id;
}
return {
tag: x.tag_name, name: x.name ?? x.tag_name, published: x.published_at ?? null,
prerelease: !!x.prerelease, url: x.html_url ?? null, body: substr(x.body ?? '', 0, 12000),
assets: map(x.assets ?? [], (a) => a.name), digests,
assets: map(x.assets ?? [], (a) => a.name), digests, ids,
};
}
@@ -194,6 +197,25 @@ export function sha256(path) {
return match(run(`sha256sum ${q(path)}`).out, /^([0-9a-f]{64})/)?.[1];
};
/** A release file's URL on github.com in parts: { repo, tag, name }, or null for any other URL. */
export function release_file(url) {
let m = match(url ?? '', /^https:\/\/github\.com\/([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)\/releases\/download\/([^\/?#]+)\/([^\/?#]+)$/);
return m ? { repo: m[1], tag: m[2], name: m[3] } : null;
};
/** The same file through the API (api.github.com), when its release is known; else null. */
function asset_api_url(url) {
let f = release_file(url);
if (!f)
return null;
let id = null;
try {
id = release(f.repo, f.tag)?.ids?.[f.name];
}
catch (e) {}
return id ? `https://api.github.com/repos/${f.repo}/releases/assets/${id}` : null;
}
/**
* Download to a file. o: { sha256, mirrors, log }. Direct first; mirrors
* only when the sha256 is known (from the API) and mirrors are allowed. A
@@ -203,24 +225,32 @@ export function sha256(path) {
export function download(url, dest, o) {
o ??= {};
let want = o.sha256 ? lc(o.sha256) : null;
let tries = [ url ];
let curl = have_curl();
let tries = [];
// Without curl a release file comes through the API first: github.com's redirect to it carries a
// Content-Security-Policy header that can outgrow uclient-fetch's 4 KB line buffer, and it stalls there.
let api = curl ? null : asset_api_url(url);
if (api)
push(tries, { u: api, accept: 'application/octet-stream' });
push(tries, { u: url });
let direct = length(tries);
if (want && o.mirrors && match(url, /^https:\/\/(github\.com|raw\.githubusercontent\.com)\//))
for (let m in MIRRORS)
push(tries, m + url);
for (let i, u in tries) {
let host = replace(u, /^https:\/\/([^\/]+)\/.*$/, '$1');
if (i > 0)
push(tries, { u: m + url, mirror: true });
for (let i, t in tries) {
let host = replace(t.u, /^https:\/\/([^\/]+)\/.*$/, '$1');
if (t.mirror)
o.log?.(sprintf(_('Trying mirror %s'), host));
let r = have_curl()
? run(`curl -fsSL --connect-timeout 15 --max-time 300 --retry 1 -o ${q(dest)} ${q(u)}`)
: run(`uclient-fetch -q -T 30 -O ${q(dest)} ${q(u)}`);
let r = curl
? run(`curl -fsSL --connect-timeout 15 --max-time 300 --retry 1 -o ${q(dest)} ${q(t.u)}`)
: run(`uclient-fetch -q -T 30 ${t.accept ? `--header=${q('Accept: ' + t.accept)} ` : ''}-O ${q(dest)} ${q(t.u)}`);
if (r.code == 0 && (stat(dest)?.size ?? 0) > 0) {
if (!want || sha256(dest) == want)
return u;
return t.u;
o.log?.(sprintf(_("Warning: %s sent a file that does not match GitHub's sha256, discarded"), host));
}
system(`rm -f ${q(dest)}`);
if (i == 0 && length(tries) > 1)
if (i == direct - 1 && length(tries) > direct)
o.log?.(_('GitHub did not answer, trying mirrors'));
}
return null;
@@ -80,7 +80,7 @@ function releases(a) {
let page = +(a.page ?? 1);
if (page != int(page) || page < 1 || page > 50)
die(_('Unknown page.'));
return { releases: map(gh.releases(REPO, page), (x) => ({ ...x, body: null, digests: null })), page };
return { releases: map(gh.releases(REPO, page), (x) => ({ ...x, body: null, digests: null, ids: null })), page };
}
/** Release notes for What's new: Dawnline by tag, or an AmneziaWG build's release. */
@@ -94,7 +94,7 @@ function notes(a) {
r = gh.release(rp, `v${tag}`);
if (!r)
die(sprintf(_('No release %s in %s.'), tag, rp));
return { ...r, digests: null, repo: rp };
return { ...r, digests: null, ids: null, repo: rp };
}
/** What changed between the installed Dawnline and a release (points for the Components tab). */
@@ -111,8 +111,10 @@ function changes(a) {
}
/**
* Start an update job. Returns the new job once its worker has written it,
* else null (the caller follows updates_status); never an older job.
* Start an update job. Returns the new job once its worker has written it
* (a quick check may be over by then), else null (the caller follows
* updates_status); never an older job. Waits two seconds at most: LuCI gives
* up on a call after twenty.
*/
function run(a) {
let what = a.what ?? 'check';
@@ -126,16 +128,17 @@ function run(a) {
if (upd.busy())
die(_('Another component action is already running'));
ensure_dir(RUN_DIR);
let t0 = time();
let t0 = time(), prev = read_json(upd.JOB_FILE, null)?.id;
let args = substr(what, 0, 5) == 'check' ? `check ${substr(what, 6)}` : `install ${what}`;
// The job speaks the admin's language (use() let only a plain language code through).
let lang = i18n.current();
system(`${lang ? `DAWNLINE_LANG=${lang} ` : ''}start-stop-daemon -S -b -x /usr/libexec/dawnline/updater -- ${args}`);
for (let i = 0; i < 20; i++) {
let j = read_json(upd.JOB_FILE, null);
if (j?.state == 'running' && j.started >= t0)
if (j && j.id != prev && j.started >= t0)
return { started: true, job: j };
system('usleep 100000 2>/dev/null || sleep 1');
// ucode's own sleep: OpenWrt's BusyBox has no usleep.
sleep(100);
}
return { started: true, job: null };
}
@@ -30,7 +30,7 @@ export function check(ctx) {
/**
* The sha256 a release publishes for a file: GitHub's own (API), else the
* release's sha256sums.txt fetched straight from github.com (never a mirror).
* release's sha256sums.txt fetched straight from GitHub (never a mirror).
*/
function want_sha(ctx, tag, asset, dir) {
let want = gh.asset_sha256(REPO, tag, asset);
@@ -5,7 +5,7 @@
import { open, readfile, writefile, rename, mkdir, stat, unlink, popen, lsdir } from 'fs';
import { _ } from 'dawnline.i18n';
export const VERSION = '0.16.0';
export const VERSION = '0.16.1';
/** GitHub repository with Dawnline releases (updates and the installer). */
export const REPO = 'tickcount/luci-app-dawnline';
export const RUN_DIR = '/var/run/dawnline';
+25
View File
@@ -0,0 +1,25 @@
// dawnline.github: which URLs are a release's files (those can come through
// the API instead of github.com's redirect) and the points of a commit message.
import * as gh from 'dawnline.github';
test('release_file', () => {
eq(gh.release_file('https://github.com/tickcount/luci-app-dawnline/releases/download/v0.16.0/sha256sums.txt'),
{ repo: 'tickcount/luci-app-dawnline', tag: 'v0.16.0', name: 'sha256sums.txt' }, 'a Dawnline release file');
eq(gh.release_file('https://github.com/Slava-Shchipunov/awg-openwrt/releases/download/v24.10.4/kmod-amneziawg_v24.10.4_aarch64_cortex-a53_mediatek_filogic.ipk'),
{ repo: 'Slava-Shchipunov/awg-openwrt', tag: 'v24.10.4', name: 'kmod-amneziawg_v24.10.4_aarch64_cortex-a53_mediatek_filogic.ipk' },
'an AmneziaWG build');
eq(gh.release_file('https://ghfast.top/https://github.com/tickcount/luci-app-dawnline/releases/download/v0.16.0/a.ipk'), null, 'a mirror');
eq(gh.release_file('https://raw.githubusercontent.com/tickcount/luci-app-dawnline/main/install.sh'), null, 'not a release file');
eq(gh.release_file('https://github.com/tickcount/luci-app-dawnline/releases/latest'), null, 'the latest redirect');
eq(gh.release_file('https://github.com/a/b/releases/download/v1/x.ipk?raw=1'), null, 'a query');
eq(gh.release_file('https://github.com/a/b/releases/download/v1/sub/x.ipk'), null, 'a deeper path');
eq(gh.release_file(null), null, 'nothing');
});
test('points', () => {
eq(gh.points('Dawnline 0.16.0\n\n- Check no longer times out\n- Downloads without curl\n go through the API'),
[ 'Check no longer times out', 'Downloads without curl go through the API' ], 'a release commit, a wrapped point');
eq(gh.points('Fix the portal'), [ 'Fix the portal' ], 'another commit: its title');
eq(gh.points('Dawnline 0.16.0'), [], 'a bare release title');
eq(gh.points('Merge branch x\n\n- y'), [], 'a merge');
});
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "dawnline-web",
"version": "0.16.0",
"version": "0.16.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "dawnline-web",
"version": "0.16.0",
"version": "0.16.1",
"license": "MIT",
"dependencies": {
"qrcode-generator": "2.0.4"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dawnline-web",
"version": "0.16.0",
"version": "0.16.1",
"private": true,
"license": "MIT",
"type": "module",
+27 -12
View File
@@ -17,7 +17,20 @@ import { isOn, sw } from './ui/controls';
import { qrCode } from './ui/qr';
import { deviceNameHelp, type Help } from './netcheck';
import { deviceStatus } from './ui/badges';
import { ago, bytes, defaultName, fitName, homeOf, isoDay, kindLabel, KINDS, netsLabel, todayOf } from '../shared/format';
import {
ago,
bytes,
defaultName,
fitName,
homeOf,
isoDay,
kindLabel,
netsLabel,
pickLabel,
PICKS,
todayOf,
type KindPick,
} from '../shared/format';
import { guardDeviceName } from '../shared/name-guard';
import { fill, fmt, locale, num } from '../shared/i18n';
import { icon } from '../shared/icons';
@@ -610,44 +623,46 @@ export function addDevice(person: Person, o: DeviceOpts) {
while (taken.some((t) => t.toLowerCase() === name.toLowerCase())) name = fitName(base, ` ${++n}`);
return name;
};
let kind: Kind = 'phone';
// Mobile from here is a phone: the admin is never on the device itself (see KindPick).
const kindOf = (p: KindPick): Kind => (p === 'mobile' ? 'phone' : p);
let pick: KindPick = 'mobile';
const nameInput = E('input', {
type: 'text',
class: 'cbi-input-text',
placeholder: suggest(kind),
placeholder: suggest(kindOf(pick)),
}) as HTMLInputElement;
const said = nameGuard(nameInput, () => nameRow.refresh());
const nameRow = liveField(_('Name'), nameInput, () =>
said(
nameInput.value.trim()
? deviceNameHelp(nameInput.value, taken, _('Shown in the portal and in the app.'))
: { text: fmt(_('Named after its type: %s.'), suggest(kind)), bad: false },
: { text: fmt(_('Named after its type: %s.'), suggest(kindOf(pick))), bad: false },
),
);
const kinds = E(
'div',
{ class: 'dl-kinds', role: 'radiogroup', 'aria-label': _('Type') },
KINDS.map((k) =>
PICKS.map((k) =>
E(
'button',
{
type: 'button',
role: 'radio',
class: k === kind ? 'on' : '',
'aria-checked': k === kind ? 'true' : 'false',
class: k === pick ? 'on' : '',
'aria-checked': k === pick ? 'true' : 'false',
'data-kind': k,
click: () => {
kind = k;
pick = k;
kinds.querySelectorAll('button').forEach((c) => {
const on = (c as HTMLElement).dataset.kind === k;
c.classList.toggle('on', on);
c.setAttribute('aria-checked', on ? 'true' : 'false');
});
nameInput.placeholder = suggest(k);
nameInput.placeholder = suggest(kindOf(k));
nameRow.refresh();
},
},
[icon(k), E('span', {}, kindLabel(k))],
[icon(k), E('span', {}, pickLabel(k))],
),
),
);
@@ -704,8 +719,8 @@ export function addDevice(person: Person, o: DeviceOpts) {
notify(h.text, 'warning');
return;
}
const name = nameInput.value.trim() || suggest(kind);
const r = await attempt(() => api.deviceCreate(person.id, name, kind, isOn(bypass)));
const name = nameInput.value.trim() || suggest(kindOf(pick));
const r = await attempt(() => api.deviceCreate(person.id, name, kindOf(pick), isOn(bypass)));
if (!r) return;
closeModal();
notify(fmt(_('%s added'), name), 'success', 3000);
+1 -1
View File
@@ -180,7 +180,7 @@
.dl-fld { display: flex; flex-direction: column; gap: 8px; margin: 0 0 16px; }
.dl-fld-label { font-size: 13px; font-weight: 500; color: var(--dl-fg); }
.dl-fld .cbi-input-text { width: 100%; box-sizing: border-box; }
.dl-kinds { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.dl-kinds { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.dl-kinds button { all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
height: 68px; border-radius: 10px; border: 1px solid var(--dl-line); color: var(--dl-fg-muted); font-size: 12px; font-weight: 500; text-align: center; min-width: 0; }
.dl-kinds button .dl-icon { width: 20px; height: 20px; }
+2 -1
View File
@@ -93,7 +93,8 @@ export async function runOperation(what: string | null, o: OpOptions, follow?: U
prevId = before?.job?.id;
since = before?.now ?? 0;
const r = await api.updatesRun(what!);
if (r.job && r.job.state === 'running' && r.job.id !== prevId) {
// A quick check may already be over: still this click's job (updates_run never returns an older one).
if (r.job && r.job.id !== prevId) {
job = r.job;
known(r.job);
}
+8 -15
View File
@@ -7,7 +7,7 @@
// to add it there.
import type { ClientConfig, Kind } from '../../shared/types';
import { defaultName, fitName, kindLabel, netsLabel } from '../../shared/format';
import { defaultName, fitName, netsLabel, pickLabel, pickOf, PICKS, type KindPick } from '../../shared/format';
import { guardDeviceName } from '../../shared/name-guard';
import { shake } from '../../shared/shake';
import { fmt, num, plural } from '../../shared/i18n';
@@ -77,15 +77,8 @@ function guessName(kind: Kind): string {
return defaultName(kind);
}
/*
* Phones and tablets are one choice. The device is still kept as a phone or a
* tablet (the lines say "the tablet"): on the device itself the browser tells
* which; picked from elsewhere it is a phone.
*/
type Pick = 'computer' | 'mobile' | 'router' | 'other';
const pickLabel = (p: Pick): string => (p === 'mobile' ? _('Mobile') : kindLabel(p));
const pickOf = (k: Kind): Pick => (k === 'phone' || k === 'tablet' ? 'mobile' : k);
const kindOf = (p: Pick): Kind => (p !== 'mobile' ? p : guessKind() === 'tablet' ? 'tablet' : 'phone');
// Mobile is a tablet when this page is open on one (see KindPick).
const kindOf = (p: KindPick): Kind => (p !== 'mobile' ? p : guessKind() === 'tablet' ? 'tablet' : 'phone');
/**
* What they chose so far, kept outside the view: Back from "Open on the device"
@@ -93,7 +86,7 @@ const kindOf = (p: Pick): Kind => (p !== 'mobile' ? p : guessKind() === 'tablet'
* typed (unset while the name is still the guess).
*/
interface Draft {
pick?: Pick;
pick?: KindPick;
bypass: boolean;
name?: string;
}
@@ -142,11 +135,11 @@ function vAdd(draft: Draft): View {
const st = state()!;
const p = st.person;
// The kinds this router takes, as the four choices.
const picks = (['computer', 'mobile', 'router', 'other'] as Pick[]).filter((k) => st.kinds.some((x) => pickOf(x) === k));
const picks = PICKS.filter((k) => st.kinds.some((x) => pickOf(x) === k));
const guess = picks.includes(pickOf(guessKind())) ? pickOf(guessKind()) : picks[0];
let pick: Pick = draft.pick && picks.includes(draft.pick) ? draft.pick : guess;
let pick: KindPick = draft.pick && picks.includes(draft.pick) ? draft.pick : guess;
const taken = new Set(p.devices.map((d) => d.name.toLowerCase()));
const suggest = (k: Pick) => {
const suggest = (k: KindPick) => {
const n = k === pickOf(guessKind()) ? guessName(kindOf(k)) : defaultName(k === 'mobile' ? 'phone' : k);
// Stripped of what the router refuses and cut to its limit, the number after it too ("Galaxy S24+ 2").
if (!taken.has(fitName(n).toLowerCase())) return fitName(n);
@@ -230,7 +223,7 @@ function vAdd(draft: Draft): View {
if (draft.name === undefined && pick === pickOf(guessKind())) input.value = suggest(pick);
});
// The picked tile rings itself where it stands (the ring does not travel between tiles).
function choose(k: Pick) {
function choose(k: KindPick) {
pick = draft.pick = k;
tiles.forEach((t, i) => {
const on = picks[i] === k;
+1 -1
View File
@@ -808,7 +808,7 @@ msgstr ""
msgid "Method not allowed."
msgstr ""
#: web/src/portal/flows/add.ts
#: web/src/shared/format.ts
msgid "Mobile"
msgstr ""
+1 -1
View File
@@ -813,7 +813,7 @@ msgstr "Мбит/с"
msgid "Method not allowed."
msgstr "Метод не поддерживается."
#: web/src/portal/flows/add.ts
#: web/src/shared/format.ts
msgid "Mobile"
msgstr "Мобильный"
+13 -3
View File
@@ -222,13 +222,23 @@ export function defaultName(k: Kind): string {
return k === 'other' ? _('Device') : kindLabel(k);
}
/** In picker order. */
export const KINDS: Kind[] = ['computer', 'phone', 'tablet', 'router', 'other'];
export function kindLabel(k: Kind): string {
return { computer: _('PC'), phone: _('Phone'), tablet: _('Tablet'), router: _('Router'), other: _('Other') }[k];
}
/**
* Adding a device, phones and tablets are one choice. The device is still
* kept as a phone or a tablet (the lines say "the tablet"): on the device
* itself the browser tells which; picked from elsewhere it is a phone.
*/
export type KindPick = 'computer' | 'mobile' | 'router' | 'other';
/** In picker order. */
export const PICKS: KindPick[] = ['computer', 'mobile', 'router', 'other'];
export const pickLabel = (p: KindPick): string => (p === 'mobile' ? _('Mobile') : kindLabel(p));
export const pickOf = (k: Kind): KindPick => (k === 'phone' || k === 'tablet' ? 'mobile' : k);
export function stateLabel(s: PersonState): string {
return {
active: _('Active'),
+3
View File
@@ -4,6 +4,9 @@ const P: Record<string, string> = {
phone: '<rect x="7" y="2.5" width="10" height="19" rx="2.2"/><path d="M11 18.5h2"/>',
computer: '<rect x="3" y="4.5" width="18" height="12" rx="1.8"/><path d="M2 19.5h20"/>',
tablet: '<rect x="4.5" y="2.5" width="15" height="19" rx="2.2"/><path d="M11 18.5h2"/>',
// Phones and tablets as one choice (KindPick): a phone in front of a tablet, which stops short of it.
mobile:
'<path d="M9.5 6V4.7a2.2 2.2 0 0 1 2.2-2.2h7.1a2.2 2.2 0 0 1 2.2 2.2v11.6a2.2 2.2 0 0 1-2.2 2.2H14"/><rect x="3" y="8" width="8.5" height="13.5" rx="2.2"/><path d="M6.5 18.5h1.5"/>',
router: '<rect x="3" y="13" width="18" height="7" rx="1.8"/><path d="M7 16.5h.01M10.5 16.5h.01M8 13l-2-6M16 13l2-6"/>',
server:
'<rect x="3" y="4" width="18" height="7" rx="1.8"/><rect x="3" y="13" width="18" height="7" rx="1.8"/><path d="M7 7.5h.01M7 16.5h.01M11 7.5h6M11 16.5h6"/>',