Dawnline 0.11.0
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
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
- Russian translation. The admin pages, the LuCI menu and the router's messages (errors, Health checks, update steps, the service log) come in Russian with the new luci-i18n-dawnline-ru package, released beside the app. LuCI shows it when its language is Russian, or "auto" with a Russian browser - The translation installs with install.sh when LuCI is in Russian (or with --lang ru), follows every Dawnline update and rollback, and can be added or removed in Components → Dawnline → Translation - The portal speaks the visitor's language: it opens in the system's language and switches between English and Russian in place, from the language pill beside its QR code. It carries its own translation and needs no package - Set-up steps quote the apps' own menus word for word, in Russian too: AmneziaVPN is "+ → Insert → Continue" (it has no "Add server"), and the Mac and Windows menus of WireGuard and AmneziaWG have their real names - Questions in the portal (Reconnect, Remove) read from the left edge and close with Cancel, without × - Numbers, sizes and dates follow the page's language. A server that can't start says why in one sentence; event details and service log lines read as whole sentences - README in Russian (README_ru.md). rules/i18n.md: how strings are written and translated; CI checks the catalogs (npm run i18n:check)
This commit is contained in:
1 parent
caed976e63
commit
2f2aaf6c34
173 files changed
+25645
-2823
No files matched your search
+10
-2
@@ -3,7 +3,9 @@
|
||||
// throws an ApiError carrying the status and, for a plain-HTTP visitor, the
|
||||
// HTTPS twin of the link.
|
||||
|
||||
import { fmt } from '../shared/i18n';
|
||||
import { base } from './state';
|
||||
import { lang, routerText } from './i18n';
|
||||
|
||||
export class ApiError extends Error {
|
||||
constructor(
|
||||
@@ -20,7 +22,8 @@ export async function call<T>(path: string, body?: unknown): Promise<T> {
|
||||
const res = await fetch(`${base}/api/${path}`, {
|
||||
method: body === undefined ? 'GET' : 'POST',
|
||||
credentials: 'omit',
|
||||
headers: body === undefined ? {} : { 'Content-Type': 'application/json' },
|
||||
// The page's language: the router writes its messages in it when it has the translation.
|
||||
headers: body === undefined ? { 'Accept-Language': lang() } : { 'Content-Type': 'application/json', 'Accept-Language': lang() },
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
cache: 'no-store',
|
||||
});
|
||||
@@ -31,7 +34,12 @@ export async function call<T>(path: string, body?: unknown): Promise<T> {
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
if (!res.ok) throw new ApiError(res.status, data?.error ?? `Request failed (${res.status})`, data?.https_url || undefined);
|
||||
if (!res.ok)
|
||||
throw new ApiError(
|
||||
res.status,
|
||||
data?.error ? routerText(data.error) : fmt(_('Request failed (%s)'), res.status),
|
||||
data?.https_url || undefined,
|
||||
);
|
||||
return data as T;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +1,44 @@
|
||||
// What the demo adds to the breadcrumb: the scenario chip right after the path,
|
||||
// and a GitHub pill just before the page's QR knob (at the end where there is
|
||||
// none: a card alone). On a phone the pill would crowd out the names, so it
|
||||
// and a GitHub pill just before the page's language picker (none over a card
|
||||
// alone, which has no picker either). On a phone the pill would crowd out the names, so it
|
||||
// gives way to a button in the scenario drawer (demo.css). The portal redraws
|
||||
// the breadcrumb with the page and knows nothing of either, so both go back in
|
||||
// place after each redraw.
|
||||
// place after each redraw; a language change makes both again in it.
|
||||
|
||||
import { h, ic } from '../dom';
|
||||
import { onLang } from '../i18n';
|
||||
import { REPO } from './data';
|
||||
import { scenarioChip } from './picker';
|
||||
import type { DemoRouter } from './router';
|
||||
|
||||
export function mountCrumbs(router: DemoRouter) {
|
||||
const app = document.getElementById('app')!;
|
||||
const chip = scenarioChip(router);
|
||||
const gh = h(
|
||||
'a',
|
||||
{ class: 'dm-gh', href: REPO, target: '_blank', rel: 'noopener', 'aria-label': 'Dawnline on GitHub' },
|
||||
ic('github'),
|
||||
h('span', {}, 'GitHub'),
|
||||
);
|
||||
const make = () => ({
|
||||
chip: scenarioChip(router),
|
||||
gh: h(
|
||||
'a',
|
||||
{ class: 'dm-gh', href: REPO, target: '_blank', rel: 'noopener', 'aria-label': _('Dawnline on GitHub') },
|
||||
ic('github'),
|
||||
h('span', {}, 'GitHub'),
|
||||
),
|
||||
});
|
||||
let { chip, gh } = make();
|
||||
// Our own insertions call this again: by then both are in place and nothing moves.
|
||||
const keep = () => {
|
||||
const crumbs = app.querySelector('.crumbs');
|
||||
const path = crumbs?.querySelector('.cr-path');
|
||||
if (!crumbs || !path) return;
|
||||
if (path.nextElementSibling !== chip) path.after(chip);
|
||||
const qr = crumbs.querySelector('.cr-qr');
|
||||
if (qr && qr.previousElementSibling !== gh) qr.before(gh);
|
||||
else if (!qr && crumbs.lastElementChild !== gh) crumbs.append(gh);
|
||||
const lang = crumbs.querySelector('.cr-lang');
|
||||
if (lang && lang.previousElementSibling !== gh) lang.before(gh);
|
||||
};
|
||||
new MutationObserver(keep).observe(app, { childList: true, subtree: true });
|
||||
keep();
|
||||
// The page has redrawn its breadcrumb in the new language by now (main.ts listens first).
|
||||
onLang(() => {
|
||||
chip.remove();
|
||||
gh.remove();
|
||||
({ chip, gh } = make());
|
||||
keep();
|
||||
});
|
||||
}
|
||||
+24
-28
@@ -19,35 +19,31 @@ export interface Scenario {
|
||||
about: string;
|
||||
}
|
||||
|
||||
/** What can be tried, in the picker's groups. */
|
||||
export const GROUPS: { title: string; items: Scenario[] }[] = [
|
||||
{
|
||||
title: 'Your page',
|
||||
items: [
|
||||
{ id: 'normal', label: 'Everything works', about: 'Three devices: one online, one waiting to be set up.' },
|
||||
{ id: 'first', label: 'First visit', about: 'A fresh link with no devices yet.' },
|
||||
{ id: 'stale', label: 'Settings changed', about: 'The admin changed something: a device needs an update.' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Stopped by the admin',
|
||||
items: [
|
||||
{ id: 'quota', label: 'Out of data', about: 'The month’s limit is used up.' },
|
||||
{ id: 'hours', label: 'Outside allowed hours', about: 'Access only at certain hours of the day.' },
|
||||
{ id: 'paused', label: 'Paused by the admin', about: 'The page turns into one card.' },
|
||||
{ id: 'expired', label: 'Access ended', about: 'The end date has passed.' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Other cases',
|
||||
items: [
|
||||
{ id: 'http', label: 'Opened over plain HTTP', about: 'Settings only travel over HTTPS.' },
|
||||
{ id: 'plain', label: 'Plain WireGuard', about: 'Disguise off: any WireGuard app connects.' },
|
||||
{ id: 'full', label: 'No free slots', about: 'Every device slot is taken.' },
|
||||
],
|
||||
},
|
||||
/** What can be tried, in the picker's groups (their words are groups()). */
|
||||
const GROUPS: ScenarioId[][] = [
|
||||
['normal', 'first', 'stale'],
|
||||
['quota', 'hours', 'paused', 'expired'],
|
||||
['http', 'plain', 'full'],
|
||||
];
|
||||
export const SCENARIOS: Scenario[] = GROUPS.flatMap((g) => g.items);
|
||||
export const SCENARIOS: { id: ScenarioId }[] = GROUPS.flat().map((id) => ({ id }));
|
||||
|
||||
/** The picker's groups in the page's language: made when it draws (the language changes in place). */
|
||||
export function groups(): { title: string; items: Scenario[] }[] {
|
||||
const titles = [_('Your page'), _('Stopped by the admin'), _('Other cases')];
|
||||
const words: Record<ScenarioId, [label: string, about: string]> = {
|
||||
normal: [_('Everything works'), _('Three devices: one online, one waiting to be set up.')],
|
||||
first: [_('First visit'), _('A fresh link with no devices yet.')],
|
||||
stale: [_('Settings changed'), _('The admin changed something: a device needs an update.')],
|
||||
quota: [_('Out of data'), _('The month’s limit is used up.')],
|
||||
hours: [_('Outside allowed hours'), _('Access only at certain hours of the day.')],
|
||||
paused: [_('Paused by the admin'), _('The page turns into one card.')],
|
||||
expired: [_('Access ended'), _('The end date has passed.')],
|
||||
http: [_('Opened over plain HTTP'), _('Settings only travel over HTTPS.')],
|
||||
plain: [_('Plain WireGuard'), _('Disguise off: any WireGuard app connects.')],
|
||||
full: [_('No free slots'), _('Every device slot is taken.')],
|
||||
};
|
||||
return GROUPS.map((ids, i) => ({ title: titles[i], items: ids.map((id) => ({ id, label: words[id][0], about: words[id][1] })) }));
|
||||
}
|
||||
export const isScenario = (id: unknown): id is ScenarioId => SCENARIOS.some((s) => s.id === id);
|
||||
|
||||
/** A device as the demo keeps it; the page's Device is made from it on every answer. */
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Dawnline\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "A fresh link with no devices yet."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Access ended"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Access only at certain hours of the day."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/crumbs.ts
|
||||
msgid "Dawnline on GitHub"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "Demo"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/main.ts
|
||||
msgid "Demo keys connect nowhere"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Disguise off: any WireGuard app connects."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Every device slot is taken."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Everything works"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "First visit"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "How the page looks in each case. Nothing here connects."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "No free slots"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Opened over plain HTTP"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Other cases"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Out of data"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Outside allowed hours"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Paused by the admin"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Plain WireGuard"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Settings changed"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Settings only travel over HTTPS."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "Start over"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Stopped by the admin"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "The admin changed something: a device needs an update."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "The demo started over"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "The end date has passed."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "The month’s limit is used up."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "The page turns into one card."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Three devices: one online, one waiting to be set up."
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "Try a scenario"
|
||||
msgstr ""
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Your page"
|
||||
msgstr ""
|
||||
@@ -0,0 +1,129 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Dawnline\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Language: ru\n"
|
||||
"Language-Team: Russian\n"
|
||||
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "A fresh link with no devices yet."
|
||||
msgstr "Новая ссылка, устройств пока нет."
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Access ended"
|
||||
msgstr "Доступ закончился"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Access only at certain hours of the day."
|
||||
msgstr "Доступ только в определённые часы."
|
||||
|
||||
#: web/src/portal/demo/crumbs.ts
|
||||
msgid "Dawnline on GitHub"
|
||||
msgstr "Dawnline на GitHub"
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "Demo"
|
||||
msgstr "Демо"
|
||||
|
||||
#: web/src/portal/demo/main.ts
|
||||
msgid "Demo keys connect nowhere"
|
||||
msgstr "Демо-ключи никуда не подключаются"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Disguise off: any WireGuard app connects."
|
||||
msgstr "Маскировка выключена: подойдёт любое приложение WireGuard."
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Every device slot is taken."
|
||||
msgstr "Все места для устройств заняты."
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Everything works"
|
||||
msgstr "Всё работает"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "First visit"
|
||||
msgstr "Первый визит"
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "How the page looks in each case. Nothing here connects."
|
||||
msgstr "Как выглядит страница в каждом случае. Ничего не подключается по-настоящему."
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "No free slots"
|
||||
msgstr "Нет свободных мест"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Opened over plain HTTP"
|
||||
msgstr "Открыто по обычному HTTP"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Other cases"
|
||||
msgstr "Другие случаи"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Out of data"
|
||||
msgstr "Трафик закончился"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Outside allowed hours"
|
||||
msgstr "Вне часов доступа"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Paused by the admin"
|
||||
msgstr "Доступ на паузе"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Plain WireGuard"
|
||||
msgstr "Обычный WireGuard"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Settings changed"
|
||||
msgstr "Настройки изменились"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Settings only travel over HTTPS."
|
||||
msgstr "Настройки передаются только по HTTPS."
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "Start over"
|
||||
msgstr "Начать заново"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Stopped by the admin"
|
||||
msgstr "Ограничения администратора"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "The admin changed something: a device needs an update."
|
||||
msgstr "Администратор что-то поменял: устройство нужно обновить."
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "The demo started over"
|
||||
msgstr "Демо началось заново"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "The end date has passed."
|
||||
msgstr "Дата окончания прошла."
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "The month’s limit is used up."
|
||||
msgstr "Месячный лимит исчерпан."
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "The page turns into one card."
|
||||
msgstr "Страница сворачивается в одну карточку."
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Three devices: one online, one waiting to be set up."
|
||||
msgstr "Три устройства: одно в сети, одно ждёт настройки."
|
||||
|
||||
#: web/src/portal/demo/picker.ts
|
||||
msgid "Try a scenario"
|
||||
msgstr "Выберите сценарий"
|
||||
|
||||
#: web/src/portal/demo/data.ts
|
||||
msgid "Your page"
|
||||
msgstr "Ваша страница"
|
||||
@@ -4,11 +4,16 @@
|
||||
// picker.ts). The order of the imports is the boot order: the router owns
|
||||
// fetch before the portal loads.
|
||||
|
||||
// First: the translation globals, before anything draws.
|
||||
import { addCatalog } from '../i18n';
|
||||
import ru from './i18n/ru.po';
|
||||
import { router } from './serve';
|
||||
import '../main';
|
||||
import { toast } from '../ui/feedback';
|
||||
import { mountCrumbs } from './crumbs';
|
||||
|
||||
// The demo's own words (the scenarios, its chip and toasts), beside the portal's.
|
||||
addCatalog('ru', ru);
|
||||
mountCrumbs(router);
|
||||
|
||||
// An AmneziaVPN key would add a server that connects nowhere to the visitor's app: the demo keeps it on the page.
|
||||
@@ -18,7 +23,7 @@ document.addEventListener(
|
||||
if (!(e.target as Element).closest?.('a[href^="vpn:"]')) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
toast('Demo keys connect nowhere', true);
|
||||
toast(_('Demo keys connect nowhere'), true);
|
||||
},
|
||||
true,
|
||||
);
|
||||
@@ -11,7 +11,7 @@ import { closeSheet, head, openSheet, sub, type View } from '../ui/sheet';
|
||||
import { glass, type Tone } from '../ui/glass';
|
||||
import { toast } from '../ui/feedback';
|
||||
import { EASE_OUT, play } from '../motion';
|
||||
import { GROUPS, REPO, type Scenario, type ScenarioId } from './data';
|
||||
import { REPO, groups, type Scenario, type ScenarioId } from './data';
|
||||
import type { DemoRouter } from './router';
|
||||
|
||||
/** Each scenario's glass icon and tone (the glass set is smaller than the line icons). */
|
||||
@@ -75,9 +75,9 @@ export function scenarioChip(router: DemoRouter): HTMLElement {
|
||||
const el = h(
|
||||
'div',
|
||||
{ class: 'view' },
|
||||
head('Try a scenario'),
|
||||
sub('How the page looks in each case. Nothing here connects.'),
|
||||
...GROUPS.map((g) =>
|
||||
head(_('Try a scenario')),
|
||||
sub(_('How the page looks in each case. Nothing here connects.')),
|
||||
...groups().map((g) =>
|
||||
h('div', { class: 'dm-group' }, h('div', { class: 'lbl-s' }, g.title), h('div', { class: 'dm-list' }, ...g.items.map(row))),
|
||||
),
|
||||
h(
|
||||
@@ -85,20 +85,20 @@ export function scenarioChip(router: DemoRouter): HTMLElement {
|
||||
{ class: 'dm-foot' },
|
||||
h(
|
||||
'button',
|
||||
{ type: 'button', class: 'btn soft', onclick: () => pick(router.scenario(), 'The demo started over') },
|
||||
{ type: 'button', class: 'btn soft', onclick: () => pick(router.scenario(), _('The demo started over')) },
|
||||
ic('reset'),
|
||||
h('span', {}, 'Start over'),
|
||||
h('span', {}, _('Start over')),
|
||||
),
|
||||
h('a', { class: 'btn soft dm-gh-alt', href: REPO, target: '_blank', rel: 'noopener' }, ic('github'), h('span', {}, 'GitHub')),
|
||||
),
|
||||
);
|
||||
return { el, label: 'Try a scenario' };
|
||||
return { el, label: _('Try a scenario') };
|
||||
}
|
||||
|
||||
return h(
|
||||
'button',
|
||||
{ type: 'button', class: 'dm-chip', 'aria-haspopup': 'dialog', onclick: () => openSheet(scenarios) },
|
||||
h('span', {}, 'Demo'),
|
||||
h('span', {}, _('Demo')),
|
||||
ic('chevron', 'i'),
|
||||
);
|
||||
}
|
||||
+34
-23
@@ -4,7 +4,8 @@
|
||||
// opens on the device itself, from a code, ready to add it there.
|
||||
|
||||
import type { ClientConfig, Kind } from '../../shared/types';
|
||||
import { KIND_LABEL } from '../../shared/format';
|
||||
import { kindLabel } from '../../shared/format';
|
||||
import { fmt, num, plural } from '../../shared/i18n';
|
||||
import { ApiError, call } from '../api';
|
||||
import { h, ic } from '../dom';
|
||||
import { EASE_OUT, play } from '../motion';
|
||||
@@ -62,12 +63,12 @@ const modelReady: Promise<string> = (async () => {
|
||||
function guessName(kind: Kind): string {
|
||||
if (/iPhone/.test(UA)) return 'iPhone';
|
||||
if (IPAD) return 'iPad';
|
||||
if (/Android/.test(UA)) return MODEL || (kind === 'tablet' ? 'Android tablet' : 'Android phone');
|
||||
if (/Android/.test(UA)) return MODEL || (kind === 'tablet' ? _('Android tablet') : _('Android phone'));
|
||||
if (/CrOS/.test(UA)) return 'Chromebook';
|
||||
if (/Mac OS X/.test(UA)) return 'Mac';
|
||||
if (/Windows/.test(UA)) return 'Windows PC';
|
||||
if (/Linux/.test(UA)) return 'Linux PC';
|
||||
return KIND_LABEL[kind];
|
||||
if (/Windows/.test(UA)) return _('Windows PC');
|
||||
if (/Linux/.test(UA)) return _('Linux PC');
|
||||
return kindLabel(kind);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -76,14 +77,18 @@ function guessName(kind: Kind): string {
|
||||
* which; picked from elsewhere it is a phone.
|
||||
*/
|
||||
type Pick = 'computer' | 'mobile' | 'router' | 'other';
|
||||
const PICK_LABEL: Record<Pick, string> = { computer: 'PC', mobile: 'Mobile', router: 'Router', other: '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');
|
||||
|
||||
export function startAdd() {
|
||||
const st = state();
|
||||
if (!st || st.locked) return;
|
||||
if (!st.can_add) return toast(`You have reached your limit of ${st.person.device_limit} devices`, true);
|
||||
if (!st.can_add)
|
||||
return toast(
|
||||
plural(st.person.device_limit, 'You have reached your limit of %s device', 'You have reached your limit of %s devices'),
|
||||
true,
|
||||
);
|
||||
if (secureFirst()) return;
|
||||
openSheet(vAdd);
|
||||
}
|
||||
@@ -97,26 +102,32 @@ function vAdd(): View {
|
||||
let edited = false;
|
||||
const taken = new Set(p.devices.map((d) => d.name.toLowerCase()));
|
||||
const suggest = (k: Pick) => {
|
||||
const n = k === pickOf(guessKind()) ? guessName(kindOf(k)) : k === 'mobile' ? 'Phone' : KIND_LABEL[k];
|
||||
const n = k === pickOf(guessKind()) ? guessName(kindOf(k)) : kindLabel(k === 'mobile' ? 'phone' : k);
|
||||
if (!taken.has(n.toLowerCase())) return n;
|
||||
for (let i = 2; i < 20; i++) if (!taken.has(`${n} ${i}`.toLowerCase())) return `${n} ${i}`;
|
||||
return n;
|
||||
};
|
||||
|
||||
const kinds = h('div', { class: 'kinds', role: 'radiogroup', 'aria-label': 'What is it?' });
|
||||
const kinds = h('div', { class: 'kinds', role: 'radiogroup', 'aria-label': _('What is it?') });
|
||||
kinds.style.setProperty('--n', String(picks.length));
|
||||
const tiles = picks.map((k) => {
|
||||
const t = h(
|
||||
'button',
|
||||
{ type: 'button', class: 'kind', role: 'radio', 'aria-label': PICK_LABEL[k], onclick: () => choose(k) },
|
||||
{ type: 'button', class: 'kind', role: 'radio', 'aria-label': pickLabel(k), onclick: () => choose(k) },
|
||||
h('span', { class: 'kind-tile' }, glass(k, 'blue')),
|
||||
h('span', { class: 'kind-lbl' }, PICK_LABEL[k]),
|
||||
h('span', { class: 'kind-lbl' }, pickLabel(k)),
|
||||
);
|
||||
kinds.appendChild(t);
|
||||
return t;
|
||||
});
|
||||
const input = h('input', { type: 'text', maxlength: 48, required: true, 'aria-label': 'Name', autocomplete: 'off' }) as HTMLInputElement;
|
||||
const goBtn = h('button', { class: 'go ready', type: 'submit', 'aria-label': 'Create connection' }, ic('arrow')) as HTMLButtonElement;
|
||||
const input = h('input', {
|
||||
type: 'text',
|
||||
maxlength: 48,
|
||||
required: true,
|
||||
'aria-label': _('Name'),
|
||||
autocomplete: 'off',
|
||||
}) as HTMLInputElement;
|
||||
const goBtn = h('button', { class: 'go ready', type: 'submit', 'aria-label': _('Create connection') }, ic('arrow')) as HTMLButtonElement;
|
||||
const err = h('p', { class: 'hint bad-t', hidden: true });
|
||||
const say = (msg: string) => {
|
||||
// Already showing: its words change in place.
|
||||
@@ -162,7 +173,7 @@ function vAdd(): View {
|
||||
e.preventDefault();
|
||||
const name = input.value.trim();
|
||||
if (!name) return;
|
||||
if (taken.has(name.toLowerCase())) return say('You already have a device with this name.');
|
||||
if (taken.has(name.toLowerCase())) return say(_('You already have a device with this name.'));
|
||||
void once(goBtn, async () => {
|
||||
try {
|
||||
const r = await call<{ id: string; config: ClientConfig; state: State }>('devices', { name, kind: kindOf(pick) });
|
||||
@@ -180,23 +191,23 @@ function vAdd(): View {
|
||||
'button',
|
||||
{ type: 'button', class: 'btn soft block', onclick: () => go(vLink) },
|
||||
ic('qr'),
|
||||
h('span', {}, 'Add it from the device'),
|
||||
h('span', {}, _('Add it from the device')),
|
||||
);
|
||||
const free = p.device_limit - p.devices.length;
|
||||
const el = h(
|
||||
'div',
|
||||
{ class: 'view' },
|
||||
head('Add a device'),
|
||||
sub(`${free} of ${p.device_limit} slots free`),
|
||||
head(_('Add a device')),
|
||||
sub(fmt(N_(p.device_limit, '%s of %s slot free', '%s of %s slots free'), num(free), num(p.device_limit))),
|
||||
kinds,
|
||||
hint('Phones and tablets get a smaller packet size that suits mobile networks.'),
|
||||
hint(_('Phones and tablets get a smaller packet size that suits mobile networks.')),
|
||||
form,
|
||||
err,
|
||||
h('div', { class: 'or' }, 'OR'),
|
||||
h('div', { class: 'or' }, _('OR')),
|
||||
viaLink,
|
||||
);
|
||||
el.querySelector('.hint')!.classList.add('kinds-note');
|
||||
return { el, label: 'Add a device' };
|
||||
return { el, label: _('Add a device') };
|
||||
}
|
||||
|
||||
/** The page on the device itself, ready to add it: the link as a code for its camera, and as text. */
|
||||
@@ -205,10 +216,10 @@ function vLink(): View {
|
||||
const el = h(
|
||||
'div',
|
||||
{ class: 'view' },
|
||||
head('Open on the device', { back: true }),
|
||||
sub('Point its camera at the code: your page opens there with this device ready to add.'),
|
||||
head(_('Open on the device'), { back: true }),
|
||||
sub(_('Point its camera at the code: your page opens there with this device ready to add.')),
|
||||
qrBox(link, true),
|
||||
linkRow(link),
|
||||
);
|
||||
return { el, label: 'Open on the device' };
|
||||
return { el, label: _('Open on the device') };
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
// be undone; the action's button stays busy until the router answers.
|
||||
|
||||
import type { ClientConfig, Device } from '../../shared/types';
|
||||
import { fmt } from '../../shared/i18n';
|
||||
import { call } from '../api';
|
||||
import { h, ic } from '../dom';
|
||||
import { EASE_IN, play } from '../motion';
|
||||
@@ -13,7 +14,7 @@ import { closeSheet, head, onClosed, openSheet, type View } from '../ui/sheet';
|
||||
import { secureFirst } from './secure';
|
||||
import { continueSetup } from './setup-view';
|
||||
|
||||
/** A question before something that cannot be undone: the action's icon in its colour, what happens, Cancel and the action. */
|
||||
/** A question before something that cannot be undone: the action's icon in its colour, what happens (on the left edge), Cancel and the action. */
|
||||
function ask(o: { icon: string; tone: Tone; title: string; text: string; action: string; cls: string; run: () => Promise<void> }): View {
|
||||
const ok = h(
|
||||
'button',
|
||||
@@ -26,11 +27,11 @@ function ask(o: { icon: string; tone: Tone; title: string; text: string; action:
|
||||
{ class: 'view' },
|
||||
h(
|
||||
'div',
|
||||
{ class: 'center-col ask' },
|
||||
{ class: 'ask' },
|
||||
glass(o.icon, o.tone, 'gi xl'),
|
||||
h('h3', {}, o.title),
|
||||
h('p', {}, o.text),
|
||||
h('div', { class: 'btnrow' }, h('button', { type: 'button', class: 'btn soft', onclick: () => closeSheet() }, 'Cancel'), ok),
|
||||
h('div', { class: 'btnrow' }, h('button', { type: 'button', class: 'btn soft', onclick: () => closeSheet() }, _('Cancel')), ok),
|
||||
),
|
||||
);
|
||||
return { el, label: o.title, asks: true };
|
||||
@@ -38,9 +39,9 @@ function ask(o: { icon: string; tone: Tone; title: string; text: string; action:
|
||||
|
||||
export function rename(d: Device) {
|
||||
openSheet(() => {
|
||||
const input = h('input', { type: 'text', maxlength: 48, 'aria-label': 'Device name', autocomplete: 'off' }) as HTMLInputElement;
|
||||
const input = h('input', { type: 'text', maxlength: 48, 'aria-label': _('Device name'), autocomplete: 'off' }) as HTMLInputElement;
|
||||
input.value = d.name;
|
||||
const save = h('button', { class: 'go', type: 'submit', 'aria-label': 'Save' }, ic('check')) as HTMLButtonElement;
|
||||
const save = h('button', { class: 'go', type: 'submit', 'aria-label': _('Save') }, ic('check')) as HTMLButtonElement;
|
||||
input.addEventListener('input', () => save.classList.toggle('ready', !!input.value.trim() && input.value.trim() !== d.name));
|
||||
const form = h('form', { class: 'field', autocomplete: 'off' }, input, save);
|
||||
form.addEventListener('submit', (e) => {
|
||||
@@ -53,7 +54,7 @@ export function rename(d: Device) {
|
||||
setState(r.state);
|
||||
onClosed(() => {
|
||||
repaint();
|
||||
toast('Renamed');
|
||||
toast(_('Renamed'));
|
||||
});
|
||||
closeSheet();
|
||||
} catch (er) {
|
||||
@@ -62,7 +63,8 @@ export function rename(d: Device) {
|
||||
});
|
||||
});
|
||||
setTimeout(() => input.select(), 60);
|
||||
return { el: h('div', { class: 'view' }, head(`Rename ${d.name}`), form), label: `Rename ${d.name}` };
|
||||
const title = fmt(_('Rename %s'), d.name);
|
||||
return { el: h('div', { class: 'view' }, head(title), form), label: title };
|
||||
});
|
||||
}
|
||||
|
||||
@@ -78,11 +80,13 @@ export function reconnect(d: Device) {
|
||||
ask({
|
||||
icon: 'refresh',
|
||||
tone: 'orange',
|
||||
title: `Reconnect ${d.name}?`,
|
||||
title: fmt(_('Reconnect %s?'), d.name),
|
||||
text: here
|
||||
? 'It gets new keys. This device is connected through its current settings: it disconnects a few seconds after you confirm. Add the new ones that open next.'
|
||||
: 'It gets new keys and its current settings stop working. Set it up again with the new ones that open next.',
|
||||
action: 'Reconnect',
|
||||
? _(
|
||||
'It gets new keys. This device is connected through its current settings: it disconnects a few seconds after you confirm. Add the new ones that open next.',
|
||||
)
|
||||
: _('It gets new keys and its current settings stop working. Set it up again with the new ones that open next.'),
|
||||
action: _('Reconnect'),
|
||||
cls: 'accent',
|
||||
run: async () => {
|
||||
try {
|
||||
@@ -103,9 +107,9 @@ export function removeDevice(d: Device) {
|
||||
ask({
|
||||
icon: 'trash',
|
||||
tone: 'red',
|
||||
title: `Remove ${d.name}?`,
|
||||
text: 'Its connection stops working at once. You can add it again later.',
|
||||
action: 'Remove',
|
||||
title: fmt(_('Remove %s?'), d.name),
|
||||
text: _('Its connection stops working at once. You can add it again later.'),
|
||||
action: _('Remove'),
|
||||
cls: 'red',
|
||||
run: async () => {
|
||||
try {
|
||||
@@ -116,7 +120,7 @@ export function removeDevice(d: Device) {
|
||||
const card = document.querySelector(`.dev[data-id="${CSS.escape(d.id)}"]`);
|
||||
const done = () => {
|
||||
repaint();
|
||||
toast('Device removed');
|
||||
toast(_('Device removed'));
|
||||
};
|
||||
if (!card) return done();
|
||||
play(
|
||||
|
||||
@@ -12,11 +12,11 @@ export function showPageCode() {
|
||||
const el = h(
|
||||
'div',
|
||||
{ class: 'view' },
|
||||
head('Open on another device'),
|
||||
sub('Point its camera at the code: this page opens there.'),
|
||||
head(_('Open on another device')),
|
||||
sub(_('Point its camera at the code: this page opens there.')),
|
||||
qrBox(url, true),
|
||||
linkRow(url),
|
||||
);
|
||||
return { el, label: 'Open on another device' };
|
||||
return { el, label: _('Open on another device') };
|
||||
});
|
||||
}
|
||||
@@ -11,20 +11,22 @@ function vSecure(url: string): View {
|
||||
const el = h(
|
||||
'div',
|
||||
{ class: 'view' },
|
||||
head('Open the link securely'),
|
||||
sub('Connection settings only travel encrypted'),
|
||||
head(_('Open the link securely')),
|
||||
sub(_('Connection settings only travel encrypted')),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'center-col secure' },
|
||||
glass('lock', 'blue', 'gi xl'),
|
||||
h('p', {}, 'This page is open without encryption. To add or set up a device, open the same link over HTTPS:'),
|
||||
h('p', {}, _('This page is open without encryption. To add or set up a device, open the same link over HTTPS:')),
|
||||
),
|
||||
// The same tab: the HTTPS page replaces this one.
|
||||
h('a', { class: 'btn accent block', href: url }, ic('lock'), h('span', {}, 'Open securely')),
|
||||
hint('The browser may warn that the certificate is not trusted: it is this router’s own. Choose to continue (“Advanced” → “Proceed”).'),
|
||||
h('a', { class: 'btn accent block', href: url }, ic('lock'), h('span', {}, _('Open securely'))),
|
||||
hint(
|
||||
_('The browser may warn that the certificate is not trusted: it is this router’s own. Choose to continue (“Advanced” → “Proceed”).'),
|
||||
),
|
||||
);
|
||||
el.lastElementChild!.classList.add('secure-note');
|
||||
return { el, label: 'Open the link securely' };
|
||||
return { el, label: _('Open the link securely') };
|
||||
}
|
||||
|
||||
/** The HTTPS twin's sheet (here, or the one the router named in a refusal). */
|
||||
|
||||
@@ -5,16 +5,19 @@
|
||||
// where an app scans a code. The rules behind them are setup.ts.
|
||||
|
||||
import type { ClientConfig, Device } from '../../shared/types';
|
||||
import { fill, fmt } from '../../shared/i18n';
|
||||
import { h, ic, type Kid } from '../dom';
|
||||
import { EASE_OUT, POP, SMOOTH, play } from '../motion';
|
||||
import {
|
||||
APP_NAME,
|
||||
PLATFORM_LABEL,
|
||||
importPath,
|
||||
importSteps,
|
||||
keyFileName,
|
||||
opensKeyLinks,
|
||||
platformLabel,
|
||||
routerStore,
|
||||
scanPath,
|
||||
vpnContinue,
|
||||
storeFor,
|
||||
type AppId,
|
||||
type Platform,
|
||||
@@ -83,7 +86,7 @@ export function badge(
|
||||
/** Where the app comes from: the store (and, on Android, the APK beside it), or a line to go and get it. */
|
||||
export function storeBlock(app: AppId, os: Platform, router: boolean): Kid[] {
|
||||
const st: Store | null = router ? routerStore(app) : storeFor(app, os);
|
||||
if (!st) return [hint(`Get ${APP_NAME[app]} on the ${PLATFORM_LABEL[os]} and come back here.`)];
|
||||
if (!st) return [hint(fmt(_('Get %s on the %s and come back here.'), APP_NAME[app], platformLabel(os)))];
|
||||
// Android: the store can fail (no Google Play, or it hides the app), so the APK sits beside it.
|
||||
if (st.alt) return [h('div', { class: 'badges2' }, badge(st), badge(st.alt)), hint(st.alt.why)];
|
||||
return [badge(st)];
|
||||
@@ -106,35 +109,40 @@ export function connectKids(c: SetupCtx): Kid[] {
|
||||
// On the phone being set up, a link opens AmneziaVPN only on Android; an
|
||||
// iPhone takes the key as a .vpn file from the share sheet.
|
||||
const inHand = c.same() && hereHandheld;
|
||||
const copyKey = (ev: Event) => copy(c.key, 'Key copied', ev.currentTarget);
|
||||
const copyKey = (ev: Event) => copy(c.key, _('Key copied'), ev.currentTarget);
|
||||
const send = app === 'vpn' && inHand && !opensKeyLinks(c.pf) ? shareFile(keyFileName(c.cfg.filename), c.key) : null;
|
||||
if (app === 'vpn' && inHand && (opensKeyLinks(c.pf) || send))
|
||||
return [
|
||||
send
|
||||
? badge({ top: 'Then come back here and tap', main: 'Send to AmneziaVPN', mark: 'amnezia', onclick: () => void send() }, true)
|
||||
: badge({ href: c.key, top: 'Then come back here and tap', main: 'Open in AmneziaVPN', mark: 'amnezia' }, true),
|
||||
? badge({ top: _('Then come back here and tap'), main: _('Send to AmneziaVPN'), mark: 'amnezia', onclick: () => void send() }, true)
|
||||
: badge({ href: c.key, top: _('Then come back here and tap'), main: _('Open in AmneziaVPN'), mark: 'amnezia' }, true),
|
||||
hint(
|
||||
send ? 'Pick AmneziaVPN in the share sheet. Not there? ' : 'Nothing opened? ',
|
||||
linkBtn('Copy the key', copyKey),
|
||||
' and add it in the app.',
|
||||
...fill(
|
||||
send
|
||||
? _('Pick AmneziaVPN in the share sheet. Not there? %s and add it in the app.')
|
||||
: _('Nothing opened? %s and add it in the app.'),
|
||||
linkBtn(_('Copy the key', 'in a sentence'), copyKey),
|
||||
),
|
||||
),
|
||||
];
|
||||
if (app === 'vpn')
|
||||
if (app === 'vpn') {
|
||||
const path = importPath('vpn');
|
||||
return [
|
||||
badge({ top: 'The connection as one key', main: 'Copy the key', mark: 'copy', onclick: copyKey }, true),
|
||||
badge({ top: _('The connection as one key'), main: _('Copy the key'), mark: 'copy', onclick: copyKey }, true),
|
||||
howto([
|
||||
['Open AmneziaVPN', ''],
|
||||
['Add server › ', 'Insert key'],
|
||||
['Paste the key and connect', ''],
|
||||
[fmt(_('Open %s', 'step'), name), ''],
|
||||
[path.replace(/ → [^→]*$/, ' → '), path.replace(/^.* → /, '')],
|
||||
[vpnContinue(), ''],
|
||||
]),
|
||||
];
|
||||
}
|
||||
const share = hereHandheld ? shareFile(c.cfg.filename, c.cfg.conf) : null;
|
||||
return [
|
||||
share
|
||||
? badge(
|
||||
{
|
||||
top: c.same() ? `Straight into ${name}` : `Send it to the ${c.there}`,
|
||||
main: 'Share the file',
|
||||
top: c.same() ? fmt(_('Straight into %s'), name) : fmt(_('Send it to the %s'), c.there),
|
||||
main: _('Share the file'),
|
||||
mark: 'share',
|
||||
onclick: () => void share(),
|
||||
},
|
||||
@@ -142,8 +150,8 @@ export function connectKids(c: SetupCtx): Kid[] {
|
||||
)
|
||||
: badge(
|
||||
{
|
||||
top: 'Then import it in the app',
|
||||
main: 'Download the file',
|
||||
top: _('Then import it in the app'),
|
||||
main: _('Download the file'),
|
||||
mark: 'download',
|
||||
onclick: () => download(c.cfg.filename, c.cfg.conf),
|
||||
},
|
||||
@@ -163,23 +171,31 @@ export function sendKids(c: SetupCtx): Kid[] {
|
||||
const file = keyFileName(c.cfg.filename);
|
||||
const share = !!shareFile(file, c.key);
|
||||
return [
|
||||
h('p', { class: 'desc' }, `Send it to the ${c.there} in a message or a note, then in AmneziaVPN: Add server › Insert key.`),
|
||||
h(
|
||||
'p',
|
||||
{ class: 'desc' },
|
||||
fmt(_('Send it to the %s in a message or a note, then in AmneziaVPN: %s.'), c.there, importPath('vpn').replace(/ → /g, ' › ')),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'btnrow2' },
|
||||
btn('copy', 'Copy the key', (ev) => copy(c.key, 'Key copied', ev.currentTarget)),
|
||||
btn(share ? 'share' : 'download', share ? 'Share as a file' : 'Download the key', () => sendFile(file, c.key)),
|
||||
btn('copy', _('Copy the key'), (ev) => copy(c.key, _('Key copied'), ev.currentTarget)),
|
||||
btn(share ? 'share' : 'download', share ? _('Share as a file') : _('Download the key'), () => sendFile(file, c.key)),
|
||||
),
|
||||
];
|
||||
}
|
||||
const share = !!shareFile(c.cfg.filename, c.cfg.conf);
|
||||
return [
|
||||
h('p', { class: 'desc' }, `Send it to the ${c.there}, then import `, h('b', {}, c.cfg.filename), ` in ${APP_NAME[app]}.`),
|
||||
h(
|
||||
'p',
|
||||
{ class: 'desc' },
|
||||
...fill<Node | string>(_('Send it to the %s, then import %s in %s.'), c.there, h('b', {}, c.cfg.filename), APP_NAME[app]),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'btnrow2' },
|
||||
btn(share ? 'share' : 'download', share ? 'Share the file' : 'Download the file', () => sendFile(c.cfg.filename, c.cfg.conf)),
|
||||
btn('copy', 'Copy the configuration', (ev) => copy(c.cfg.conf, 'Configuration copied', ev.currentTarget)),
|
||||
btn(share ? 'share' : 'download', share ? _('Share the file') : _('Download the file'), () => sendFile(c.cfg.filename, c.cfg.conf)),
|
||||
btn('copy', _('Copy the configuration'), (ev) => copy(c.cfg.conf, _('Configuration copied'), ev.currentTarget)),
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -208,7 +224,7 @@ export function filePane(cfg: ClientConfig): HTMLElement {
|
||||
class: 'btn soft sm',
|
||||
onclick: () => {
|
||||
reveal = !reveal;
|
||||
eye.replaceChildren(ic(reveal ? 'x' : 'key'), h('span', {}, reveal ? 'Hide key' : 'Show key'));
|
||||
eye.replaceChildren(ic(reveal ? 'x' : 'key'), h('span', {}, reveal ? _('Hide key') : _('Show key')));
|
||||
paint();
|
||||
// A key shown comes into focus out of a blur; hidden again, the mask fades back.
|
||||
pre.querySelectorAll('.mask, .k').forEach((x) =>
|
||||
@@ -224,13 +240,13 @@ export function filePane(cfg: ClientConfig): HTMLElement {
|
||||
},
|
||||
},
|
||||
ic('key'),
|
||||
h('span', {}, 'Show key'),
|
||||
h('span', {}, _('Show key')),
|
||||
);
|
||||
const cp = h(
|
||||
'button',
|
||||
{ type: 'button', class: 'btn soft sm', onclick: (ev: Event) => copy(cfg.conf, 'Configuration copied', ev.currentTarget) },
|
||||
{ type: 'button', class: 'btn soft sm', onclick: (ev: Event) => copy(cfg.conf, _('Configuration copied'), ev.currentTarget) },
|
||||
ic('copy'),
|
||||
h('span', { class: 'lbl' }, 'Copy'),
|
||||
h('span', { class: 'lbl' }, _('Copy')),
|
||||
);
|
||||
const card = h(
|
||||
'div',
|
||||
@@ -239,16 +255,16 @@ export function filePane(cfg: ClientConfig): HTMLElement {
|
||||
'div',
|
||||
{ class: 'fc-row' },
|
||||
h('span', { class: 'filecard-ic' }, '.conf'),
|
||||
h('span', { class: 't' }, h('span', { class: 'mono' }, cfg.filename), h('span', {}, 'For computers and routers')),
|
||||
h('span', { class: 't' }, h('span', { class: 'mono' }, cfg.filename), h('span', {}, _('For computers and routers'))),
|
||||
),
|
||||
h(
|
||||
'button',
|
||||
{ type: 'button', class: 'btn accent sm block', onclick: () => sendFile(cfg.filename, cfg.conf) },
|
||||
ic(share ? 'open' : 'download'),
|
||||
h('span', {}, share ? 'Share file' : 'Download'),
|
||||
h('span', {}, share ? _('Share file') : _('Download')),
|
||||
),
|
||||
);
|
||||
const conf = accordion([{ icon: glass('file'), title: 'Configuration', body: [h('div', { class: 'confbar' }, eye, cp), pre] }], {
|
||||
const conf = accordion([{ icon: glass('file'), title: _('Configuration'), body: [h('div', { class: 'confbar' }, eye, cp), pre] }], {
|
||||
inset: true,
|
||||
});
|
||||
return h('div', { class: 'step-box' }, card, conf.el);
|
||||
@@ -265,7 +281,7 @@ export function scanLine(app: AppId): ScanLine {
|
||||
const name = h('span', { class: 'osm-p' }, APP_NAME[app]);
|
||||
const path = menuLine(scanPath(app, 'ios'), scanPath(app, 'android'));
|
||||
return {
|
||||
el: h('span', { class: 'scanline' }, h('span', {}, 'In ', name, ':'), path.el),
|
||||
el: h('span', { class: 'scanline' }, h('span', {}, ...fill(_('In %s:'), name)), path.el),
|
||||
set(a) {
|
||||
morphText(name, APP_NAME[a], undefined, { whole: true });
|
||||
path.set(scanPath(a, 'ios'), scanPath(a, 'android'));
|
||||
@@ -291,12 +307,12 @@ export function connPill(get: () => { text: string; msg: string; file: string; a
|
||||
const tip = h('span', { class: 'hp-tip', 'aria-hidden': 'true' }, tt, tm);
|
||||
const dl = h('button', { type: 'button', class: 'hp-b', onclick: () => sendFile(get().file, get().text) }, ic('download'));
|
||||
const cp = h('button', { type: 'button', class: 'hp-b' }, ic('copy'));
|
||||
const el = h('div', { class: 'hpill', role: 'group', 'aria-label': 'The connection', 'data-key': 'conn' }, dl, cp, tip);
|
||||
const el = h('div', { class: 'hpill', role: 'group', 'aria-label': _('The connection'), 'data-key': 'conn' }, dl, cp, tip);
|
||||
|
||||
let tipFor: HTMLElement | null = null;
|
||||
let tipT = 0;
|
||||
let warmUntil = 0;
|
||||
const words = (b: HTMLElement) => (b === cp && cp.classList.contains('done') ? 'Copied' : (b.getAttribute('aria-label') ?? ''));
|
||||
const words = (b: HTMLElement) => (b === cp && cp.classList.contains('done') ? _('Copied') : (b.getAttribute('aria-label') ?? ''));
|
||||
// Centred under its key, but never past the sheet's edge (× and its margin to the right).
|
||||
const centre = (b: HTMLElement, t: string) => {
|
||||
tm.textContent = t;
|
||||
@@ -401,8 +417,8 @@ export function connPill(get: () => { text: string; msg: string; file: string; a
|
||||
el,
|
||||
sync() {
|
||||
const app = get().app;
|
||||
dl.setAttribute('aria-label', `Download ${app} config`);
|
||||
cp.setAttribute('aria-label', `Copy ${app} config`);
|
||||
dl.setAttribute('aria-label', fmt(_('Download %s config'), app));
|
||||
cp.setAttribute('aria-label', fmt(_('Copy %s config'), app));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
// connection sits on top the whole time (wait.ts).
|
||||
|
||||
import type { ClientConfig, Device } from '../../shared/types';
|
||||
import { fmt } from '../../shared/i18n';
|
||||
import { vpnKey, vpnQrText } from '../../shared/vpnkey';
|
||||
import { ApiError, call } from '../api';
|
||||
import { h, put } from '../dom';
|
||||
@@ -115,6 +116,7 @@ export function setupView(d: Device, cfg: ClientConfig, key: string): View {
|
||||
const same = sameDevice(d.kind, pf);
|
||||
const layout: Layout = same ? 'same' : router ? 'router' : handheld ? 'away' : 'pc-away';
|
||||
const there = deviceNoun(d.kind);
|
||||
const thereOn = deviceNoun(d.kind, true);
|
||||
// A router takes AmneziaWG (or WireGuard), never AmneziaVPN.
|
||||
const choices = apps.filter((a) => !router || a.id !== 'vpn');
|
||||
let app: AppId = recallApp(d) ?? (router ? 'awg' : 'vpn');
|
||||
@@ -152,15 +154,15 @@ export function setupView(d: Device, cfg: ClientConfig, key: string): View {
|
||||
layout === 'away'
|
||||
? connPill(() => ({
|
||||
...(app === 'vpn'
|
||||
? { text: key, msg: 'Key copied', file: keyFileName(cfg.filename) }
|
||||
: { text: cfg.conf, msg: 'Configuration copied', file: cfg.filename }),
|
||||
? { text: key, msg: _('Key copied'), file: keyFileName(cfg.filename) }
|
||||
: { text: cfg.conf, msg: _('Configuration copied'), file: cfg.filename }),
|
||||
app: APP_NAME[app],
|
||||
}))
|
||||
: null;
|
||||
|
||||
/** Everything a pick changes, refilled in place. */
|
||||
function fill() {
|
||||
morphText(title1, router ? `Get ${APP_NAME[app]} on the router` : `Get ${APP_NAME[app]}`, undefined, { whole: true });
|
||||
morphText(title1, router ? fmt(_('Get %s on the router'), APP_NAME[app]) : fmt(_('Get %s'), APP_NAME[app]), undefined, { whole: true });
|
||||
morphInto(getBox, storeBlock(app, pf, router));
|
||||
// The router's file is the same for either app: it stays as it is (a folded configuration stays folded).
|
||||
if (!router) morphInto(addBox, connectKids(c));
|
||||
@@ -187,22 +189,22 @@ export function setupView(d: Device, cfg: ClientConfig, key: string): View {
|
||||
const linkThere = setupLink(pageUrl(), d.id);
|
||||
const linkBody = () => [
|
||||
handheld
|
||||
? codeRow(linkThere, [h('span', {}, 'Point its camera at the code: the link opens there.')]).el
|
||||
: h('p', { class: 'desc' }, `Open this link on the ${there} to set it up there.`),
|
||||
? codeRow(linkThere, [h('span', {}, _('Point its camera at the code: the link opens there.'))]).el
|
||||
: h('p', { class: 'desc' }, fmt(_('Open this link on the %s to set it up there.'), thereOn)),
|
||||
linkRow(linkThere),
|
||||
];
|
||||
const step1 = () => step('1', title1, [picker(), getBox]);
|
||||
const step2 = () => step('2', router ? 'Import the configuration' : 'Add the connection', [addBox]);
|
||||
const step2 = () => step('2', router ? _('Import the configuration') : _('Add the connection'), [addBox]);
|
||||
|
||||
const body = h('div', { class: 'setup' });
|
||||
if (inWebview(navigator.userAgent))
|
||||
body.appendChild(
|
||||
notice('warn', 'shield', null, 'Open this page in Safari or Chrome: the store opens from here, but the app handoff does not.'),
|
||||
notice('warn', 'shield', null, _('Open this page in Safari or Chrome: the store opens from here, but the app handoff does not.')),
|
||||
);
|
||||
if (layout === 'same') {
|
||||
// Opened, the way round folds the steps away: the device is not in hand.
|
||||
const steps = h('div', { class: 'steps-wrap' }, h('div', { class: 'steps-gap' }), step1(), step2());
|
||||
const round = accordion([{ icon: glass('link'), title: `Not on the ${there} right now?`, body: linkBody() }], {
|
||||
const round = accordion([{ icon: glass('link'), title: fmt(_('Not on the %s right now?'), thereOn), body: linkBody() }], {
|
||||
inset: true,
|
||||
onToggle: (_i, open, instant) => foldBlock(steps, open, instant),
|
||||
});
|
||||
@@ -213,8 +215,8 @@ export function setupView(d: Device, cfg: ClientConfig, key: string): View {
|
||||
body.appendChild(
|
||||
accordion(
|
||||
[
|
||||
{ icon: glass('link'), title: `Open your link on the ${there}`, body: linkBody() },
|
||||
{ icon: glass('app'), title: 'Already has the app', body: [picker(), codeBox] },
|
||||
{ icon: glass('link'), title: fmt(_('Open your link on the %s'), thereOn), body: linkBody() },
|
||||
{ icon: glass('app'), title: _('Already has the app'), body: [picker(), codeBox] },
|
||||
],
|
||||
{ inset: true, open: 1 },
|
||||
).el,
|
||||
@@ -224,8 +226,8 @@ export function setupView(d: Device, cfg: ClientConfig, key: string): View {
|
||||
body.appendChild(
|
||||
accordion(
|
||||
[
|
||||
{ icon: glass('link'), title: `Open your link on the ${there}`, body: linkBody() },
|
||||
{ icon: glass('key'), title: 'Copy or save the connection', body: [picker(), sendBox] },
|
||||
{ icon: glass('link'), title: fmt(_('Open your link on the %s'), thereOn), body: linkBody() },
|
||||
{ icon: glass('key'), title: _('Copy or save the connection'), body: [picker(), sendBox] },
|
||||
],
|
||||
{ inset: true, open: 0 },
|
||||
).el,
|
||||
@@ -248,7 +250,12 @@ export function setupView(d: Device, cfg: ClientConfig, key: string): View {
|
||||
onClosed(() => repaint());
|
||||
|
||||
const subline =
|
||||
layout === 'same' ? 'Two steps, about a minute' : router ? 'The packages and the file for OpenWrt' : `The app goes on the ${there}.`;
|
||||
const el = h('div', { class: 'view' }, head(`Set up ${d.name}`, { acts: !!pill }), sub(subline), way.el, body);
|
||||
return { el, label: `Set up ${d.name}`, acts: pill?.el ?? null };
|
||||
layout === 'same'
|
||||
? _('Two steps, about a minute')
|
||||
: router
|
||||
? _('The packages and the file for OpenWrt')
|
||||
: fmt(_('The app goes on the %s.'), there);
|
||||
const title = fmt(_('Set up %s'), d.name);
|
||||
const el = h('div', { class: 'view' }, head(title, { acts: !!pill }), sub(subline), way.el, body);
|
||||
return { el, label: title, acts: pill?.el ?? null };
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
// and the sheet closes by itself onto the page.
|
||||
|
||||
import type { Device } from '../../shared/types';
|
||||
import { fmt } from '../../shared/i18n';
|
||||
import { gone, call } from '../api';
|
||||
import { h, ic } from '../dom';
|
||||
import { EASE_OUT, play } from '../motion';
|
||||
@@ -20,7 +21,7 @@ export interface Way {
|
||||
}
|
||||
|
||||
export function waitWay(d: Device): Way {
|
||||
const line = h('b', {}, 'Waiting for the connection');
|
||||
const line = h('b', {}, _('Waiting for the connection'));
|
||||
const more = h('span', { class: 'ws', hidden: true });
|
||||
const el = h(
|
||||
'div',
|
||||
@@ -38,12 +39,12 @@ export function waitWay(d: Device): Way {
|
||||
el,
|
||||
connected() {
|
||||
el.classList.add('done');
|
||||
morphText(line, `${d.name} connected`);
|
||||
morphText(line, fmt(_('%s connected'), d.name));
|
||||
},
|
||||
gaveUp() {
|
||||
el.classList.add('stopped');
|
||||
morphText(line, 'No connection yet');
|
||||
more.textContent = 'Close this and open it again to keep checking.';
|
||||
morphText(line, _('No connection yet'));
|
||||
more.textContent = _('Close this and open it again to keep checking.');
|
||||
more.hidden = false;
|
||||
play(
|
||||
line.parentElement!,
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
// The portal's languages: English (the code's) and the translations bundled
|
||||
// with it (i18n/<lang>.po, turned into lookup tables at build time). The page
|
||||
// opens in the visitor's own choice, kept in this browser, or else in the
|
||||
// first of the browser's (the system's) languages it has; the language menu in
|
||||
// the breadcrumb switches it in place. This module installs the globals _()
|
||||
// and N_() that the page and the shared code call (shared/i18n.ts), so it is
|
||||
// imported before anything that draws.
|
||||
|
||||
import type { Catalog } from '../../i18n/po';
|
||||
import ru from './i18n/ru.po';
|
||||
|
||||
export interface Lang {
|
||||
code: string;
|
||||
/** In its own language: what the menu lists. */
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const LANGS: Lang[] = [
|
||||
{ code: 'en', name: 'English' },
|
||||
{ code: 'ru', name: 'Русский' },
|
||||
];
|
||||
|
||||
const catalogs: Record<string, Catalog[]> = { ru: [ru] };
|
||||
|
||||
/** Which plural form n takes (the index into the .po's msgstr[n]), by each language's gettext rule. */
|
||||
const FORMS: Record<string, (n: number) => number> = {
|
||||
en: (n) => (n !== 1 ? 1 : 0),
|
||||
ru: (n) => (n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
|
||||
};
|
||||
|
||||
const STORE = 'dl.lang';
|
||||
|
||||
/** The language to open in: the visitor's kept choice, else the browser's first we have, else English. */
|
||||
export function pickLang(kept: string | null, browser: readonly string[]): string {
|
||||
const have = (c: string | null | undefined) => (c && LANGS.some((l) => l.code === c) ? c : null);
|
||||
return have(kept) ?? browser.map((b) => have(b.toLowerCase().split(/[-_]/)[0])).find(Boolean) ?? 'en';
|
||||
}
|
||||
|
||||
let current = 'en';
|
||||
let active: Catalog[] = [];
|
||||
const listeners: (() => void)[] = [];
|
||||
|
||||
const key = (s: string, ctx?: string) => (ctx ? `${ctx}\u0004${s}` : s);
|
||||
|
||||
function tr(s: string, ctx?: string): string {
|
||||
const k = key(s, ctx);
|
||||
for (const c of active) if (k in c.s) return c.s[k];
|
||||
return s;
|
||||
}
|
||||
|
||||
function ntr(n: number, s: string, p: string, ctx?: string): string {
|
||||
const k = key(s, ctx);
|
||||
const forms = active.find((c) => k in c.p)?.p[k];
|
||||
return forms?.[(FORMS[current] ?? FORMS.en)(n)] ?? (n === 1 ? s : p);
|
||||
}
|
||||
|
||||
export const lang = () => current;
|
||||
|
||||
/**
|
||||
* A message the router sent: in English when no translation is installed on
|
||||
* it, so the page translates the ones its catalog has (the backend's
|
||||
* portal.uc and devices.uc are in it).
|
||||
*/
|
||||
export const routerText = (msg: string) => tr(msg);
|
||||
|
||||
/** Switch the page's language; `keep`: remember it in this browser (the visitor chose it). */
|
||||
export function setLang(code: string, keep = true) {
|
||||
current = LANGS.some((l) => l.code === code) ? code : 'en';
|
||||
active = catalogs[current] ?? [];
|
||||
document.documentElement.lang = current;
|
||||
if (keep)
|
||||
try {
|
||||
localStorage.setItem(STORE, current);
|
||||
} catch {
|
||||
/* no storage: the choice lasts this visit */
|
||||
}
|
||||
listeners.forEach((f) => f());
|
||||
}
|
||||
|
||||
/** Redraw on a language change (main.ts: the page; the demo: its own parts). */
|
||||
export function onLang(f: () => void) {
|
||||
listeners.push(f);
|
||||
}
|
||||
|
||||
/** More strings for a language (the demo's own, from its catalog). */
|
||||
export function addCatalog(code: string, c: Catalog) {
|
||||
(catalogs[code] ??= []).push(c);
|
||||
if (code === current) active = catalogs[code];
|
||||
}
|
||||
|
||||
function kept(): string | null {
|
||||
try {
|
||||
return localStorage.getItem(STORE);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(globalThis, { _: tr, N_: ntr });
|
||||
setLang(pickLang(kept(), navigator.languages?.length ? navigator.languages : [navigator.language]), false);
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+21
-2
@@ -6,6 +6,8 @@
|
||||
// Layout: no navbar, a breadcrumb on top. Phone: "Your access" first, devices
|
||||
// under it; desktop (≥ 960px): devices left, access right and sticky.
|
||||
|
||||
// First: the translation globals, before anything draws.
|
||||
import { onLang } from './i18n';
|
||||
import { put, h } from './dom';
|
||||
import { EASE_OUT, play, publishSprings } from './motion';
|
||||
import { gone, call } from './api';
|
||||
@@ -26,6 +28,8 @@ const app = document.getElementById('app')!;
|
||||
|
||||
let parts: { notice: HTMLElement; devices: HTMLElement; access: HTMLElement } | null = null;
|
||||
let booted = false;
|
||||
/** How the page was last drawn: what a language change draws again. */
|
||||
let redraw: () => void = () => {};
|
||||
|
||||
/** The first paint comes in: the blocks rise one after the other, the sun rises behind its line. */
|
||||
function intro() {
|
||||
@@ -65,6 +69,7 @@ function intro() {
|
||||
function render(o: RepaintOpts = {}) {
|
||||
const st = state();
|
||||
if (!st) return;
|
||||
redraw = render;
|
||||
// Paused by the admin: nothing on the page works until it is resumed, so the page is the one card that says so.
|
||||
if (st.person.state === 'paused') {
|
||||
document.title = placeName();
|
||||
@@ -101,7 +106,14 @@ function only(icon: string, title: string, text: string, gone = false, tone: Ton
|
||||
function linkGone() {
|
||||
setState(null);
|
||||
closeSheet(true);
|
||||
only('key', 'This link no longer works', 'Ask for a new one.', true);
|
||||
redraw = linkGone;
|
||||
only('key', _('This link no longer works'), _('Ask for a new one.'), true);
|
||||
}
|
||||
|
||||
/** Nothing could load: the reason as the router or the browser gave it. */
|
||||
function notLoaded(why: string) {
|
||||
redraw = () => notLoaded(why);
|
||||
only('server', _('The page could not load'), why);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,10 +142,17 @@ async function refresh() {
|
||||
} catch (e) {
|
||||
if (gone(e)) linkGone();
|
||||
// A network hiccup: keep showing the last state (the page loads fresh data on reload).
|
||||
else if (!state()) only('server', 'The page could not load', (e as Error).message);
|
||||
else if (!state()) notLoaded((e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
// Another language: everything is drawn again in it, the sections too (their headings are text).
|
||||
onLang(() => {
|
||||
closeMenu(true);
|
||||
parts = null;
|
||||
redraw();
|
||||
});
|
||||
|
||||
// What the keyboard does never animates.
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key !== 'Escape') return;
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
// calendar of the weeks, with the admin's hours as a bar of the day.
|
||||
|
||||
import type { Person } from '../../shared/types';
|
||||
import { ACCESS_LABEL, byDeviceState, bytes, date, daysLeft, endsSoon, parseDay } from '../../shared/format';
|
||||
import { accessLabel, byDeviceState, bytes, date, daysLeft, endsSoon, parseDay } from '../../shared/format';
|
||||
import { fill, fmt, locale, num, plural } from '../../shared/i18n';
|
||||
import { h, ic, markup } from '../dom';
|
||||
import { calendar, clockOf, hoursFor, minuteAt, monthOf, stretches } from '../days';
|
||||
import { now, today, type State } from '../state';
|
||||
@@ -18,6 +19,8 @@ import { reachableFromHome } from './devices';
|
||||
const desc = (text: string) => h('p', { class: 'desc' }, text);
|
||||
/** A share of a length, as a CSS percentage. */
|
||||
const pc = (part: number, whole: number) => `${((part / whole) * 100).toFixed(2)}%`;
|
||||
/** A router day (YYYY-MM-DD) as "13 Oct", without the year. */
|
||||
const dayMonth = (d: string) => parseDay(d).toLocaleDateString(locale(), { day: 'numeric', month: 'short' });
|
||||
|
||||
/** What the access reaches, as two tiles: the home network and the internet, each in or out. */
|
||||
function reachTiles(access: Person['access']): HTMLElement {
|
||||
@@ -27,14 +30,14 @@ function reachTiles(access: Person['access']): HTMLElement {
|
||||
{ class: `reach-tile${on ? '' : ' off'}` },
|
||||
glass(icon, on ? 'blue' : 'grey', 'gi rt-ic'),
|
||||
h('b', {}, name),
|
||||
h('span', { class: 'rt-sub' }, on ? sub : 'Not included'),
|
||||
h('span', { class: 'rt-mark', 'aria-label': on ? 'Included' : 'Not included' }, ic(on ? 'check' : 'minus')),
|
||||
h('span', { class: 'rt-sub' }, on ? sub : _('Not included')),
|
||||
h('span', { class: 'rt-mark', 'aria-label': on ? _('Included') : _('Not included') }, ic(on ? 'check' : 'minus')),
|
||||
);
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'reach2' },
|
||||
tile(access !== 'internet', 'home', 'Home network', 'Devices at home'),
|
||||
tile(access !== 'lan', 'globe', 'Internet', 'Through the router'),
|
||||
tile(access !== 'internet', 'home', _('Home network'), _('Devices at home')),
|
||||
tile(access !== 'lan', 'globe', _('Internet'), _('Through the router')),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,12 +48,12 @@ function namesAtHome(p: Person, mesh: boolean): Node[] {
|
||||
const first = named[0].hostname;
|
||||
const dot0 = first.indexOf('.');
|
||||
const domain = dot0 > 0 ? first.slice(dot0) : '';
|
||||
const pattern = h('span', { class: 'mono' }, `${_('name')}${domain}`);
|
||||
return [
|
||||
h(
|
||||
'span',
|
||||
{ class: 'lbl-s' },
|
||||
mesh ? 'Devices at home and on this VPN reach yours as ' : 'Other devices at home reach yours as ',
|
||||
h('span', { class: 'mono' }, `name${domain}`),
|
||||
...fill(mesh ? _('Devices at home and on this VPN reach yours as %s') : _('Other devices at home reach yours as %s'), pattern),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
@@ -63,8 +66,8 @@ function namesAtHome(p: Person, mesh: boolean): Node[] {
|
||||
type: 'button',
|
||||
class: 'namechip',
|
||||
title: d.name,
|
||||
'aria-label': `Copy ${d.hostname}`,
|
||||
onclick: (ev: Event) => copy(d.hostname, 'Address copied', ev.currentTarget),
|
||||
'aria-label': fmt(_('Copy %s'), d.hostname),
|
||||
onclick: (ev: Event) => copy(d.hostname, _('Address copied'), ev.currentTarget),
|
||||
},
|
||||
h('span', {}, dot > 0 ? [d.hostname.slice(0, dot), h('span', { class: 'faint' }, d.hostname.slice(dot))] : d.hostname),
|
||||
ic('copy'),
|
||||
@@ -95,12 +98,16 @@ function month(p: Person, used: number, pct: number): HTMLElement {
|
||||
const { days, day } = monthOf(today());
|
||||
const series = p.month_days ?? [];
|
||||
const max = Math.max(1, ...series);
|
||||
const short = (d: number) =>
|
||||
parseDay(`${today().slice(0, 8)}${String(d).padStart(2, '0')}`).toLocaleDateString('en-GB', { day: 'numeric', month: 'short' });
|
||||
const short = (d: number) => dayMonth(`${today().slice(0, 8)}${String(d).padStart(2, '0')}`);
|
||||
// The total, and a bar under the pointer in its place, at once: no morph while the pointer moves.
|
||||
const total = h('b', { class: 'num', 'data-t': 'm-used' }, bytes(used));
|
||||
const tail = h('span', {}, ' used');
|
||||
const read = h('span', { class: 'mread' }, total, tail);
|
||||
const read = h('span', { class: 'mread' });
|
||||
/** The month's total, or (`d`) one day's: the number in its sentence. */
|
||||
const say = (v: number, d?: number) => {
|
||||
setText(total, bytes(v));
|
||||
read.replaceChildren(...(d ? fill<Node | string>(_('%s on %s'), total, short(d)) : fill(_('%s used'), total)));
|
||||
};
|
||||
say(used);
|
||||
const bars = h('div', { class: 'mbars' });
|
||||
for (let i = 0; i < days; i++) {
|
||||
if (i >= day) {
|
||||
@@ -110,18 +117,12 @@ function month(p: Person, used: number, pct: number): HTMLElement {
|
||||
const v = series[i] ?? 0;
|
||||
const b = h('i', { class: i === day - 1 ? 'today' : '' });
|
||||
b.style.height = `${Math.max(3, Math.round((v / max) * 64))}px`;
|
||||
b.addEventListener('pointerenter', () => {
|
||||
setText(total, bytes(v));
|
||||
setText(tail, ` on ${short(i + 1)}`);
|
||||
});
|
||||
b.addEventListener('pointerleave', () => {
|
||||
setText(total, bytes(used));
|
||||
setText(tail, ' used');
|
||||
});
|
||||
b.addEventListener('pointerenter', () => say(v, i + 1));
|
||||
b.addEventListener('pointerleave', () => say(used));
|
||||
bars.appendChild(b);
|
||||
}
|
||||
// "Today" under its bar; the month's ends step aside when it comes close.
|
||||
const td = h('span', { class: 'td' }, 'Today');
|
||||
const td = h('span', { class: 'td' }, _('Today'));
|
||||
td.style.left = pc(day - 0.5, days);
|
||||
const axis = h(
|
||||
'div',
|
||||
@@ -142,7 +143,7 @@ function month(p: Person, used: number, pct: number): HTMLElement {
|
||||
h(
|
||||
'span',
|
||||
{ class: `num${p.state === 'quota' ? ' bad-t' : ''}`, 'data-t': 'm-left' },
|
||||
p.quota_limit ? `${bytes(Math.max(0, p.quota_limit - used))} left` : 'No limit',
|
||||
p.quota_limit ? fmt(_('%s left'), bytes(Math.max(0, p.quota_limit - used))) : _('No limit'),
|
||||
),
|
||||
),
|
||||
p.quota_limit ? meter(pct) : null,
|
||||
@@ -151,7 +152,9 @@ function month(p: Person, used: number, pct: number): HTMLElement {
|
||||
|
||||
/** The days left as a number over a calendar of the weeks to the end (the last day ringed). */
|
||||
function untilCal(p: Person, left: number): HTMLElement {
|
||||
const day = (d: string) => parseDay(d).toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short' });
|
||||
const day = (d: string) => parseDay(d).toLocaleDateString(locale(), { weekday: 'short', day: 'numeric', month: 'short' });
|
||||
// The weekdays' initials, Monday first (1 Jan 2024 was a Monday).
|
||||
const weekdays = Array.from({ length: 7 }, (_x, i) => new Date(2024, 0, 1 + i, 12).toLocaleDateString(locale(), { weekday: 'narrow' }));
|
||||
const cells = calendar(today(), p.expires);
|
||||
const cal = cells
|
||||
? h(
|
||||
@@ -160,7 +163,7 @@ function untilCal(p: Person, left: number): HTMLElement {
|
||||
h(
|
||||
'div',
|
||||
{ class: 'cal-h' },
|
||||
['M', 'T', 'W', 'T', 'F', 'S', 'S'].map((x) => h('span', {}, x)),
|
||||
weekdays.map((x) => h('span', {}, x)),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
@@ -179,9 +182,9 @@ function untilCal(p: Person, left: number): HTMLElement {
|
||||
h(
|
||||
'div',
|
||||
{ class: 'until-num' },
|
||||
h('b', { class: 'num' }, String(left)),
|
||||
h('span', {}, `${left === 1 ? 'day' : 'days'} left`),
|
||||
h('span', { class: 'until-sub' }, `Ends ${day(p.expires)}`),
|
||||
h('b', { class: 'num' }, num(left)),
|
||||
h('span', {}, N_(left, 'day left', 'days left')),
|
||||
h('span', { class: 'until-sub' }, fmt(_('Ends %s'), day(p.expires))),
|
||||
),
|
||||
cal,
|
||||
);
|
||||
@@ -203,7 +206,7 @@ function hoursBar(hours: string, tzOffset: number | undefined): HTMLElement | nu
|
||||
i.style.width = pc(b - a, 1440);
|
||||
bar.appendChild(i);
|
||||
}
|
||||
const mark = h('span', { class: `hours-now${inside ? '' : ' out'}`, title: `Now, ${clockOf(at)}` });
|
||||
const mark = h('span', { class: `hours-now${inside ? '' : ' out'}`, title: fmt(_('Now, %s'), clockOf(at)) });
|
||||
mark.style.left = pc(at, 1440);
|
||||
bar.appendChild(mark);
|
||||
return h(
|
||||
@@ -212,7 +215,7 @@ function hoursBar(hours: string, tzOffset: number | undefined): HTMLElement | nu
|
||||
h(
|
||||
'div',
|
||||
{ class: 'hours-top' },
|
||||
h('span', {}, hw.yours ? 'Hours, your time' : 'Hours, router time'),
|
||||
h('span', {}, hw.yours ? _('Hours, your time') : _('Hours, router time')),
|
||||
h('b', { class: 'num' }, `${clockOf(hw.from)}–${clockOf(hw.to)}`),
|
||||
),
|
||||
bar,
|
||||
@@ -236,30 +239,30 @@ export function accessAccordion(st: State, open = 1): Accordion {
|
||||
? h(
|
||||
'span',
|
||||
{ class: 'until-val' },
|
||||
h('span', { class: 'num', 'data-t': 'until-date' }, date(p.expires).replace(/ \d{4}$/, '')),
|
||||
h('span', { class: 'num', 'data-t': 'until-date' }, dayMonth(p.expires)),
|
||||
left != null
|
||||
? h(
|
||||
'span',
|
||||
{ class: `num ${left < 0 ? 'bad-t' : endsSoon(p, left) ? 'warn-t' : 'ok-t'}`, 'data-t': 'until-left' },
|
||||
left >= 0 ? `${left} day${left === 1 ? '' : 's'}` : 'ended',
|
||||
left >= 0 ? plural(left, '%s day', '%s days') : _('ended'),
|
||||
)
|
||||
: null,
|
||||
)
|
||||
: h('span', {}, 'No end date');
|
||||
: h('span', {}, _('No end date'));
|
||||
const untilBody = [
|
||||
!p.expires ? null : left != null && left < 0 ? desc(`It ended on ${date(p.expires)}.`) : untilCal(p, left ?? 0),
|
||||
!p.expires ? null : left != null && left < 0 ? desc(fmt(_('It ended on %s.'), date(p.expires))) : untilCal(p, left ?? 0),
|
||||
p.hours ? hoursBar(p.hours, st.tz_offset) : null,
|
||||
];
|
||||
return accordion(
|
||||
[
|
||||
{
|
||||
icon: glass(p.access === 'internet' ? 'globe' : p.access === 'lan' ? 'home' : 'shield'),
|
||||
title: ACCESS_LABEL[p.access],
|
||||
title: accessLabel(p.access),
|
||||
body: [reachTiles(p.access), ...namesAtHome(p, !!st.server.device_mesh)],
|
||||
},
|
||||
{
|
||||
icon: glass('chart'),
|
||||
title: total ? 'Data used' : 'Data this month',
|
||||
title: total ? _('Data used') : _('Data this month'),
|
||||
val: h(
|
||||
'span',
|
||||
{ class: 'data-val' },
|
||||
@@ -267,23 +270,23 @@ export function accessAccordion(st: State, open = 1): Accordion {
|
||||
h(
|
||||
'span',
|
||||
{ class: 'num', 'data-t': 'data-val' },
|
||||
`${bytes(used)}${p.quota_limit ? ` / ${bytes(p.quota_limit)}` : ' · no limit'}`,
|
||||
`${bytes(used)} ${p.quota_limit ? `/ ${bytes(p.quota_limit)}` : `· ${_('no limit')}`}`,
|
||||
),
|
||||
),
|
||||
valHide: true,
|
||||
body: [
|
||||
total ? desc(`${bytes(used)} of ${bytes(p.quota_limit)} in total.`) : month(p, used, pct),
|
||||
total ? desc(fmt(_('%s of %s in total.'), bytes(used), bytes(p.quota_limit))) : month(p, used, pct),
|
||||
desc(
|
||||
!p.quota_limit
|
||||
? 'No data limit. The count starts again on the 1st.'
|
||||
? _('No data limit. The count starts again on the 1st.')
|
||||
: total
|
||||
? 'A total for your whole access, it does not reset.'
|
||||
: 'Resets on the 1st.',
|
||||
? _('A total for your whole access, it does not reset.')
|
||||
: _('Resets on the 1st.'),
|
||||
),
|
||||
],
|
||||
},
|
||||
// No end date and no hours: nothing to open, the row just says so.
|
||||
{ icon: glass('calendar'), title: 'Access until', val: untilVal, valHide: !!p.expires && (left ?? 0) >= 0, body: untilBody },
|
||||
{ icon: glass('calendar'), title: _('Access until'), val: untilVal, valHide: !!p.expires && (left ?? 0) >= 0, body: untilBody },
|
||||
],
|
||||
{ open },
|
||||
);
|
||||
@@ -293,8 +296,8 @@ export function accessAccordion(st: State, open = 1): Accordion {
|
||||
export function accessSection(): HTMLElement {
|
||||
return h(
|
||||
'section',
|
||||
{ class: 'access', id: 'access', 'aria-label': 'Your access' },
|
||||
h('div', { class: 'sec-head' }, h('h2', {}, 'Your access')),
|
||||
{ class: 'access', id: 'access', 'aria-label': _('Your access') },
|
||||
h('div', { class: 'sec-head' }, h('h2', {}, _('Your access'))),
|
||||
h('div', { class: 'acc-slot' }),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import type { Device, Person } from '../../shared/types';
|
||||
import { addDays, ago, byDeviceState, bytes, parseDay } from '../../shared/format';
|
||||
import { fmt, locale, num, plural } from '../../shared/i18n';
|
||||
import { h, ic } from '../dom';
|
||||
import { BOUNCY, EASE_IN, EASE_OUT, SMOOTH, play } from '../motion';
|
||||
import { now, today, type RepaintOpts, type State } from '../state';
|
||||
@@ -22,16 +23,16 @@ export const reachableFromHome = (p: Person, d: Device) => p.access !== 'interne
|
||||
|
||||
/** The status line: its class and words (short, on one line; the full wording shows on hover). */
|
||||
function statusOf(d: Device, p: Person): [string, string] {
|
||||
if (d.disabled) return ['', 'Disabled'];
|
||||
if (d.disabled) return ['', _('Disabled')];
|
||||
// The Update pill beside it says what to do.
|
||||
if (d.config_stale && d.handshake) return ['warn-t', 'Settings changed'];
|
||||
if (d.config_stale && d.handshake) return ['warn-t', _('Settings changed')];
|
||||
// Over the data limit or outside the hours the tunnel stays up but passes nothing: the app says
|
||||
// "connected", so say here why nothing works.
|
||||
if (d.online && p.state === 'quota') return ['warn-t', 'Connected, no data left'];
|
||||
if (d.online && p.state === 'hours') return ['warn-t', 'Connected, outside your hours'];
|
||||
if (d.online) return ['ok-t', 'Connected'];
|
||||
if (!d.handshake) return ['warn-t', 'Not set up yet'];
|
||||
return ['', `Last connected ${ago(d.handshake, now())}`];
|
||||
if (d.online && p.state === 'quota') return ['warn-t', _('Connected, no data left')];
|
||||
if (d.online && p.state === 'hours') return ['warn-t', _('Connected, outside your hours')];
|
||||
if (d.online) return ['ok-t', _('Connected')];
|
||||
if (!d.handshake) return ['warn-t', _('Not set up yet')];
|
||||
return ['', fmt(_('Last connected %s'), ago(d.handshake, now()))];
|
||||
}
|
||||
|
||||
function menuItems(d: Device, st: State): (MenuItem | null)[] {
|
||||
@@ -39,8 +40,8 @@ function menuItems(d: Device, st: State): (MenuItem | null)[] {
|
||||
// How devices at home reach it: only where the router actually lets them through.
|
||||
...(reachableFromHome(st.person, d)
|
||||
? [
|
||||
{ label: 'Copy IP address', icon: 'copy', run: () => copy(d.address, 'IP address copied') },
|
||||
...(d.hostname ? [{ label: 'Copy local address', icon: 'home', run: () => copy(d.hostname, 'Address copied') }] : []),
|
||||
{ label: _('Copy IP address'), icon: 'copy', run: () => copy(d.address, _('IP address copied')) },
|
||||
...(d.hostname ? [{ label: _('Copy local address'), icon: 'home', run: () => copy(d.hostname, _('Address copied')) }] : []),
|
||||
null,
|
||||
]
|
||||
: []),
|
||||
@@ -48,24 +49,24 @@ function menuItems(d: Device, st: State): (MenuItem | null)[] {
|
||||
...(d.disabled
|
||||
? []
|
||||
: [
|
||||
{ label: 'Rename', icon: 'edit', run: () => rename(d) },
|
||||
{ label: 'Reconnect', icon: 'refresh', tone: 'warn' as const, run: () => reconnect(d) },
|
||||
{ label: 'Remove', icon: 'trash', tone: 'bad' as const, run: () => removeDevice(d) },
|
||||
{ label: _('Rename'), icon: 'edit', run: () => rename(d) },
|
||||
{ label: _('Reconnect'), icon: 'refresh', tone: 'warn' as const, run: () => reconnect(d) },
|
||||
{ label: _('Remove'), icon: 'trash', tone: 'bad' as const, run: () => removeDevice(d) },
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
/** "Today", "Yesterday", "Tue 13 Oct": a spark bar's day, on the router's calendar. */
|
||||
function dayName(back: number): string {
|
||||
if (back === 0) return 'Today';
|
||||
if (back === 1) return 'Yesterday';
|
||||
return parseDay(addDays(today(), -back)).toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short' });
|
||||
if (back === 0) return _('Today');
|
||||
if (back === 1) return _('Yesterday');
|
||||
return parseDay(addDays(today(), -back)).toLocaleDateString(locale(), { weekday: 'short', day: 'numeric', month: 'short' });
|
||||
}
|
||||
|
||||
/** Last 7 days as a number and bars; a bar under the pointer puts its own day in the number's place. */
|
||||
function usage(d: Device, stale: boolean): HTMLElement {
|
||||
const week = d.spark.reduce((a, b) => a + b, 0);
|
||||
const lbl = h('span', { class: 'use-lbl' }, 'Last 7 days');
|
||||
const lbl = h('span', { class: 'use-lbl' }, _('Last 7 days'));
|
||||
const val = h('span', { class: 'use-val num', 'data-t': `${d.id}:use` }, bytes(week));
|
||||
let side: HTMLElement;
|
||||
if (stale)
|
||||
@@ -74,12 +75,12 @@ function usage(d: Device, stale: boolean): HTMLElement {
|
||||
{
|
||||
type: 'button',
|
||||
class: 'upd-pill',
|
||||
'aria-label': 'Update the connection',
|
||||
title: 'Its settings changed: update the connection',
|
||||
'aria-label': _('Update the connection'),
|
||||
title: _('Its settings changed: update the connection'),
|
||||
onclick: () => reconnect(d),
|
||||
},
|
||||
ic('refresh'),
|
||||
h('span', {}, 'Update'),
|
||||
h('span', {}, _('Update')),
|
||||
);
|
||||
else {
|
||||
const max = Math.max(1, ...d.spark);
|
||||
@@ -94,7 +95,7 @@ function usage(d: Device, stale: boolean): HTMLElement {
|
||||
setText(val, bytes(v));
|
||||
});
|
||||
b.addEventListener('pointerleave', () => {
|
||||
setText(lbl, 'Last 7 days');
|
||||
setText(lbl, _('Last 7 days'));
|
||||
setText(val, bytes(week));
|
||||
});
|
||||
side.appendChild(b);
|
||||
@@ -108,15 +109,15 @@ function card(d: Device, st: State): HTMLElement {
|
||||
const locked = !!st.locked;
|
||||
// The device this page was opened from (through the tunnel): it is connected, so say which one it is instead.
|
||||
const here = st.here === d.id;
|
||||
const [cls, words] = here ? ['here-t', 'This device'] : statusOf(d, p);
|
||||
const [cls, words] = here ? ['here-t', _('This device')] : statusOf(d, p);
|
||||
const setUp = !d.handshake && !d.disabled;
|
||||
const stale = d.config_stale && !setUp && !locked && !d.disabled;
|
||||
// On one line; the exact time, or the whole wording, on hover.
|
||||
const title =
|
||||
!here && d.handshake && !d.online && !d.disabled && !d.config_stale
|
||||
? new Date(d.handshake * 1000).toLocaleString('en-GB')
|
||||
? new Date(d.handshake * 1000).toLocaleString(locale())
|
||||
: stale
|
||||
? 'Settings changed, update needed'
|
||||
? _('Settings changed, update needed')
|
||||
: words;
|
||||
const items = menuItems(d, st);
|
||||
const more =
|
||||
@@ -124,7 +125,13 @@ function card(d: Device, st: State): HTMLElement {
|
||||
? null
|
||||
: h(
|
||||
'button',
|
||||
{ type: 'button', class: 'knob more', 'aria-label': `${d.name} options`, 'aria-haspopup': 'menu', 'aria-expanded': 'false' },
|
||||
{
|
||||
type: 'button',
|
||||
class: 'knob more',
|
||||
'aria-label': fmt(_('%s options'), d.name),
|
||||
'aria-haspopup': 'menu',
|
||||
'aria-expanded': 'false',
|
||||
},
|
||||
ic('more'),
|
||||
);
|
||||
more?.addEventListener('click', () => openMenu(more, items));
|
||||
@@ -152,11 +159,11 @@ function card(d: Device, st: State): HTMLElement {
|
||||
{
|
||||
type: 'button',
|
||||
class: 'btn tint block setup-btn',
|
||||
'aria-label': `Set up ${d.name}`,
|
||||
'aria-label': fmt(_('Set up %s'), d.name),
|
||||
onclick: (ev: Event) => openSetup(d, ev.currentTarget),
|
||||
},
|
||||
ic('qr'),
|
||||
h('span', {}, 'Connect'),
|
||||
h('span', {}, _('Connect')),
|
||||
)
|
||||
: usage(d, stale),
|
||||
);
|
||||
@@ -168,25 +175,25 @@ const firstCard = (mobile: boolean) =>
|
||||
'div',
|
||||
{ class: 'dev first', 'data-id': 'first' },
|
||||
glass('plus', 'blue'),
|
||||
h('b', {}, 'Add your first device'),
|
||||
h('p', {}, 'Two steps, about a minute: get the app, then add the connection.'),
|
||||
h('b', {}, _('Add your first device')),
|
||||
h('p', {}, _('Two steps, about a minute: get the app, then add the connection.')),
|
||||
h(
|
||||
'button',
|
||||
{ type: 'button', class: 'btn accent block', onclick: startAdd },
|
||||
ic('plus'),
|
||||
h('span', {}, mobile ? 'Add this phone' : 'Add this device'),
|
||||
h('span', {}, mobile ? _('Add this phone') : _('Add this device')),
|
||||
),
|
||||
);
|
||||
|
||||
const addCard = () =>
|
||||
h('button', { type: 'button', class: 'dev add', 'data-id': 'add', onclick: startAdd }, glass('plus'), h('span', {}, 'Add device'));
|
||||
h('button', { type: 'button', class: 'dev add', 'data-id': 'add', onclick: startAdd }, glass('plus'), h('span', {}, _('Add device')));
|
||||
|
||||
/** The section, built once; `fill` puts the cards in. */
|
||||
export function devicesSection(): HTMLElement {
|
||||
return h(
|
||||
'section',
|
||||
{ class: 'devices', id: 'devices', 'aria-label': 'Your devices' },
|
||||
h('div', { class: 'sec-head' }, h('h2', {}, 'Your devices'), h('span', { class: 'aside num' })),
|
||||
{ class: 'devices', id: 'devices', 'aria-label': _('Your devices') },
|
||||
h('div', { class: 'sec-head' }, h('h2', {}, _('Your devices')), h('span', { class: 'aside num' })),
|
||||
h('div', { class: 'dgrid' }),
|
||||
h('p', { class: 'note-s limit', hidden: true }),
|
||||
);
|
||||
@@ -254,7 +261,7 @@ export function fillDevices(section: HTMLElement, st: State, o: RepaintOpts = {}
|
||||
}
|
||||
if (repainting) morphChanged(grid, said);
|
||||
const count = section.querySelector('.sec-head .aside') as HTMLElement;
|
||||
const n = `${p.devices.length} of ${p.device_limit}`;
|
||||
const n = fmt(_('%s of %s'), num(p.devices.length), num(p.device_limit));
|
||||
if (repainting) morphText(count, n);
|
||||
else count.textContent = n;
|
||||
// The admin may add devices past the limit.
|
||||
@@ -262,7 +269,11 @@ export function fillDevices(section: HTMLElement, st: State, o: RepaintOpts = {}
|
||||
const limit = section.querySelector('.limit') as HTMLElement;
|
||||
const was = limit.hidden;
|
||||
const hide = st.can_add || !!st.locked;
|
||||
limit.textContent = `You have reached your limit of ${p.device_limit} devices. Remove one to add another.`;
|
||||
limit.textContent = plural(
|
||||
p.device_limit,
|
||||
'You have reached your limit of %s device. Remove one to add another.',
|
||||
'You have reached your limit of %s devices. Remove one to add another.',
|
||||
);
|
||||
limit.getAnimations().forEach((a) => a.cancel());
|
||||
// A slot freed: the note fades the way it came, then leaves the layout.
|
||||
if (repainting && !was && hide) {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// The page's frame: no navbar. The page fades out under the screen's top and
|
||||
// bottom edges (the top fade only once it scrolls, so the breadcrumb at rest
|
||||
// stays crisp), and opens with a breadcrumb: the Dawnline mark, the place (the
|
||||
// server's name) and the person. The content goes in `body`.
|
||||
// server's name) and the person, then the language and this page's code. The
|
||||
// content goes in `body`.
|
||||
|
||||
import { h, ic, markup } from '../dom';
|
||||
import { placeName, state } from '../state';
|
||||
import { showPageCode } from '../flows/page-code';
|
||||
import { openMenu } from '../ui/menu';
|
||||
import { LANGS, lang, setLang } from '../i18n';
|
||||
|
||||
// The sun rises from behind the horizon once, on the visit's first paint.
|
||||
const LOGO =
|
||||
@@ -37,10 +40,28 @@ export function single(on: boolean) {
|
||||
pageEl?.classList.toggle('single', on);
|
||||
}
|
||||
|
||||
/** The language: its code and a chevron; the menu lists the languages by their own names. */
|
||||
function langPicker(): HTMLElement {
|
||||
const b = h(
|
||||
'button',
|
||||
{ type: 'button', class: 'cr-lang', 'aria-label': _('Language'), 'aria-haspopup': 'menu', 'aria-expanded': 'false' },
|
||||
h('span', {}, lang().toUpperCase()),
|
||||
ic('chevron', 'i cr-down'),
|
||||
);
|
||||
b.addEventListener('click', () =>
|
||||
openMenu(
|
||||
b,
|
||||
LANGS.map((l) => ({ label: l.name, checked: l.code === lang(), run: () => l.code !== lang() && setLang(l.code) })),
|
||||
),
|
||||
);
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* The breadcrumb: the place, then the person (none when the link stopped
|
||||
* working); at its end, this page's code for another device, on the page
|
||||
* itself only (not over a card: paused, link gone, nothing loaded).
|
||||
* working); at its end, the language and this page's code for another
|
||||
* device, on the page itself only (not over a card: paused, link gone,
|
||||
* nothing loaded).
|
||||
*/
|
||||
export function crumbs(gone = false, card = false) {
|
||||
if (!crumbsEl) return;
|
||||
@@ -50,12 +71,13 @@ export function crumbs(gone = false, card = false) {
|
||||
h('span', { class: 'cr-mark' }, markup(LOGO)),
|
||||
h(
|
||||
'nav',
|
||||
{ class: 'cr-path', 'aria-label': 'Breadcrumb' },
|
||||
{ class: 'cr-path', 'aria-label': _('Breadcrumb') },
|
||||
place,
|
||||
p ? [ic('chevron'), h('span', { class: 'cur', 'aria-current': 'page' }, p.name)] : null,
|
||||
),
|
||||
...(card ? [] : [langPicker()]),
|
||||
...(p && !card
|
||||
? [h('button', { type: 'button', class: 'knob cr-qr', 'aria-label': 'Open on another device', onclick: showPageCode }, ic('qr'))]
|
||||
? [h('button', { type: 'button', class: 'knob cr-qr', 'aria-label': _('Open on another device'), onclick: showPageCode }, ic('qr'))]
|
||||
: []),
|
||||
);
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import type { Person } from '../../shared/types';
|
||||
import { daysLeft, date, endsIn, endsSoon } from '../../shared/format';
|
||||
import { fmt } from '../../shared/i18n';
|
||||
import { h } from '../dom';
|
||||
import { clockOf, hoursFor } from '../days';
|
||||
import { state, today } from '../state';
|
||||
@@ -23,25 +24,26 @@ export function notice(tone: Tone, icon: string, title: string | null, sub: stri
|
||||
/** The admin's hours as the visitor reads them: "08:00–22:00 your time" (or the router's, said so). */
|
||||
export function hoursText(hours: string): string {
|
||||
const hw = hoursFor(hours, state()?.tz_offset, -new Date().getTimezoneOffset());
|
||||
if (!hw) return `${hours.replace('-', '–')} (router time)`;
|
||||
return `${clockOf(hw.from)}–${clockOf(hw.to)} ${hw.yours ? 'your time' : '(router time)'}`;
|
||||
if (!hw) return fmt(_('%s (router time)'), hours.replace('-', '–'));
|
||||
const span = `${clockOf(hw.from)}–${clockOf(hw.to)}`;
|
||||
return fmt(hw.yours ? _('%s your time') : _('%s (router time)'), span);
|
||||
}
|
||||
|
||||
/** Why the person's devices can't connect: icon, a short title, and a line that adds to it (never says it again). */
|
||||
export function stateNotice(p: Person): [string, string, string] {
|
||||
switch (p.state) {
|
||||
case 'server_off':
|
||||
return ['server', 'Server is disabled', 'Your devices can’t connect until it’s enabled again.'];
|
||||
return ['server', _('Server is disabled'), _('Your devices can’t connect until it’s enabled again.')];
|
||||
case 'no_server':
|
||||
return ['server', 'No server yet', 'You haven’t been added to one.'];
|
||||
return ['server', _('No server yet'), _('You haven’t been added to one.')];
|
||||
case 'quota':
|
||||
return ['chart', 'Out of data', 'Nothing gets through until it resets.'];
|
||||
return ['chart', _('Out of data'), _('Nothing gets through until it resets.')];
|
||||
case 'expired':
|
||||
return ['calendar', 'Access ended', 'Your devices can’t connect until it’s extended.'];
|
||||
return ['calendar', _('Access ended'), _('Your devices can’t connect until it’s extended.')];
|
||||
case 'hours':
|
||||
return ['clock', 'Outside your hours', `Open ${hoursText(p.hours)}.`];
|
||||
return ['clock', _('Outside your hours'), fmt(_('Open %s.'), hoursText(p.hours))];
|
||||
default:
|
||||
return ['pause', 'Access paused', 'Your devices can’t connect until it’s resumed.'];
|
||||
return ['pause', _('Access paused'), _('Your devices can’t connect until it’s resumed.')];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,5 +51,7 @@ export function stateNotice(p: Person): [string, string, string] {
|
||||
export function pageNotice(p: Person): HTMLElement | null {
|
||||
if (p.state !== 'active') return notice(p.state === 'quota' || p.state === 'expired' ? 'bad' : 'warn', ...stateNotice(p));
|
||||
const left = daysLeft(p.expires, today());
|
||||
return endsSoon(p, left) ? notice('warn', 'calendar', `Access ${endsIn(left as number)}`, `On ${date(p.expires)}.`) : null;
|
||||
return endsSoon(p, left)
|
||||
? notice('warn', 'calendar', fmt(_('Access %s'), endsIn(left as number)), fmt(_('On %s.'), date(p.expires)))
|
||||
: null;
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
// A .po catalog imported by the portal is its lookup table, made at build time
|
||||
// (tsup.config.ts and vitest.config.ts read it with i18n/po.ts).
|
||||
declare module '*.po' {
|
||||
const catalog: import('../../i18n/po').Catalog;
|
||||
export default catalog;
|
||||
}
|
||||
+79
-54
@@ -2,6 +2,7 @@
|
||||
// is open on the device being set up. Pure: the set-up sheet (flows/) draws it.
|
||||
|
||||
import type { Kind } from '../shared/types';
|
||||
import { fmt } from '../shared/i18n';
|
||||
|
||||
export type Platform = 'ios' | 'android' | 'windows' | 'mac' | 'linux' | 'unknown';
|
||||
export type AppId = 'vpn' | 'awg' | 'wg';
|
||||
@@ -61,64 +62,67 @@ export interface Store {
|
||||
}
|
||||
|
||||
const GH_CLIENT = 'https://github.com/amnezia-vpn/amnezia-client/releases/latest';
|
||||
const APK: NonNullable<Store['alt']> = {
|
||||
href: GH_CLIENT,
|
||||
top: 'APK file on',
|
||||
const apk = (href: string): NonNullable<Store['alt']> => ({
|
||||
href,
|
||||
top: _('APK file on'),
|
||||
main: 'GitHub',
|
||||
mark: 'github',
|
||||
why: 'The APK is for phones without Google Play, or where the store hides the app.',
|
||||
};
|
||||
why: _('The APK is for phones without Google Play, or where the store hides the app.'),
|
||||
});
|
||||
|
||||
/** Where the app comes from on a platform: the store first, the official GitHub release where no store has it. */
|
||||
export function storeFor(app: AppId, platform: Platform): Store | null {
|
||||
const onAppStore = _('Download on the');
|
||||
const onPlay = _('Get it on');
|
||||
const onGitHub = _('Official release on GitHub');
|
||||
const S: Record<AppId, Partial<Record<Platform, Store>>> = {
|
||||
vpn: {
|
||||
ios: { href: 'https://apps.apple.com/app/amneziavpn/id1600529900', top: 'Download on the', main: 'App Store', mark: 'appstore' },
|
||||
ios: { href: 'https://apps.apple.com/app/amneziavpn/id1600529900', top: onAppStore, main: 'App Store', mark: 'appstore' },
|
||||
android: {
|
||||
href: 'https://play.google.com/store/apps/details?id=org.amnezia.vpn',
|
||||
top: 'Get it on',
|
||||
top: onPlay,
|
||||
main: 'Google Play',
|
||||
mark: 'googleplay',
|
||||
alt: APK,
|
||||
alt: apk(GH_CLIENT),
|
||||
},
|
||||
windows: { href: GH_CLIENT, top: 'Official release on GitHub', main: 'Download for Windows', mark: 'windows' },
|
||||
mac: { href: GH_CLIENT, top: 'Official release on GitHub', main: 'Download for Mac', mark: 'apple' },
|
||||
linux: { href: GH_CLIENT, top: 'Official release on GitHub', main: 'Download for Linux', mark: 'linux' },
|
||||
windows: { href: GH_CLIENT, top: onGitHub, main: _('Download for Windows'), mark: 'windows' },
|
||||
mac: { href: GH_CLIENT, top: onGitHub, main: _('Download for Mac'), mark: 'apple' },
|
||||
linux: { href: GH_CLIENT, top: onGitHub, main: _('Download for Linux'), mark: 'linux' },
|
||||
},
|
||||
awg: {
|
||||
ios: { href: 'https://apps.apple.com/us/app/amneziawg/id6478942365', top: 'Download on the', main: 'App Store', mark: 'appstore' },
|
||||
ios: { href: 'https://apps.apple.com/us/app/amneziawg/id6478942365', top: onAppStore, main: 'App Store', mark: 'appstore' },
|
||||
android: {
|
||||
href: 'https://play.google.com/store/apps/details?id=org.amnezia.awg',
|
||||
top: 'Get it on',
|
||||
top: onPlay,
|
||||
main: 'Google Play',
|
||||
mark: 'googleplay',
|
||||
alt: { ...APK, href: 'https://github.com/amnezia-vpn/amneziawg-android/releases' },
|
||||
alt: apk('https://github.com/amnezia-vpn/amneziawg-android/releases'),
|
||||
},
|
||||
windows: {
|
||||
href: 'https://github.com/amnezia-vpn/amneziawg-windows-client/releases',
|
||||
top: 'Official release on GitHub',
|
||||
main: 'Download for Windows',
|
||||
top: onGitHub,
|
||||
main: _('Download for Windows'),
|
||||
mark: 'windows',
|
||||
},
|
||||
mac: {
|
||||
href: 'https://apps.apple.com/us/app/amneziawg/id6478942365',
|
||||
top: 'Download on the',
|
||||
top: onAppStore,
|
||||
main: 'Mac App Store',
|
||||
mark: 'appstore',
|
||||
},
|
||||
linux: { href: 'https://github.com/amnezia-vpn/amneziawg-tools', top: 'On GitHub', main: 'amneziawg-tools', mark: 'linux' },
|
||||
linux: { href: 'https://github.com/amnezia-vpn/amneziawg-tools', top: _('On GitHub'), main: 'amneziawg-tools', mark: 'linux' },
|
||||
},
|
||||
wg: {
|
||||
ios: { href: 'https://apps.apple.com/app/wireguard/id1441195209', top: 'Download on the', main: 'App Store', mark: 'appstore' },
|
||||
ios: { href: 'https://apps.apple.com/app/wireguard/id1441195209', top: onAppStore, main: 'App Store', mark: 'appstore' },
|
||||
android: {
|
||||
href: 'https://play.google.com/store/apps/details?id=com.wireguard.android',
|
||||
top: 'Get it on',
|
||||
top: onPlay,
|
||||
main: 'Google Play',
|
||||
mark: 'googleplay',
|
||||
},
|
||||
windows: { href: 'https://www.wireguard.com/install/', top: 'Download from', main: 'wireguard.com', mark: 'windows' },
|
||||
mac: { href: 'https://apps.apple.com/app/wireguard/id1451685025', top: 'Download on the', main: 'Mac App Store', mark: 'appstore' },
|
||||
linux: { href: 'https://www.wireguard.com/install/', top: 'Install from', main: 'wireguard.com', mark: 'linux' },
|
||||
windows: { href: 'https://www.wireguard.com/install/', top: _('Download from'), main: 'wireguard.com', mark: 'windows' },
|
||||
mac: { href: 'https://apps.apple.com/app/wireguard/id1451685025', top: onAppStore, main: 'Mac App Store', mark: 'appstore' },
|
||||
linux: { href: 'https://www.wireguard.com/install/', top: _('Install from'), main: 'wireguard.com', mark: 'linux' },
|
||||
},
|
||||
};
|
||||
return S[app][platform] ?? null;
|
||||
@@ -129,12 +133,12 @@ export const routerStore = (app: AppId): Store =>
|
||||
app === 'wg'
|
||||
? {
|
||||
href: 'https://openwrt.org/docs/guide-user/services/vpn/wireguard/start',
|
||||
top: 'OpenWrt packages',
|
||||
top: _('OpenWrt packages'),
|
||||
main: 'wireguard-tools',
|
||||
mark: 'openwrt',
|
||||
}
|
||||
: // One line on a phone: the kernel module goes on top.
|
||||
{ href: 'https://openwrt.org/packages/start', top: 'OpenWrt packages + kmod', main: 'amneziawg-tools', mark: 'openwrt' };
|
||||
{ href: 'https://openwrt.org/packages/start', top: _('OpenWrt packages + kmod'), main: 'amneziawg-tools', mark: 'openwrt' };
|
||||
|
||||
/**
|
||||
* Does AmneziaVPN here open a `vpn://` link? Only the Android app registers the
|
||||
@@ -146,31 +150,45 @@ export const opensKeyLinks = (platform: Platform): boolean => platform === 'andr
|
||||
/** The key as a file for the share sheet: AmneziaVPN on iOS imports `.vpn` files (the key as text). */
|
||||
export const keyFileName = (confName: string): string => `${confName.replace(/\.conf$/i, '')}.vpn`;
|
||||
|
||||
/** A path through an app's menus: its items in order. */
|
||||
const menu = (...items: string[]) => items.join(' → ');
|
||||
|
||||
/*
|
||||
* Inside the app: where the scanner and the importer are, as each platform's
|
||||
* app words it. The WireGuard apps are the same apps as AmneziaWG (it is
|
||||
* their fork), menus included.
|
||||
* Inside the app: where the scanner and the importer are, word for word as
|
||||
* each platform's app labels them, in its own Russian when the page is in
|
||||
* Russian (every one of these apps has it). Checked against the apps'
|
||||
* sources in October 2026: wireguard-apple, wireguard-android and
|
||||
* wireguard-windows, their amneziawg forks (the same apps, menus included)
|
||||
* and amnezia-client. The context keeps the apps' words apart from the
|
||||
* portal's own. AmneziaVPN opens its "Connection" screen from the + in its
|
||||
* bottom bar (no label there); the scanner is on it on phones only.
|
||||
*/
|
||||
const TUNNEL_MENU: Partial<Record<Platform, { file: string; qr?: string }>> = {
|
||||
ios: { file: '+ → Create from file or archive', qr: '+ → Create from QR code' },
|
||||
android: { file: '+ → Import from file or archive', qr: '+ → Scan from QR code' },
|
||||
mac: { file: '+ → Import tunnel(s) from file' },
|
||||
windows: { file: 'Add Tunnel → Import tunnel(s) from file' },
|
||||
};
|
||||
function tunnelMenu(platform: Platform): { file: string; qr?: string } | undefined {
|
||||
const menus: Partial<Record<Platform, { file: string; qr?: string }>> = {
|
||||
ios: { file: menu('+', _('Create from file or archive', 'WireGuard app')), qr: menu('+', _('Create from QR code', 'WireGuard app')) },
|
||||
android: { file: menu('+', _('Import from file or archive', 'WireGuard app')), qr: menu('+', _('Scan from QR code', 'WireGuard app')) },
|
||||
mac: { file: menu('+', _('Import Tunnel(s) from File…', 'WireGuard app')) },
|
||||
windows: { file: menu(_('Add Tunnel', 'WireGuard app'), _('Import tunnel(s) from file…', 'WireGuard app')) },
|
||||
};
|
||||
return menus[platform];
|
||||
}
|
||||
|
||||
/** Where the app scans a code; a phone of either kind gets both wordings. */
|
||||
export function scanPath(app: AppId, platform: Platform = 'unknown'): string {
|
||||
if (app === 'vpn') return 'Add server → Scan QR';
|
||||
const qr = TUNNEL_MENU[platform]?.qr;
|
||||
return qr ?? `${TUNNEL_MENU.ios!.qr} (Android: ${TUNNEL_MENU.android!.qr!.replace(/^.* → /, '')})`;
|
||||
if (app === 'vpn') return menu('+', _('QR code', 'AmneziaVPN app'));
|
||||
const qr = tunnelMenu(platform)?.qr;
|
||||
return qr ?? fmt(_('%s (Android: %s)'), tunnelMenu('ios')!.qr, tunnelMenu('android')!.qr!.replace(/^.* → /, ''));
|
||||
}
|
||||
|
||||
/** Where the app takes a file (AmneziaVPN: the key). */
|
||||
/** Where the app takes a file (AmneziaVPN: the key, pasted by its Insert button); elsewhere, the Android app's words. */
|
||||
export function importPath(app: AppId, platform: Platform = 'unknown'): string {
|
||||
if (app === 'vpn') return 'Add server → Insert key';
|
||||
return TUNNEL_MENU[platform]?.file ?? 'Add tunnel → Import from file';
|
||||
if (app === 'vpn') return menu('+', _('Insert', 'AmneziaVPN app'));
|
||||
return (tunnelMenu(platform) ?? tunnelMenu('android')!).file;
|
||||
}
|
||||
|
||||
/** The last step in AmneziaVPN, once the key is in: its Continue button. */
|
||||
export const vpnContinue = () => fmt(_('Tap “%s” and connect'), _('Continue', 'AmneziaVPN app'));
|
||||
|
||||
/**
|
||||
* The file into the app, step by step: [text, the part in bold]. Linux has no
|
||||
* app, only the tools: the file goes up straight from where it was saved
|
||||
@@ -179,25 +197,22 @@ export function importPath(app: AppId, platform: Platform = 'unknown'): string {
|
||||
export function importSteps(app: AppId, platform: Platform, file: string, shared: boolean): [string, string][] {
|
||||
if (platform === 'linux')
|
||||
return [
|
||||
['Open a terminal in the folder with the file', ''],
|
||||
['Run ', `sudo ${app === 'wg' ? 'wg-quick' : 'awg-quick'} up ./${file}`],
|
||||
[_('Open a terminal in the folder with the file'), ''],
|
||||
// The command comes after the word, in bold: "Run sudo awg-quick up …".
|
||||
[`${_('Run')} `, `sudo ${app === 'wg' ? 'wg-quick' : 'awg-quick'} up ./${file}`],
|
||||
];
|
||||
const path = importPath(app, platform);
|
||||
return [
|
||||
[`Open ${APP_NAME[app]}`, ''],
|
||||
[fmt(_('Open %s', 'step'), APP_NAME[app]), ''],
|
||||
[path.replace(/ → [^→]*$/, ' → '), path.replace(/^.* → /, '')],
|
||||
[shared ? 'Confirm the import and connect' : 'Pick the file and connect', ''],
|
||||
[shared ? _('Confirm the import and connect') : _('Pick the file and connect'), ''],
|
||||
];
|
||||
}
|
||||
|
||||
export const PLATFORM_LABEL: Record<Platform, string> = {
|
||||
ios: 'iPhone / iPad',
|
||||
android: 'Android',
|
||||
windows: 'Windows',
|
||||
mac: 'Mac',
|
||||
linux: 'Linux',
|
||||
unknown: 'this device',
|
||||
};
|
||||
/** The platform in a sentence: its name, or "this device". */
|
||||
export function platformLabel(p: Platform): string {
|
||||
return { ios: 'iPhone / iPad', android: 'Android', windows: 'Windows', mac: 'Mac', linux: 'Linux', unknown: _('this device') }[p];
|
||||
}
|
||||
|
||||
/**
|
||||
* The personal link that opens straight on one device's set-up: the page then
|
||||
@@ -220,6 +235,16 @@ export const wantsAdd = (hash: string): boolean => hash === '#add';
|
||||
/**
|
||||
* "the phone", "the computer": the device being set up, in a sentence. The
|
||||
* sheet's title already names it; the lines under it do not repeat the name.
|
||||
* `on`: the word after "on the" ("open it on the phone"), which other
|
||||
* languages decline (Russian: на телефоне, but на телефон after "to the").
|
||||
*/
|
||||
export const deviceNoun = (kind: Kind): string =>
|
||||
({ phone: 'phone', tablet: 'tablet', computer: 'computer', router: 'router', other: 'device' })[kind];
|
||||
export const deviceNoun = (kind: Kind, on = false): string =>
|
||||
(on
|
||||
? {
|
||||
phone: _('phone', 'on the'),
|
||||
tablet: _('tablet', 'on the'),
|
||||
computer: _('computer', 'on the'),
|
||||
router: _('router', 'on the'),
|
||||
other: _('device', 'on the'),
|
||||
}
|
||||
: { phone: _('phone'), tablet: _('tablet'), computer: _('computer'), router: _('router'), other: _('device') })[kind];
|
||||
@@ -55,6 +55,10 @@
|
||||
height: 16px;
|
||||
color: var(--text-2);
|
||||
}
|
||||
/* An option's check, kept in its place on the others so the names line up. */
|
||||
.mi .i.off {
|
||||
visibility: hidden;
|
||||
}
|
||||
.mi.warn,
|
||||
.mi.warn .i {
|
||||
color: var(--warn);
|
||||
|
||||
@@ -81,6 +81,44 @@ body.scrolled .edge-fade.top {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
/* The language: a pill as high as the QR knob beside it, its code and a chevron that turns up while
|
||||
the menu is open. */
|
||||
.cr-lang {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
height: 32px;
|
||||
padding: 0 8px 0 12px;
|
||||
border-radius: 999px;
|
||||
background: var(--knob);
|
||||
color: var(--text);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.01em;
|
||||
flex: none;
|
||||
transition:
|
||||
transform 150ms var(--ease-out),
|
||||
background-color 150ms;
|
||||
}
|
||||
.cr-lang:hover {
|
||||
background: color-mix(in srgb, var(--knob), var(--text) 6%);
|
||||
}
|
||||
.cr-lang:active {
|
||||
transform: scale(0.94);
|
||||
}
|
||||
.cr-lang[aria-expanded='true'] {
|
||||
background: color-mix(in srgb, var(--knob), var(--text) 10%);
|
||||
}
|
||||
.cr-down {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
color: var(--text-2);
|
||||
transform: rotate(90deg);
|
||||
transition: transform 200ms var(--ease-out);
|
||||
}
|
||||
.cr-lang[aria-expanded='true'] .cr-down {
|
||||
transform: rotate(-90deg);
|
||||
}
|
||||
|
||||
/* Phones: one column, access first. From 960px: devices left, access right and sticky. The foot
|
||||
clears the bottom fade at the end of the scroll. */
|
||||
|
||||
@@ -210,7 +210,8 @@
|
||||
visibility: hidden;
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* Connected: nothing is left to do here, so × and the view's buttons step away; the sheet then closes by itself. */
|
||||
/* Connected: nothing is left to do here, so × and the view's buttons step away; the sheet then closes
|
||||
by itself. A question has its own Cancel: no × beside it either. */
|
||||
.sheet .x,
|
||||
.sheet-acts {
|
||||
transition:
|
||||
@@ -221,7 +222,8 @@
|
||||
scale 240ms var(--ease-out);
|
||||
}
|
||||
.sheet.arrived .x,
|
||||
.sheet.arrived .sheet-acts {
|
||||
.sheet.arrived .sheet-acts,
|
||||
.sheet.asks .x {
|
||||
opacity: 0;
|
||||
filter: blur(3px);
|
||||
scale: 0.9;
|
||||
@@ -229,38 +231,54 @@
|
||||
}
|
||||
|
||||
/* A question before something that cannot be undone. */
|
||||
.center-col {
|
||||
.center-col,
|
||||
.ask {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.center-col {
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
.center-col.ask {
|
||||
padding-top: 28px;
|
||||
/* A question before something that cannot be undone (Reconnect, Remove): the icon, the question
|
||||
and what happens on the left edge, as iOS asks now, as far from the top as from the sides; the
|
||||
buttons span the sheet under them. */
|
||||
.ask {
|
||||
align-items: flex-start;
|
||||
text-align: left;
|
||||
padding-top: 24px;
|
||||
}
|
||||
.center-col.secure {
|
||||
padding-top: 4px;
|
||||
}
|
||||
.center-col .gi.xl {
|
||||
:is(.center-col, .ask) .gi.xl {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
margin: 8px 0 16px;
|
||||
}
|
||||
.center-col h3 {
|
||||
.ask .gi.xl {
|
||||
margin: 0 0 18px;
|
||||
}
|
||||
:is(.center-col, .ask) h3 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
line-height: 28px;
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.5px;
|
||||
}
|
||||
.center-col p {
|
||||
:is(.center-col, .ask) p {
|
||||
margin: 6px 0 22px;
|
||||
color: var(--text-2);
|
||||
font-size: 15px;
|
||||
line-height: 21px;
|
||||
}
|
||||
.center-col p {
|
||||
max-width: 30ch;
|
||||
text-wrap: balance;
|
||||
}
|
||||
.ask p {
|
||||
text-wrap: pretty;
|
||||
}
|
||||
.center-col.secure p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,12 @@ export function linkRow(url: string): HTMLElement {
|
||||
h('span', { class: 'mono' }, url.replace(/^https?:\/\//, '')),
|
||||
h(
|
||||
'button',
|
||||
{ type: 'button', class: 'knob', 'aria-label': 'Copy the link', onclick: (ev: Event) => copy(url, 'Link copied', ev.currentTarget) },
|
||||
{
|
||||
type: 'button',
|
||||
class: 'knob',
|
||||
'aria-label': _('Copy the link'),
|
||||
onclick: (ev: Event) => copy(url, _('Link copied'), ev.currentTarget),
|
||||
},
|
||||
ic('copy'),
|
||||
),
|
||||
share
|
||||
@@ -107,7 +112,7 @@ export function linkRow(url: string): HTMLElement {
|
||||
{
|
||||
type: 'button',
|
||||
class: 'knob',
|
||||
'aria-label': 'Share the link',
|
||||
'aria-label': _('Share the link'),
|
||||
onclick: () => navigator.share({ url, title: placeName() }).catch(() => undefined),
|
||||
},
|
||||
ic('share'),
|
||||
|
||||
@@ -43,7 +43,9 @@ export function toast(msg: string, bad = false) {
|
||||
|
||||
/**
|
||||
* The control that copied says so for a moment: its icon turns into a check
|
||||
* and a "Copy…" label (`.lbl`, a badge's main line) into "Copied".
|
||||
* and its "Copy…" label (`.lbl`, a badge's main line) into "Copied". Every
|
||||
* control that copies with a label says "Copy…" (in any language), so the
|
||||
* label is not read for the word.
|
||||
*/
|
||||
function copied(from: Element) {
|
||||
if (from.classList.contains('copied')) return;
|
||||
@@ -67,16 +69,16 @@ function copied(from: Element) {
|
||||
},
|
||||
);
|
||||
}
|
||||
if (label && /^Copy/.test(was)) morphText(label, 'Copied');
|
||||
if (label) morphText(label, _('Copied'));
|
||||
setTimeout(() => {
|
||||
if (check && icon) check.replaceWith(icon);
|
||||
if (label && /^Copy/.test(was)) morphText(label, was);
|
||||
if (label) morphText(label, was);
|
||||
from.classList.remove('copied');
|
||||
}, 1600);
|
||||
}
|
||||
|
||||
/** `from`: the control that copied, which then shows a check for a moment. */
|
||||
export async function copy(text: string, what = 'Copied', from?: EventTarget | null) {
|
||||
export async function copy(text: string, what = _('Copied'), from?: EventTarget | null) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch {
|
||||
@@ -85,7 +87,7 @@ export async function copy(text: string, what = 'Copied', from?: EventTarget | n
|
||||
ta.select();
|
||||
const ok = document.execCommand('copy');
|
||||
ta.remove();
|
||||
if (!ok) return toast('Copying is blocked here. Select the text and copy it by hand.', true);
|
||||
if (!ok) return toast(_('Copying is blocked here. Select the text and copy it by hand.'), true);
|
||||
}
|
||||
if (from instanceof Element) copied(from);
|
||||
toast(what);
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
// The ⋯ menu: a small panel under (or over) its button, items with an icon,
|
||||
// a highlight that glides after the pointer and takes the item's colour
|
||||
// (orange for Reconnect, red for Remove). One at a time; it closes on a press
|
||||
// outside, on scroll, on Escape and when its button is pressed again.
|
||||
// (orange for Reconnect, red for Remove). A choice among options (the
|
||||
// language) marks the current one with a check instead of icons. One at a
|
||||
// time; it closes on a press outside, on scroll, on Escape and when its button
|
||||
// is pressed again.
|
||||
|
||||
import { h, ic } from '../dom';
|
||||
import { EASE_IN, POP, play } from '../motion';
|
||||
|
||||
export interface MenuItem {
|
||||
label: string;
|
||||
icon: string;
|
||||
/** An action's icon; an option (`checked` set) shows a check in its place, on the current one only. */
|
||||
icon?: string;
|
||||
checked?: boolean;
|
||||
tone?: 'warn' | 'bad';
|
||||
run: () => unknown;
|
||||
}
|
||||
@@ -53,14 +57,15 @@ export function openMenu(anchor: HTMLElement, all: (MenuItem | null)[]) {
|
||||
'button',
|
||||
{
|
||||
type: 'button',
|
||||
role: 'menuitem',
|
||||
role: it.checked === undefined ? 'menuitem' : 'menuitemradio',
|
||||
'aria-checked': it.checked === undefined ? null : String(it.checked),
|
||||
class: `mi ${it.tone ?? ''}`,
|
||||
onclick: () => {
|
||||
closeMenu();
|
||||
it.run();
|
||||
},
|
||||
},
|
||||
ic(it.icon),
|
||||
it.checked === undefined ? ic(it.icon ?? '') : ic('check', it.checked ? 'i' : 'i off'),
|
||||
h('span', {}, it.label),
|
||||
);
|
||||
// The highlight comes in where the pointer is, then glides from item to item.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// "iPad connected"), and a menu path for another app or the other phone system
|
||||
// (`menuLine`: where the app scans, iOS "Create", Android "Scan").
|
||||
|
||||
import { fmt } from '../../shared/i18n';
|
||||
import { h, ic, markup, put, type Kid } from '../dom';
|
||||
import { EASE_IN, EASE_OUT, POP, SMOOTH, calm, play } from '../motion';
|
||||
|
||||
@@ -229,8 +230,8 @@ export function morphText(el: HTMLElement, next: string, from = textOf(el), o: M
|
||||
easing: SMOOTH.easing,
|
||||
});
|
||||
});
|
||||
const out = was.filter((_, i) => !stays.has(i));
|
||||
const inn = now.filter((_, j) => !comes.has(j));
|
||||
const out = was.filter((_x, i) => !stays.has(i));
|
||||
const inn = now.filter((_x, j) => !comes.has(j));
|
||||
// A long text keeps the same overall sweep: the steps shorten instead.
|
||||
const so = Math.min(12, 160 / Math.max(1, out.length));
|
||||
const si = Math.min(22, 260 / Math.max(1, inn.length));
|
||||
@@ -521,7 +522,7 @@ export function menuLine(ios: string, android: string): MenuLine {
|
||||
);
|
||||
|
||||
const set = (i: string, a: string) => {
|
||||
el.setAttribute('aria-label', (i === a ? i : `${i} (Android: ${a.split(' → ').pop()})`).replace(/ → /g, ' › '));
|
||||
el.setAttribute('aria-label', (i === a ? i : fmt(_('%s (Android: %s)'), i, a.split(' → ').pop())).replace(/ → /g, ' › '));
|
||||
const I = i.split(' → ');
|
||||
const A = a.split(' → ');
|
||||
const next = I.map((s, n) => cut(s, A[n] ?? s));
|
||||
|
||||
@@ -14,7 +14,7 @@ export interface View {
|
||||
el: HTMLElement;
|
||||
/** The sheet's accessible name while this view shows (its title). */
|
||||
label: string;
|
||||
/** A question (Remove, Reconnect): an alert dialog. */
|
||||
/** A question (Remove, Reconnect): an alert dialog, closed by its Cancel (no ×). */
|
||||
asks?: boolean;
|
||||
/** Its own buttons, pinned beside × while it shows. */
|
||||
acts?: HTMLElement | null;
|
||||
@@ -108,7 +108,7 @@ export function startWidth(p: WidthPlan | null) {
|
||||
/* ---------- the drawer ---------- */
|
||||
|
||||
function build() {
|
||||
closeBtn = h('button', { type: 'button', class: 'knob x', 'aria-label': 'Close', onclick: () => closeSheet() }, ic('x'));
|
||||
closeBtn = h('button', { type: 'button', class: 'knob x', onclick: () => closeSheet() }, ic('x'));
|
||||
actsEl = h('div', { class: 'sheet-acts' });
|
||||
vp = h('div', { class: 'vp' });
|
||||
scroller = h('div', { class: 'sheet-scroll' }, vp);
|
||||
@@ -122,7 +122,10 @@ function build() {
|
||||
|
||||
function label(v: View) {
|
||||
sheetEl.setAttribute('aria-label', v.label);
|
||||
// Built once, named each time: the language may have changed since.
|
||||
closeBtn.setAttribute('aria-label', _('Close'));
|
||||
sheetEl.setAttribute('role', v.asks ? 'alertdialog' : 'dialog');
|
||||
sheetEl.classList.toggle('asks', !!v.asks);
|
||||
}
|
||||
|
||||
/** The view being left (a new one, or the sheet closing) lets go of what it holds. */
|
||||
@@ -466,7 +469,7 @@ export function head(title: string, o: { back?: boolean; acts?: boolean } = {}):
|
||||
return h(
|
||||
'div',
|
||||
{ class: `vhead${o.back ? ' center' : ''}${o.acts ? ' with-acts' : ''}` },
|
||||
o.back ? h('button', { type: 'button', class: 'knob back', 'aria-label': 'Back', onclick: back }, ic('chevron')) : null,
|
||||
o.back ? h('button', { type: 'button', class: 'knob back', 'aria-label': _('Back'), onclick: back }, ic('chevron')) : null,
|
||||
h('h2', {}, title),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user