Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Android: a third APK, Plus (240 px), between Standard and HD
Duarte Santos98eac9af7d42
diff --git a/frontend/src/lib/update.js b/frontend/src/lib/update.jsindex 70c3b837c..f821fcf36 100644--- a/frontend/src/lib/update.js+++ b/frontend/src/lib/update.js@@ -69,22 +69,28 @@ async function fetchLatest() {}/**- * Since v1.4.2 a release carries two sideloaded APKs: the Standard one (180 px animations built in,- * openGym-<v>.apk) and the HD one (sharper animations, openGym-HD-<v>.apk). Each installed APK- * only ever updates to its own kind, so a phone that picked HD keeps HD, and nobody is handed a- * download twice the size they never asked for. The build says which kind it is (VITE_APK_VARIANT, set- * by scripts/android/build-release.sh); a build without it goes by what it has built in.+ * Since v1.4.2 a release carries three sideloaded APKs, the same app with different animations+ * built in: Standard (180 px, openGym-<v>.apk), Plus (240 px, openGym-Plus-<v>.apk) and HD+ * (360 px, openGym-HD-<v>.apk). Each installed APK only ever updates to its own kind, so a phone+ * that picked HD keeps HD, and nobody is handed a download twice the size they never asked for.+ * The build says which kind it is (VITE_APK_VARIANT, set by scripts/android/build-release.sh); a+ * build without it goes by what it has built in.* The checksum is the one named after the chosen APK, never just the first .sha256 in the list.- * An HD build finds no HD APK in a release: no direct download (the update row then opens the- * releases page), rather than quietly swapping it for the Standard one.+ * A release without an APK of this kind: no direct download (the update row then opens the+ * releases page), rather than quietly swapping it for another kind.+ * Phones from before v1.4.2 take the first .apk of the list, and GitHub sorts assets by name:+ * "openGym-1…" comes before "openGym-HD-…" and "openGym-Plus-…", so they land on Standard.*/const ENV = import.meta.env || {}-export const APK_VARIANT = ENV.VITE_APK_VARIANT === 'hd' || ENV.VITE_APK_VARIANT === 'standard'+export const APK_VARIANTS = ['standard', 'plus', 'hd']+export const APK_VARIANT = APK_VARIANTS.includes(ENV.VITE_APK_VARIANT)? ENV.VITE_APK_VARIANT- : (BUILTIN_PX > 180 ? 'hd' : 'standard')-const isHdApk = name => /(^|[-_.])hd([-_.]|$)/i.test(name)+ : (BUILTIN_PX >= 360 ? 'hd' : BUILTIN_PX > 180 ? 'plus' : 'standard')+const tagged = (name, tag) => new RegExp(`(^|[-_.])${tag}([-_.]|$)`, 'i').test(name)+/** Which kind an APK file name is: 'hd', 'plus' or 'standard'. */+export const apkKind = name => tagged(name, 'hd') ? 'hd' : tagged(name, 'plus') ? 'plus' : 'standard'export function pickApk(assets, variant = APK_VARIANT) {- const apk = assets.find(a => /\.apk$/i.test(a.name) && isHdApk(a.name) === (variant === 'hd')) || null+ const apk = assets.find(a => /\.apk$/i.test(a.name) && apkKind(a.name) === variant) || nullconst hash = apk ? assets.find(a => a.name === `${apk.name}.sha256`) || null : nullreturn { apk, hash }}diff --git a/frontend/src/lib/update.test.js b/frontend/src/lib/update.test.jsindex a37c9e5e3..e89a0cdf6 100644--- a/frontend/src/lib/update.test.js+++ b/frontend/src/lib/update.test.js@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'-import { checkForUpdate, sha256, resetUpdateCheck, fetchChecksum, pickApk, APK_VARIANT } from './update.js'+import { checkForUpdate, sha256, resetUpdateCheck, fetchChecksum, pickApk, APK_VARIANT, apkKind } from './update.js'// __APP_VERSION__ is defined at build time by vite.config.js (reads package.json).// In the test environment vitest applies the same define, so it's available here.@@ -281,3 +281,37 @@ describe('pickApk: Standard and HD APKs', () => {expect(hash).toBe(null)})})++describe('pickApk: Standard, Plus and HD', () => {+ const a = n => ({ name: n, browser_download_url: `https://github.com/DuarteSantos8/openGym/releases/download/v1.4.2/${n}` })+ const NAMES = ['openGym-1.4.2.apk', 'openGym-1.4.2.apk.sha256', 'openGym-HD-1.4.2.apk', 'openGym-HD-1.4.2.apk.sha256',+ 'openGym-Plus-1.4.2.apk', 'openGym-Plus-1.4.2.apk.sha256']+ const sorted = [...NAMES].sort().map(a) // GitHub lists assets by name++ it('names the three kinds', () => {+ expect(apkKind('openGym-1.4.2.apk')).toBe('standard')+ expect(apkKind('openGym-Plus-1.4.2.apk')).toBe('plus')+ expect(apkKind('openGym-HD-1.4.2.apk')).toBe('hd')+ expect(apkKind('openGym-1.5.0-plus.apk')).toBe('plus')+ expect(apkKind('openGym-surplus-1.4.2.apk')).toBe('standard')+ })++ it('each kind updates only to itself, with its own checksum, in any order', () => {+ for (const list of [sorted, [...sorted].reverse()]) {+ for (const [variant, name] of [['standard', 'openGym-1.4.2.apk'], ['plus', 'openGym-Plus-1.4.2.apk'], ['hd', 'openGym-HD-1.4.2.apk']]) {+ const { apk, hash } = pickApk(list, variant)+ expect(apk.name).toBe(name)+ expect(hash.name).toBe(`${name}.sha256`)+ }+ }+ })++ it('a phone from before v1.4.2 (first .apk, first .sha256 in name order) lands on Standard, checksum matching', () => {+ expect(sorted.find(x => /\.apk$/i.test(x.name)).name).toBe('openGym-1.4.2.apk')+ expect(sorted.find(x => /\.apk\.sha256$/i.test(x.name)).name).toBe('openGym-1.4.2.apk.sha256')+ })++ it('a Plus build is not moved to another kind when a release has no Plus APK', () => {+ expect(pickApk(['openGym-1.4.3.apk', 'openGym-HD-1.4.3.apk'].map(a), 'plus').apk).toBe(null)+ })+})diff --git a/scripts/android/build-release.sh b/scripts/android/build-release.shindex 6c0850f84..a708b1691 100755--- a/scripts/android/build-release.sh+++ b/scripts/android/build-release.sh@@ -1,11 +1,12 @@#!/usr/bin/env bash# Builds and signs the Android releases on the release machine:# openGym-<version>.apk the Standard sideloaded APK (GitHub, opengym.ch): 180 px built in+# openGym-Plus-<version>.apk the Plus sideloaded APK: 240 px built in (PLUS_PX)# openGym-HD-<version>.apk the HD sideloaded APK: sharper animations built in (HD_PX, 360)# openGym-<version>.aab the Google Play bundle: Play updates it-# Each from its own phone build (owner, v1.4.2). The two APKs have no packs and update themselves,+# Each from its own phone build (owner, v1.4.2). The APKs have no packs and update themselves,# each to its own kind (lib/update.js pickApk, told by VITE_APK_VARIANT); both are the same app-# with the same key, so installing one over the other keeps the data. The Play bundle carries+# with the same key, so installing one over another keeps the data. The Play bundle carries# 180 px built in, like the App Store app, and every sharper quality whose folder exists as an on-demand Play asset pack# (scripts/android/make-asset-packs.mjs), which Google Play delivers when someone picks it. These# animations go into the packages and nowhere else (Gym visual licence, Part B), which is why this@@ -16,7 +17,9 @@# Usage: scripts/android/build-release.sh <keystore> <password-file> <alias-file> [out-dir]# QUALITY_ROOT the private quality folders, default /mnt/backup-hdd/opengym-media/quality# APK_PX the Standard APK's built-in size, default 180; PLAY_PX the bundle's, default 180+# PLUS_PX the Plus APK's built-in size, default 240; PLUS_PX=0 builds no Plus APK# HD_PX the HD APK's built-in size, default 360; HD_PX=0 builds no HD APK+# APK_ONLY=1 only the APKs, no Play bundle# NO_PACKS=1 a Play bundle without asset packsset -euo pipefail@@ -25,12 +28,13 @@ ROOT=$(cd "$(dirname "$0")/../.." && pwd)OUT=${4:-$PWD}QUALITY_ROOT=${QUALITY_ROOT:-/mnt/backup-hdd/opengym-media/quality}APK_PX=${APK_PX:-180}+PLUS_PX=${PLUS_PX:-240}HD_PX=${HD_PX:-360}PLAY_PX=${PLAY_PX:-180}export VITE_CLIP_EXT=webp: "${ANDROID_HOME:?set ANDROID_HOME}"BT=$(ls -d "$ANDROID_HOME"/build-tools/* | sort -V | tail -1)-for px in "$APK_PX" "$PLAY_PX" $([ "$HD_PX" != 0 ] && echo "$HD_PX"); do+for px in "$APK_PX" "$PLAY_PX" $([ "$PLUS_PX" != 0 ] && echo "$PLUS_PX") $([ "$HD_PX" != 0 ] && echo "$HD_PX"); do[ -d "$QUALITY_ROOT/$px" ] || { echo "no $QUALITY_ROOT/$px" >&2; exit 1; }done@@ -48,12 +52,18 @@ phone_build() {[ "$n" -gt 6000 ] || { echo "the $1 px phone build has only $n animations" >&2; exit 1; }}-# 1. The APKs: Standard (180 px built in) and HD (HD_PX built in), no packs.+# 1. The APKs: Standard (180 px built in), Plus (PLUS_PX) and HD (HD_PX), no packs.node "$ROOT/scripts/android/make-asset-packs.mjs" --cleanphone_build "$APK_PX" standard(cd android && ./gradlew --no-daemon clean assembleSideloadRelease)APK_BUILT="$OUT/.openGym-$VER-sideload-unsigned.apk" # beside the outputs: the root disk has no roomcp android/app/build/outputs/apk/sideload/release/app-sideload-release-unsigned.apk "$APK_BUILT"+PLUS_BUILT="$OUT/.openGym-Plus-$VER-sideload-unsigned.apk"+if [ "$PLUS_PX" != 0 ]; then+ phone_build "$PLUS_PX" plus+ (cd android && ./gradlew --no-daemon assembleSideloadRelease)+ cp android/app/build/outputs/apk/sideload/release/app-sideload-release-unsigned.apk "$PLUS_BUILT"+fiHD_BUILT="$OUT/.openGym-HD-$VER-sideload-unsigned.apk"if [ "$HD_PX" != 0 ]; thenphone_build "$HD_PX" hd@@ -61,18 +71,6 @@ if [ "$HD_PX" != 0 ]; thencp android/app/build/outputs/apk/sideload/release/app-sideload-release-unsigned.apk "$HD_BUILT"fi-# 2. The Play bundle: 180 px built in, the sharper ones as asset packs.-phone_build "$PLAY_PX"-if [ -z "${NO_PACKS:-}" ]; then- trap 'node "$ROOT/scripts/android/make-asset-packs.mjs" --clean; rm -f "$APK_BUILT" "$HD_BUILT"' EXIT- node "$ROOT/scripts/android/make-asset-packs.mjs" --builtin "$PLAY_PX" --src-root "$QUALITY_ROOT"-else- trap 'rm -f "$APK_BUILT" "$HD_BUILT"' EXIT-fi-(cd android && ./gradlew --no-daemon bundlePlayRelease)--AAB_IN=android/app/build/outputs/bundle/playRelease/app-play-release.aab-sign_apk() { # <unsigned> <name>"$BT/zipalign" -f -p 4 "$1" "$OUT/aligned.apk""$BT/apksigner" sign --ks "$KS" --ks-pass "file:$PASS" --ks-key-alias "$ALIAS" \@@ -82,7 +80,28 @@ sign_apk() { # <unsigned> <name>(cd "$OUT" && sha256sum "$2" > "$2.sha256")}sign_apk "$APK_BUILT" "openGym-$VER.apk"+[ "$PLUS_PX" = 0 ] || sign_apk "$PLUS_BUILT" "openGym-Plus-$VER.apk"[ "$HD_PX" = 0 ] || sign_apk "$HD_BUILT" "openGym-HD-$VER.apk"+(cd "$OUT" && cat openGym-*"$VER".apk.sha256 > SHA256SUMS)+++if [ -n "${APK_ONLY:-}" ]; then+ rm -f "$APK_BUILT" "$PLUS_BUILT" "$HD_BUILT"+ ls -la "$OUT"/openGym-*"$VER".apk+ exit 0+fi++# 2. The Play bundle: 180 px built in, the sharper ones as asset packs.+phone_build "$PLAY_PX"+if [ -z "${NO_PACKS:-}" ]; then+ trap 'node "$ROOT/scripts/android/make-asset-packs.mjs" --clean; rm -f "$APK_BUILT" "$PLUS_BUILT" "$HD_BUILT"' EXIT+ node "$ROOT/scripts/android/make-asset-packs.mjs" --builtin "$PLAY_PX" --src-root "$QUALITY_ROOT"+else+ trap 'rm -f "$APK_BUILT" "$PLUS_BUILT" "$HD_BUILT"' EXIT+fi+(cd android && ./gradlew --no-daemon bundlePlayRelease)++AAB_IN=android/app/build/outputs/bundle/playRelease/app-play-release.aab# An app bundle is signed like a jar; Play checks it with the upload key and re-signs the APKs# it builds from it with the app signing key.