Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/lib/modules/device/lib/ble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,25 @@ export class Watch {
dbg("subscriptions done, key saved:", Boolean(loadKey()));
const k = loadKey();

// rescue never pairs: pairing waits for a tap on a watch whose screen may never light up.
// Fail now and say why, instead of hanging on a confirmation nobody can give
if (rescue && !k)
throw new Error(
"no saved key for this watch in this browser — rescue can't pair, it needs a tap on the watch",
);
if (k) {
try {
await this.authenticate(k);
} catch (e) {
// a stale key (the watch was re-paired/reset) shows up as authFailed or silence on the first
// encrypted exchange (authMac = 0x49); other errors don't touch the saved key
if (!/rejected the auth key|timeout waiting for 0x49/.test((e as Error).message)) throw e;
// encrypted exchange (authMac = 0x49); other errors don't touch the saved key. On rescue
// the key is all there is, and a wedged watch going silent proves nothing: keep it, and
// let the caller try again
if (
rescue ||
!/rejected the auth key|timeout waiting for 0x49/.test((e as Error).message)
)
throw e;
dbg("stored key stale, clearing:", (e as Error).message);
localStorage.removeItem(KEY_STORE);
// pairing needs the shell service — if it's not visible on the current connection, reconnect,
Expand Down
10 changes: 10 additions & 0 deletions src/lib/modules/device/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const en = {
dialNotInstalled: (id: string, d: string) => `dial ${id} not installed (${d})`,
notAccepted: (why: string, kb: string) => `watch did not accept the file (${why}; ${kb} KB)`,
storedNotActivated: "stored but not activated",
rescueNoKey:
"no saved key for this watch in this browser — rescue can't pair, it needs a tap on the watch",
deleteFailed: (d: string) => `dial delete failed (${d})`,
refusedReplace: (name: string) =>
`the watch refused to replace “${name}” — flash again and pick a different dial to replace`,
Expand Down Expand Up @@ -149,6 +151,8 @@ export const bt = dict(en, {
dialNotInstalled: (id, d) => `циферблат ${id} не установлен (${d})`,
notAccepted: (why, kb) => `часы не приняли файл (${why}; ${kb} КБ)`,
deleteFailed: (d) => `не удалось удалить циферблат (${d})`,
rescueNoKey:
"в этом браузере нет ключа часов — восстановление не может выполнить сопряжение, для него нужно нажатие на часах",
storedNotActivated: "сохранён, но не активирован",
refusedReplace: (name) =>
`часы отказались заменить «${name}» — загрузите ещё раз и выберите другой циферблат для замены`,
Expand Down Expand Up @@ -242,6 +246,8 @@ export const bt = dict(en, {
dialNotInstalled: (id, d) => `циферблат ${id} не встановлено (${d})`,
notAccepted: (why, kb) => `годинник не прийняв файл (${why}; ${kb} КБ)`,
deleteFailed: (d) => `не вдалося видалити циферблат (${d})`,
rescueNoKey:
"у цьому браузері немає ключа годинника — відновлення не може виконати сполучення, для нього потрібне натискання на годиннику",
storedNotActivated: "збережено, але не активовано",
refusedReplace: (name) =>
`годинник відмовився замінити «${name}» — завантажте ще раз і виберіть інший циферблат для заміни`,
Expand Down Expand Up @@ -335,6 +341,8 @@ export const bt = dict(en, {
dialNotInstalled: (id, d) => `la esfera ${id} no está instalada (${d})`,
notAccepted: (why, kb) => `el reloj no aceptó el archivo (${why}; ${kb} KB)`,
deleteFailed: (d) => `no se pudo borrar la esfera (${d})`,
rescueNoKey:
"este navegador no tiene la clave del reloj — el rescate no puede emparejar, eso requiere tocar el reloj",
storedNotActivated: "guardado pero no activado",
refusedReplace: (name) =>
`el reloj se negó a reemplazar «${name}» — vuelve a enviarla y elige otra esfera para reemplazar`,
Expand Down Expand Up @@ -430,6 +438,7 @@ export const bt = dict(en, {
dialNotInstalled: (id, d) => `फ़ेस ${id} इंस्टॉल नहीं है (${d})`,
notAccepted: (why, kb) => `घड़ी ने फ़ाइल स्वीकार नहीं की (${why}; ${kb} KB)`,
deleteFailed: (d) => `फ़ेस हटाना विफल रहा (${d})`,
rescueNoKey: "इस ब्राउज़र में घड़ी की key नहीं है — रेस्क्यू पेयर नहीं कर सकता, उसके लिए घड़ी पर टैप चाहिए",
storedNotActivated: "सेव हुई पर चालू नहीं हुई",
refusedReplace: (name) =>
`घड़ी ने “${name}” को बदलने से मना किया — फिर से भेजें और बदलने के लिए दूसरा फ़ेस चुनें`,
Expand Down Expand Up @@ -535,6 +544,7 @@ const RULES: Rule[] = [
[/^the watch refused to replace “(.+)” — /, (w, m) => w.refusedReplace(m[1])],
[/^dial delete failed \((.+)\)$/, (w, m) => w.deleteFailed(m[1])],
lit("aodNoPreview"),
lit("rescueNoKey"),
[
/^an image is (\d+)×(\d+) px, over the (\d+) px limit/,
(w, m) => w.imageOverLimit(m[1], m[2], m[3]),
Expand Down
4 changes: 3 additions & 1 deletion src/lib/modules/device/model/rescue.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/** The gentler action: delete the faces this browser installed, the bad one among them. */
export const facesRequested = createEvent();
export const stopRequested = createEvent();
export type RescueResult = { action: "reset" } | { action: "faces"; deleted: number };

Check warning on line 21 in src/lib/modules/device/model/rescue.model.ts

View workflow job for this annotation

GitHub Actions / check

style(blank-line-after-vars)

src/lib/modules/device/model/rescue.model.ts:21:1: Expected a blank line after variable declarations
type Words = StoreValue<typeof t>;

export const $status = createStore("");
Expand Down Expand Up @@ -76,7 +76,9 @@
for (const id of flashedHere()) if (await w.deleteDial(id, FILLER)) deleted++;
return { action, deleted };
} catch (e) {
if (pickerClosed(e) || stopping) throw e;
// no key is no key on every attempt: say it once instead of retrying forever
if (pickerClosed(e) || stopping || (e as Error).message.startsWith("no saved key"))
throw e;
logged(`attempt ${attempt} failed: ${(e as Error).message}`);
statusChanged(t.rescueRetrying(attempt + 1));
await new Promise((r) => setTimeout(r, RETRY_MS));
Expand Down
Loading