Settings: an Updates section as the last thing on the page (check and install on Android, APK link on the web); changelog for the merged MRs
The deload-demo.html page from !103 does not ship: frontend/public/ lands in every dist.
This commit is contained in:
1 parent
637e32a904
commit
bf9764e3a2
18 files changed
+220
-128
No files matched your search
@@ -46,6 +46,8 @@ export default function Settings() {
|
||||
|
||||
// --- update check state ---
|
||||
const [updateInfo, setUpdateInfo] = useState(null) // { hasUpdate, latestVersion, apkUrl, hashUrl } | null
|
||||
const [android, setAndroid] = useState(false)
|
||||
const [checking, setChecking] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
// The in-app updater installs an .apk, so it only applies to the native Android build.
|
||||
@@ -53,9 +55,24 @@ export default function Settings() {
|
||||
// already answers false off the mobile build; the MOBILE check on top keeps the web bundle
|
||||
// from even asking (and from calling gitlab.com on every Settings visit).
|
||||
if (!MOBILE) return
|
||||
isAndroid().then(ok => { if (ok) checkForUpdate().then(setUpdateInfo).catch(() => {}) })
|
||||
isAndroid().then(ok => { setAndroid(ok); if (ok) checkForUpdate().then(setUpdateInfo).catch(() => {}) })
|
||||
}, [])
|
||||
|
||||
// The same check, on demand: the automatic one is silent when it finds nothing or cannot
|
||||
// reach gitlab.com, and a person who taps "Check for updates" deserves an answer either way.
|
||||
const checkNow = async () => {
|
||||
if (checking) return
|
||||
setChecking(true)
|
||||
try {
|
||||
const info = await checkForUpdate()
|
||||
setUpdateInfo(info)
|
||||
if (!info.hasUpdate) toast(t('You have the latest version.'))
|
||||
} catch {
|
||||
toast(t('Could not check for updates — are you online?'))
|
||||
}
|
||||
setChecking(false)
|
||||
}
|
||||
|
||||
const onUpdateRowClick = () => {
|
||||
if (!updateInfo?.hasUpdate) return
|
||||
if (updateInfo.apkUrl) {
|
||||
@@ -320,9 +337,6 @@ export default function Settings() {
|
||||
|
||||
{/* ---------- data: fill it, bring things over, back it up, wipe it ---------- */}
|
||||
<Section title={t('Data')}>
|
||||
{MOBILE && updateInfo?.hasUpdate && updateInfo.apkUrl && <Row icon="info" iconTint="var(--purple)" title={t('openGym v{0} available', updateInfo.latestVersion)}
|
||||
accessory="chevron"
|
||||
onClick={onUpdateRowClick} />}
|
||||
<Row icon="sparkles" iconTint="var(--acc)" title={t('Load starter plan')} accessory="chevron" onClick={starterPlanSheet} />
|
||||
<Row icon="shuffle" iconTint="var(--teal)" title={t('Import from another app')}
|
||||
subtitle={t('FitNotes, Strong, Hevy — or body weight from Apple Health')}
|
||||
@@ -350,6 +364,23 @@ export default function Settings() {
|
||||
subtitle={t('to install openGym as a full-screen app.') + ' ' + (user ? t('Your data syncs with your profile — sign in anywhere to see it.') : t('Guest data stays on this device — export a backup now and then!'))} />
|
||||
</Section>}
|
||||
|
||||
{/* ---------- updates: the last thing on the page, so keeping openGym current is one tap ----------
|
||||
On Android the row is always there — it checks on demand and installs when a release is
|
||||
newer (checksum verified, see onUpdateRowClick). On the web the app updates with its
|
||||
server, so the row points at the APK for the phone instead. iOS has no APK: nothing. */}
|
||||
{(!MOBILE || android) && <Section title={t('Updates')}
|
||||
footer={MOBILE ? t('Releases are checked on gitlab.com. The download is verified against its checksum before the installer opens.') : t('The web app updates together with your server. The Android app installs its own updates from here.')}>
|
||||
{MOBILE
|
||||
? <Row icon="download" iconTint="var(--acc)"
|
||||
title={updateInfo?.hasUpdate ? t('Update to openGym v{0}', updateInfo.latestVersion) : t('Check for updates')}
|
||||
subtitle={checking ? t('Checking…') : t('You have v{0}', __APP_VERSION__)}
|
||||
accessory="chevron"
|
||||
onClick={() => (updateInfo?.hasUpdate ? onUpdateRowClick() : checkNow())} />
|
||||
: <Row icon="download" iconTint="var(--acc)" title={t('Get the Android app')}
|
||||
subtitle={t('Download the APK from opengym.duarte-santos.ch')} accessory="chevron"
|
||||
onClick={() => window.open('https://opengym.duarte-santos.ch/#download', '_blank', 'noopener')} />}
|
||||
</Section>}
|
||||
|
||||
{/* The version, at the bottom of Settings — which is where the support template has been
|
||||
telling people to look for it, and where it was not. On the phone build there is no
|
||||
address bar and no about box, so without this there is no way to tell which build you
|
||||
|
||||
@@ -86,20 +86,26 @@ const mount = async () => {
|
||||
await act(async () => { root.render(<Settings />) })
|
||||
await act(async () => { await Promise.resolve(); await Promise.resolve() })
|
||||
}
|
||||
const updateRow = () => [...host.querySelectorAll('.lrow')].find(r => r.textContent.includes('openGym v9.9.9 available'))
|
||||
const updateRow = () => [...host.querySelectorAll('.lrow')].find(r => r.textContent.includes('Update to openGym v9.9.9'))
|
||||
const checkRow = () => [...host.querySelectorAll('.lrow')].find(r => r.textContent.includes('Check for updates'))
|
||||
const webRow = () => [...host.querySelectorAll('.lrow')].find(r => r.textContent.includes('Get the Android app'))
|
||||
|
||||
describe('Settings — in-app update check', () => {
|
||||
it('web build: never asks for releases and shows no update row', async () => {
|
||||
it('web build: never asks for releases; the Updates section points at the APK instead', async () => {
|
||||
await mount()
|
||||
expect(mocks.checkForUpdate).not.toHaveBeenCalled()
|
||||
expect(updateRow()).toBeUndefined()
|
||||
expect(checkRow()).toBeUndefined()
|
||||
expect(webRow()).toBeTruthy()
|
||||
})
|
||||
|
||||
it('mobile build on iOS: no check, no row', async () => {
|
||||
it('mobile build on iOS: no check, no row, no section', async () => {
|
||||
mocks.MOBILE = true
|
||||
await mount()
|
||||
expect(mocks.checkForUpdate).not.toHaveBeenCalled()
|
||||
expect(updateRow()).toBeUndefined()
|
||||
expect(checkRow()).toBeUndefined()
|
||||
expect(webRow()).toBeUndefined()
|
||||
})
|
||||
|
||||
it('mobile build on Android: checks once and shows the row, tapping it asks before downloading', async () => {
|
||||
@@ -113,20 +119,26 @@ describe('Settings — in-app update check', () => {
|
||||
expect(mocks.confirmSheet.mock.calls[0][0].title).toBe('Update to 9.9.9?')
|
||||
})
|
||||
|
||||
it('Android without a newer release: no row', async () => {
|
||||
it('Android without a newer release: a "Check for updates" row stays, and tapping it checks again', async () => {
|
||||
mocks.MOBILE = true
|
||||
mocks.android = true
|
||||
mocks.checkForUpdate.mockResolvedValueOnce({ hasUpdate: false, latestVersion: 'test', apkUrl: null, hashUrl: null })
|
||||
await mount()
|
||||
expect(mocks.checkForUpdate).toHaveBeenCalledTimes(1)
|
||||
expect(updateRow()).toBeUndefined()
|
||||
expect(checkRow()).toBeTruthy()
|
||||
await act(async () => { checkRow().click(); await Promise.resolve() })
|
||||
expect(mocks.checkForUpdate).toHaveBeenCalledTimes(2)
|
||||
await act(async () => { await Promise.resolve() })
|
||||
expect(updateRow()).toBeTruthy() // the second (default) answer had 9.9.9 — the row now offers it
|
||||
})
|
||||
|
||||
it('Android when gitlab.com is unreachable: stays quiet', async () => {
|
||||
it('Android when gitlab.com is unreachable: stays quiet, keeps the row', async () => {
|
||||
mocks.MOBILE = true
|
||||
mocks.android = true
|
||||
mocks.checkForUpdate.mockRejectedValueOnce(new Error('offline'))
|
||||
await mount()
|
||||
expect(updateRow()).toBeUndefined()
|
||||
expect(checkRow()).toBeTruthy()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user