diff --git a/src/lib/modules/device/lib/ble.ts b/src/lib/modules/device/lib/ble.ts index e3b570d..079ad6e 100644 --- a/src/lib/modules/device/lib/ble.ts +++ b/src/lib/modules/device/lib/ble.ts @@ -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, diff --git a/src/lib/modules/device/messages.ts b/src/lib/modules/device/messages.ts index 4c87475..184c89d 100644 --- a/src/lib/modules/device/messages.ts +++ b/src/lib/modules/device/messages.ts @@ -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`, @@ -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}» — загрузите ещё раз и выберите другой циферблат для замены`, @@ -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}» — завантажте ще раз і виберіть інший циферблат для заміни`, @@ -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`, @@ -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}” को बदलने से मना किया — फिर से भेजें और बदलने के लिए दूसरा फ़ेस चुनें`, @@ -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]), diff --git a/src/lib/modules/device/model/rescue.model.ts b/src/lib/modules/device/model/rescue.model.ts index c067524..7b6d04d 100644 --- a/src/lib/modules/device/model/rescue.model.ts +++ b/src/lib/modules/device/model/rescue.model.ts @@ -76,7 +76,9 @@ const rescueFx = attach({ 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));