v1.3.5: own API key on the phone no longer hangs (secure-storage plugin handed to a promise as a thenable)
Every key-store call on Android stalled before it started: the Capacitor plugin proxy answers `then` with a native method, so a promise resolving to the plugin itself never settled. Save greyed out, key "not saved", Coach "thinking" forever (#42, #58). The plugin now travels inside a plain object; a test drives the store through a Capacitor-style proxy. Verified on an emulator.
This commit is contained in:
1 parent
95654b4f55
commit
684b0054ad
13 files changed
+94
-22
No files matched your search
@@ -1,5 +1,22 @@
|
||||
# Changelog
|
||||
|
||||
## v1.3.5 — 2026-09-06
|
||||
|
||||
One bug, and the one everybody with the Android app and their own API key ran into. Web bundle and
|
||||
APK; the API only carries the version number.
|
||||
|
||||
- 🔑 **"Bring my own API key" works on the phone.** Since v1.3.0 every key-store call on Android
|
||||
hung before it started: the secure-storage plugin was handed to the app as the value of a promise,
|
||||
and a Capacitor plugin object answers *any* property name with a native method — `then`
|
||||
included — so the promise took it for a thenable, called a native `SecureStorage.then()` that does
|
||||
not exist, and never settled. That one stuck `await` was all three reports at once: "Save and use
|
||||
the Coach" greyed out forever, the key "not saved" when you came back, and a Coach that sat on
|
||||
"thinking…" without end because the job read the key first. The plugin now travels inside a plain
|
||||
object, a test drives the store through a Capacitor-style proxy so it cannot come back, and the
|
||||
whole flow — save, intake, plan, restart with the key still there — was run on an emulator before
|
||||
tagging. The web app and the "use my self-hosted openGym" mode were never affected.
|
||||
(issues #42, #58; reported by many on Discord)
|
||||
|
||||
## v1.3.4 — 2026-09-05
|
||||
|
||||
Two things noticed on the phone right after v1.3.3. Web bundle and APK; the API only carries the
|
||||
|
||||
@@ -210,9 +210,9 @@ host side of that volume, not the variable.
|
||||
## Roadmap
|
||||
|
||||
The plan lives in [ROADMAP.md](ROADMAP.md) and on the
|
||||
[GitLab milestones](https://gitlab.com/DuarteSantos8/opengym/-/milestones): v1.3.4 programmes and
|
||||
[GitLab milestones](https://gitlab.com/DuarteSantos8/opengym/-/milestones): v1.3.5 programmes and
|
||||
progression (explicit warm-up/work phases, AMRAP driver selection, multi-week programmes, adaptive
|
||||
1RM), v1.3.5 accounts and sync (password and OIDC login, personal-trainer role, remote MCP), v1.3.6
|
||||
1RM), v1.3.6 accounts and sync (password and OIDC login, personal-trainer role, remote MCP), v1.3.7
|
||||
mobile (timer in the notification bar, widgets, Withings). Ideas and merge requests welcome — the
|
||||
[board](https://gitlab.com/DuarteSantos8/opengym/-/boards) shows what is planned, in progress and
|
||||
waiting for a test on the staging instance.
|
||||
|
||||
+3
-3
@@ -57,7 +57,7 @@ Left over from this block:
|
||||
- A real pause for the workout timers (#29 asked for it)
|
||||
- Discord announcement (owner)
|
||||
|
||||
## v1.3.4 — Programmes & progression (October 2026)
|
||||
## v1.3.5 — Programmes & progression (October 2026)
|
||||
|
||||
**Theme: training structure beyond one weekly template.** Most of this is the Space-Hermes series.
|
||||
It changes the training model (per-set roles, explicit phases, normalisation on every persist), so
|
||||
@@ -81,7 +81,7 @@ it goes in one MR at a time, each rebased and tested on gym-test before the next
|
||||
- Catalogue cleanup: exercises that should not carry weight, incline and interval fields for
|
||||
cardio (#46); timers for planks and outdoor cardio are already there, document them (#45)
|
||||
|
||||
## v1.3.5 — Accounts & sync (November 2026)
|
||||
## v1.3.6 — Accounts & sync (November 2026)
|
||||
|
||||
**Theme: who may sign in, and what else may read or write your data.**
|
||||
|
||||
@@ -99,7 +99,7 @@ it goes in one MR at a time, each rebased and tested on gym-test before the next
|
||||
logged sessions lost after editing a routine (#25)
|
||||
- Admin: per-user export, invite management, audit log filters
|
||||
|
||||
## v1.3.6 — Mobile (December 2026)
|
||||
## v1.3.7 — Mobile (December 2026)
|
||||
|
||||
**Theme: the Android app catches up with the web app.**
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ openapi: 3.1.0
|
||||
|
||||
info:
|
||||
title: openGym API
|
||||
version: 1.3.4
|
||||
version: 1.3.5
|
||||
summary: Passkey (WebAuthn) auth + per-user state storage for openGym
|
||||
description: |
|
||||
The backend of [openGym](https://opengym.duarte-santos.ch) — a free, open-source
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "gym-api",
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "gym-api",
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.5",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@simplewebauthn/server": "^13.1.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gym-api",
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.5",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "server.js",
|
||||
|
||||
@@ -7,8 +7,8 @@ android {
|
||||
applicationId "ch.duartesantos.opengym"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 18
|
||||
versionName "1.3.4"
|
||||
versionCode 19
|
||||
versionName "1.3.5"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "opengym-frontend",
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "opengym-frontend",
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.5",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@aparajita/capacitor-secure-storage": "^7.1.6",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "opengym-frontend",
|
||||
"private": true,
|
||||
"version": "1.3.4",
|
||||
"version": "1.3.5",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -10,12 +10,19 @@
|
||||
const KEY = 'coach.apiKey'
|
||||
const memory = new Map()
|
||||
|
||||
// The loaded plugin travels inside a plain object, never as a promise's own value (no `await`
|
||||
// or `.then` may ever hand the proxy back bare — the wrapper below is the whole point). Capacitor's
|
||||
// registerPlugin() hands out a Proxy that answers EVERY property name with a native-method
|
||||
// wrapper — `then` included — so a promise that resolves to the proxy itself takes it for a
|
||||
// thenable, calls SecureStorage.then() on the native side ("not implemented on android"), and
|
||||
// never settles. That one await hung the whole feature on the phone: "Save and use the Coach"
|
||||
// greyed out forever, the key "not saved", the Coach "thinking" without end (issues #42, #58).
|
||||
let pluginPromise = null
|
||||
function plugin() {
|
||||
if (!pluginPromise) {
|
||||
pluginPromise = import('@aparajita/capacitor-secure-storage')
|
||||
.then(m => (m && m.SecureStorage && typeof m.SecureStorage.get === 'function' ? m.SecureStorage : null))
|
||||
.catch(() => null)
|
||||
.then(m => ({ store: m && m.SecureStorage && typeof m.SecureStorage.get === 'function' ? m.SecureStorage : null }))
|
||||
.catch(() => ({ store: null }))
|
||||
}
|
||||
return pluginPromise
|
||||
}
|
||||
@@ -30,7 +37,7 @@ export const withTimeout = (promise, ms = NATIVE_TIMEOUT_MS) => new Promise((res
|
||||
})
|
||||
|
||||
export async function getApiKey() {
|
||||
const p = await plugin()
|
||||
const { store: p } = await plugin()
|
||||
if (p) {
|
||||
try { const v = await withTimeout(p.get(KEY)); return typeof v === 'string' && v ? v : null } catch { /* fall through */ }
|
||||
}
|
||||
@@ -39,14 +46,14 @@ export async function getApiKey() {
|
||||
export async function setApiKey(value) {
|
||||
const v = String(value || '').trim()
|
||||
if (!v) return clearApiKey()
|
||||
const p = await plugin()
|
||||
const { store: p } = await plugin()
|
||||
if (p) {
|
||||
try { await withTimeout(p.set(KEY, v)); memory.delete(KEY); return } catch { /* fall through */ }
|
||||
}
|
||||
memory.set(KEY, v)
|
||||
}
|
||||
export async function clearApiKey() {
|
||||
const p = await plugin()
|
||||
const { store: p } = await plugin()
|
||||
if (p) { try { await withTimeout(p.remove(KEY)) } catch { /* nothing to clear */ } }
|
||||
memory.delete(KEY)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// @vitest-environment node
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
// A stand-in for what @capacitor/core's registerPlugin() really returns: a Proxy that turns ANY
|
||||
// property — `then` included — into a method wrapper whose native call fails asynchronously
|
||||
// without ever invoking the callbacks it was handed. Resolving a promise with that object makes
|
||||
// the promise wait for `then` to call back, which it never does (issues #42 / #58).
|
||||
const calls = []
|
||||
const backing = new Map()
|
||||
const impl = {
|
||||
get: async k => (backing.has(k) ? backing.get(k) : null),
|
||||
set: async (k, v) => { backing.set(k, v) },
|
||||
remove: async k => backing.delete(k)
|
||||
}
|
||||
const SecureStorage = new Proxy({}, {
|
||||
get(_, prop) {
|
||||
if (prop === '$$typeof') return undefined
|
||||
if (prop === 'toJSON') return () => ({})
|
||||
return (...args) => {
|
||||
calls.push(String(prop))
|
||||
if (impl[prop]) return impl[prop](...args)
|
||||
return Promise.reject(new Error(`"SecureStorage.${String(prop)}()" is not implemented on android`))
|
||||
}
|
||||
}
|
||||
})
|
||||
vi.mock('@aparajita/capacitor-secure-storage', () => ({ SecureStorage }))
|
||||
|
||||
const secrets = await import('./coach-secrets.js')
|
||||
|
||||
const within = (p, ms) => Promise.race([p, new Promise((_, rej) => setTimeout(() => rej(new Error(`hung for ${ms} ms`)), ms))])
|
||||
|
||||
describe('coach-secrets against a Capacitor-style plugin proxy', () => {
|
||||
beforeEach(() => { calls.length = 0; backing.clear() })
|
||||
|
||||
it('a round trip settles instead of waiting on the proxy\'s never-answering then()', async () => {
|
||||
await within(secrets.setApiKey('sk-live-1'), 1000)
|
||||
expect(await within(secrets.getApiKey(), 1000)).toBe('sk-live-1')
|
||||
await within(secrets.clearApiKey(), 1000)
|
||||
expect(await within(secrets.getApiKey(), 1000)).toBe(null)
|
||||
expect(calls).not.toContain('then')
|
||||
})
|
||||
|
||||
it('goes through the platform store, not the in-memory fallback', async () => {
|
||||
await within(secrets.setApiKey('sk-live-2'), 1000)
|
||||
expect([...backing.keys()]).toEqual(['coach.apiKey'])
|
||||
expect(calls).toEqual(['set'])
|
||||
})
|
||||
})
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- GENERATED FILE - do not edit by hand.
|
||||
Built by scripts/build-api-docs.mjs from api/openapi.yaml (openGym API v1.3.4).
|
||||
Built by scripts/build-api-docs.mjs from api/openapi.yaml (openGym API v1.3.5).
|
||||
Regenerate with: node scripts/build-api-docs.mjs -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -232,7 +232,7 @@ main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; fon
|
||||
</div>
|
||||
<p class="api-facts">
|
||||
<span>OpenAPI 3.1.0</span>
|
||||
<span>openGym v1.3.4</span>
|
||||
<span>openGym v1.3.5</span>
|
||||
<span>28 endpoints</span>
|
||||
<span>AGPL-3.0-or-later</span>
|
||||
</p>
|
||||
|
||||
+1
-1
@@ -404,7 +404,7 @@ try {
|
||||
</ul>
|
||||
<div class="push">
|
||||
<a class="btn" href="openGym.apk" download>Download for Android</a>
|
||||
<p class="meta">v1.3.4 · 27.7 MB · Android 6.0+ · signed APK. Your browser will ask
|
||||
<p class="meta">v1.3.5 · 27.7 MB · Android 6.0+ · signed APK. Your browser will ask
|
||||
before installing; that is normal outside the Play Store.</p>
|
||||
<p class="meta">Every release is also built and signed by CI and attached to the
|
||||
<a href="https://gitlab.com/DuarteSantos8/opengym/-/releases" rel="noopener">GitLab
|
||||
|
||||
Reference in new issue
Block a user