Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be0f893f67 | ||
|
|
694e180855 | ||
|
|
65bf540ea0 | ||
| 81632a4275 |
@@ -6,54 +6,31 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
# RN/NDK builds need ~6GB and once took down the 8GB VPS — desktop runner only.
|
# Builds on Marcus's MacBook: runner label `macos`, host mode (no container),
|
||||||
# Jobs queue while the desktop is offline.
|
# using the Node, JDK 21 and Android SDK set in the runner's config.yaml.
|
||||||
runs-on: desktop
|
# Jobs queue while the laptop is asleep or offline.
|
||||||
container:
|
# (Was `desktop` + a Linux container until 2026-11-24.)
|
||||||
image: eclipse-temurin:21-jdk
|
runs-on: macos
|
||||||
steps:
|
steps:
|
||||||
# actions/checkout needs node, which this container lacks — clone directly
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
run: |
|
run: |
|
||||||
apt-get update -qq && apt-get install -y -qq git unzip curl xz-utils >/dev/null
|
|
||||||
git init -q .
|
git init -q .
|
||||||
git fetch -q --depth 1 "https://git.rehbock.xyz/${{ github.repository }}.git" "${{ github.sha }}"
|
git fetch -q --depth 1 "https://git.rehbock.xyz/${{ github.repository }}.git" "${{ github.sha }}"
|
||||||
git checkout -q FETCH_HEAD
|
git checkout -q FETCH_HEAD
|
||||||
|
|
||||||
# /root/.npm and /root/.gradle and /root/android-sdk are persistent named
|
- name: Toolchain
|
||||||
# volumes (act_runner config.yaml) — downloads below only happen on a cold cache.
|
|
||||||
- name: Install Node 22 (cached in npm volume)
|
|
||||||
run: |
|
run: |
|
||||||
NODE_DIR="$HOME/.npm/_node-v22.14.0"
|
node --version
|
||||||
if [ ! -x "$NODE_DIR/bin/node" ]; then
|
java -version 2>&1 | head -1
|
||||||
curl -sLo /tmp/node.tar.xz https://nodejs.org/dist/v22.14.0/node-v22.14.0-linux-x64.tar.xz
|
test -d "$ANDROID_HOME/platforms" && echo "Android SDK: $ANDROID_HOME"
|
||||||
mkdir -p "$NODE_DIR" && tar xJf /tmp/node.tar.xz -C "$NODE_DIR" --strip-components=1
|
|
||||||
fi
|
|
||||||
echo "$NODE_DIR/bin" >> "$GITHUB_PATH"
|
|
||||||
"$NODE_DIR/bin/node" --version
|
|
||||||
|
|
||||||
- name: npm ci
|
- name: npm ci
|
||||||
run: npm ci --no-audit --no-fund
|
run: npm ci --no-audit --no-fund
|
||||||
|
|
||||||
- name: Install Android SDK + NDK (cached volume)
|
|
||||||
run: |
|
|
||||||
SDK="$HOME/android-sdk"
|
|
||||||
SDKMAN="$SDK/cmdline-tools/latest/bin/sdkmanager"
|
|
||||||
if [ ! -x "$SDKMAN" ]; then
|
|
||||||
mkdir -p "$SDK/cmdline-tools"
|
|
||||||
curl -sLo /tmp/ct.zip https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
|
|
||||||
unzip -q /tmp/ct.zip -d /tmp
|
|
||||||
mv /tmp/cmdline-tools "$SDK/cmdline-tools/latest"
|
|
||||||
fi
|
|
||||||
yes | "$SDKMAN" --sdk_root="$SDK" --licenses >/dev/null 2>&1 || true
|
|
||||||
"$SDKMAN" --sdk_root="$SDK" \
|
|
||||||
"platform-tools" "platforms;android-36" "build-tools;36.0.0" \
|
|
||||||
"ndk;27.1.12297006" "cmake;3.22.1" >/dev/null
|
|
||||||
|
|
||||||
- name: Decode signing keystore
|
- name: Decode signing keystore
|
||||||
env:
|
env:
|
||||||
KEYSTORE_B64: ${{ secrets.KEYSTORE_B64 }}
|
KEYSTORE_B64: ${{ secrets.KEYSTORE_B64 }}
|
||||||
run: echo "$KEYSTORE_B64" | base64 -d > /tmp/release.jks
|
run: echo "$KEYSTORE_B64" | base64 -d > "$PWD/.release.jks"
|
||||||
|
|
||||||
- name: Prebuild android project
|
- name: Prebuild android project
|
||||||
env:
|
env:
|
||||||
@@ -63,13 +40,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Build signed release APK (arm64)
|
- name: Build signed release APK (arm64)
|
||||||
env:
|
env:
|
||||||
HEALTH_KEYSTORE: /tmp/release.jks
|
|
||||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||||
KEY_ALIAS: health
|
KEY_ALIAS: health
|
||||||
VERSION_CODE: ${{ github.run_number }}
|
VERSION_CODE: ${{ github.run_number }}
|
||||||
VERSION_NAME: 1.0.${{ github.run_number }}
|
VERSION_NAME: 1.0.${{ github.run_number }}
|
||||||
run: |
|
run: |
|
||||||
export ANDROID_HOME="$HOME/android-sdk"
|
export HEALTH_KEYSTORE="$PWD/.release.jks"
|
||||||
echo "sdk.dir=$ANDROID_HOME" > android/local.properties
|
echo "sdk.dir=$ANDROID_HOME" > android/local.properties
|
||||||
cd android && ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8a \
|
cd android && ./gradlew assembleRelease -PreactNativeArchitectures=arm64-v8a \
|
||||||
--no-daemon --console=plain
|
--no-daemon --console=plain
|
||||||
@@ -85,8 +61,8 @@ jobs:
|
|||||||
curl -sf -X POST "$API/releases" \
|
curl -sf -X POST "$API/releases" \
|
||||||
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"Automated build of commit ${{ github.sha }}\",\"target_commitish\":\"${{ github.sha }}\"}" \
|
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"Automated build of commit ${{ github.sha }}\",\"target_commitish\":\"${{ github.sha }}\"}" \
|
||||||
> /tmp/release.json
|
> "$PWD/.release.json"
|
||||||
RID=$(grep -o '"id":[0-9]*' /tmp/release.json | head -1 | cut -d: -f2)
|
RID=$(grep -o '"id":[0-9]*' "$PWD/.release.json" | head -1 | cut -d: -f2)
|
||||||
echo "release id: $RID"
|
echo "release id: $RID"
|
||||||
curl -sf -X POST "$API/releases/$RID/assets?name=health-app-$TAG-arm64.apk" \
|
curl -sf -X POST "$API/releases/$RID/assets?name=health-app-$TAG-arm64.apk" \
|
||||||
-H "Authorization: token $TOKEN" \
|
-H "Authorization: token $TOKEN" \
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Cross-platform (iOS + Android) Expo app — native front end for the private
|
|||||||
health dashboard at **https://health.rehbock.xyz**.
|
health dashboard at **https://health.rehbock.xyz**.
|
||||||
|
|
||||||
The app is a pure client: all data lives on the server and is fetched live over
|
The app is a pure client: all data lives on the server and is fetched live over
|
||||||
HTTPS with HTTP Basic auth. Nothing is stored on the device except the auth
|
HTTPS with a bearer API token. Nothing is stored on the device except the auth
|
||||||
token (in the platform keychain via `expo-secure-store`).
|
token (in the platform keychain via `expo-secure-store`).
|
||||||
|
|
||||||
## Screens
|
## Screens
|
||||||
@@ -30,7 +30,10 @@ npm install
|
|||||||
npx expo start # scan the QR with Expo Go (iOS or Android)
|
npx expo start # scan the QR with Expo Go (iOS or Android)
|
||||||
```
|
```
|
||||||
|
|
||||||
Log in with the same Basic-auth credentials as the website.
|
There is no login screen. Open **Settings** (⚙️ on the Today screen) and paste the API token;
|
||||||
|
without one the app has no data. The server accepts it via `HEALTH_APP_TOKEN` in
|
||||||
|
`health-auth` (`~/personal/health-auth/.env` on the VPS, passed through `docker-compose.yml`).
|
||||||
|
Rotate it by changing that value and running `docker compose up -d`.
|
||||||
|
|
||||||
## Android release APK
|
## Android release APK
|
||||||
|
|
||||||
|
|||||||
1
assets/icon-src/background.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"><defs><radialGradient id="hb" cx="50%" cy="44%" r="72%"><stop offset="0" stop-color="#1d1a33"/><stop offset="1" stop-color="#0b0b0e"/></radialGradient></defs><rect width="1024" height="1024" fill="url(#hb)"/></svg>
|
||||||
|
After Width: | Height: | Size: 306 B |
1
assets/icon-src/foreground.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"><defs><linearGradient id="pl" gradientUnits="userSpaceOnUse" x1="205.1" y1="0" x2="711.9" y2="0"><stop offset="0" stop-color="#3fc8f2"/><stop offset="0.5" stop-color="#7c6cf7"/><stop offset="1" stop-color="#f06bc0"/></linearGradient><linearGradient id="fadeg" gradientUnits="userSpaceOnUse" x1="205.1" y1="0" x2="329.0" y2="0"><stop offset="0" stop-color="#fff" stop-opacity="0.05"/><stop offset="1" stop-color="#fff"/></linearGradient><mask id="fm" maskUnits="userSpaceOnUse" x="0" y="0" width="1024" height="1024"><rect width="1024" height="1024" fill="url(#fadeg)"/></mask><filter id="bl" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="32.5"/></filter><filter id="bl2" x="-100%" y="-100%" width="300%" height="300%"><feGaussianBlur stdDeviation="53.2"/></filter><radialGradient id="dot"><stop offset="0" stop-color="#ffffff"/><stop offset="0.55" stop-color="#ffe6f4"/><stop offset="1" stop-color="#f06bc0"/></radialGradient></defs><g mask="url(#fm)" filter="url(#bl)" opacity="0.75"><path d="M205.1 530.9 L329.0 530.9 L368.4 490.7 L402.2 530.9 L430.3 530.9 L481.0 294.4 L537.3 724.9 L582.4 483.6 L610.6 530.9 L711.9 530.9" fill="none" stroke="url(#pl)" stroke-width="59.1" stroke-linecap="round" stroke-linejoin="round"/></g><circle cx="711.9" cy="530.9" r="112.4" fill="#f06bc0" opacity="0.55" filter="url(#bl2)"/><g mask="url(#fm)"><path d="M205.1 530.9 L329.0 530.9 L368.4 490.7 L402.2 530.9 L430.3 530.9 L481.0 294.4 L537.3 724.9 L582.4 483.6 L610.6 530.9 L711.9 530.9" fill="none" stroke="url(#pl)" stroke-width="59.1" stroke-linecap="round" stroke-linejoin="round"/></g><circle cx="711.9" cy="530.9" r="79.8" fill="none" stroke="#f06bc0" stroke-opacity="0.35" stroke-width="13.0"/><circle cx="711.9" cy="530.9" r="54.4" fill="url(#dot)"/></svg>
|
||||||
|
After Width: | Height: | Size: 1.8 KiB |
@@ -1,25 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
|
||||||
<defs>
|
|
||||||
<linearGradient id="heart" x1="0" y1="0" x2="1" y2="1">
|
|
||||||
<stop offset="0%" stop-color="#8a86ff"/>
|
|
||||||
<stop offset="100%" stop-color="#5b57d6"/>
|
|
||||||
</linearGradient>
|
|
||||||
</defs>
|
|
||||||
<!-- glyph only, transparent bg, scaled into the adaptive-icon safe zone -->
|
|
||||||
<g transform="translate(512 512) scale(0.62) translate(-512 -512)">
|
|
||||||
<path d="M512 812
|
|
||||||
C 402 726, 232 616, 210 462
|
|
||||||
C 196 360, 268 268, 372 268
|
|
||||||
C 436 268, 486 304, 512 356
|
|
||||||
C 538 304, 588 268, 652 268
|
|
||||||
C 756 268, 828 360, 814 462
|
|
||||||
C 792 616, 622 726, 512 812 Z"
|
|
||||||
fill="url(#heart)"/>
|
|
||||||
<polyline points="60,520 330,520 385,520 425,414 478,626 528,368 576,556 608,520 964,520"
|
|
||||||
fill="none" stroke="#0d0d0f" stroke-width="58"
|
|
||||||
stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
<polyline points="60,520 330,520 385,520 425,414 478,626 528,368 576,556 608,520 964,520"
|
|
||||||
fill="none" stroke="#ffffff" stroke-width="26"
|
|
||||||
stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -1,32 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"><defs><radialGradient id="hb" cx="50%" cy="44%" r="72%"><stop offset="0" stop-color="#1d1a33"/><stop offset="1" stop-color="#0b0b0e"/></radialGradient><linearGradient id="pl" gradientUnits="userSpaceOnUse" x1="122.9" y1="0" x2="823.3" y2="0"><stop offset="0" stop-color="#3fc8f2"/><stop offset="0.5" stop-color="#7c6cf7"/><stop offset="1" stop-color="#f06bc0"/></linearGradient><linearGradient id="fadeg" gradientUnits="userSpaceOnUse" x1="122.9" y1="0" x2="294.1" y2="0"><stop offset="0" stop-color="#fff" stop-opacity="0.05"/><stop offset="1" stop-color="#fff"/></linearGradient><mask id="fm" maskUnits="userSpaceOnUse" x="0" y="0" width="1024" height="1024"><rect width="1024" height="1024" fill="url(#fadeg)"/></mask><filter id="bl" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="44.9"/></filter><filter id="bl2" x="-100%" y="-100%" width="300%" height="300%"><feGaussianBlur stdDeviation="73.5"/></filter><radialGradient id="dot"><stop offset="0" stop-color="#ffffff"/><stop offset="0.55" stop-color="#ffe6f4"/><stop offset="1" stop-color="#f06bc0"/></radialGradient></defs><rect width="1024" height="1024" fill="url(#hb)"/><g mask="url(#fm)" filter="url(#bl)" opacity="0.75"><path d="M122.9 538.1 L294.1 538.1 L348.6 482.6 L395.3 538.1 L434.2 538.1 L504.2 211.3 L582.0 806.2 L644.3 472.8 L683.2 538.1 L823.3 538.1" fill="none" stroke="url(#pl)" stroke-width="81.7" stroke-linecap="round" stroke-linejoin="round"/></g><circle cx="823.3" cy="538.1" r="155.3" fill="#f06bc0" opacity="0.55" filter="url(#bl2)"/><g mask="url(#fm)"><path d="M122.9 538.1 L294.1 538.1 L348.6 482.6 L395.3 538.1 L434.2 538.1 L504.2 211.3 L582.0 806.2 L644.3 472.8 L683.2 538.1 L823.3 538.1" fill="none" stroke="url(#pl)" stroke-width="81.7" stroke-linecap="round" stroke-linejoin="round"/></g><circle cx="823.3" cy="538.1" r="126.7" fill="none" stroke="#f06bc0" stroke-opacity="0.35" stroke-width="18.0"/><circle cx="823.3" cy="538.1" r="75.2" fill="url(#dot)"/></svg>
|
||||||
<defs>
|
|
||||||
<radialGradient id="bg" cx="50%" cy="38%" r="75%">
|
|
||||||
<stop offset="0%" stop-color="#1e1e26"/>
|
|
||||||
<stop offset="100%" stop-color="#0d0d0f"/>
|
|
||||||
</radialGradient>
|
|
||||||
<linearGradient id="heart" x1="0" y1="0" x2="1" y2="1">
|
|
||||||
<stop offset="0%" stop-color="#8a86ff"/>
|
|
||||||
<stop offset="100%" stop-color="#5b57d6"/>
|
|
||||||
</linearGradient>
|
|
||||||
</defs>
|
|
||||||
|
|
||||||
<rect width="1024" height="1024" fill="url(#bg)"/>
|
|
||||||
|
|
||||||
<!-- heart -->
|
|
||||||
<path d="M512 812
|
|
||||||
C 402 726, 232 616, 210 462
|
|
||||||
C 196 360, 268 268, 372 268
|
|
||||||
C 436 268, 486 304, 512 356
|
|
||||||
C 538 304, 588 268, 652 268
|
|
||||||
C 756 268, 828 360, 814 462
|
|
||||||
C 792 616, 622 726, 512 812 Z"
|
|
||||||
fill="url(#heart)"/>
|
|
||||||
|
|
||||||
<!-- ECG pulse across the heart -->
|
|
||||||
<polyline points="120,520 330,520 385,520 425,414 478,626 528,368 576,556 608,520 904,520"
|
|
||||||
fill="none" stroke="#0d0d0f" stroke-width="58"
|
|
||||||
stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
<polyline points="120,520 330,520 385,520 425,414 478,626 528,368 576,556 608,520 904,520"
|
|
||||||
fill="none" stroke="#ffffff" stroke-width="26"
|
|
||||||
stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
</svg>
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 2.0 KiB |
116
assets/icon-src/make.py
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Generate the Health app icon set from one mark: a live heartbeat trace.
|
||||||
|
|
||||||
|
python3 assets/icon-src/make.py # needs `resvg` and `magick` (Homebrew)
|
||||||
|
|
||||||
|
The mark is a bold ECG trace in the dashboard's blue → violet → pink gradient
|
||||||
|
that fades in from the left and ends in a glowing "now" dot, like the live
|
||||||
|
point on a chart. The background is the app's near-black (#0d0d0f) with a
|
||||||
|
violet glow.
|
||||||
|
|
||||||
|
Writes the SVG sources next to this file and the PNGs into assets/images/:
|
||||||
|
icon.png 1024 opaque (iOS + fallback)
|
||||||
|
android-icon-background.png 1024 opaque (adaptive background)
|
||||||
|
android-icon-foreground.png 1024 alpha (adaptive foreground, inside the 66dp safe zone)
|
||||||
|
android-icon-monochrome.png 1024 alpha (themed icon, white glyph)
|
||||||
|
splash-icon.png 512 alpha (splash, glyph only)
|
||||||
|
favicon.png 64 opaque (web)
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
IMAGES = os.path.join(HERE, '..', 'images')
|
||||||
|
|
||||||
|
BG_CENTER, BG_EDGE = '#1d1a33', '#0b0b0e'
|
||||||
|
TRACE = [(0, '#3fc8f2'), (0.5, '#7c6cf7'), (1, '#f06bc0')] # blue → accent violet → pink
|
||||||
|
|
||||||
|
# x in 0..1 across the glyph, y in -1..1 (negative = up)
|
||||||
|
PULSE = [(0.00, 0), (0.22, 0), (0.29, -0.17), (0.35, 0.0), (0.40, 0),
|
||||||
|
(0.49, -1.0), (0.59, 0.82), (0.67, -0.20), (0.72, 0), (0.90, 0)]
|
||||||
|
|
||||||
|
|
||||||
|
def svg(size, body, defs=''):
|
||||||
|
return (f'<svg xmlns="http://www.w3.org/2000/svg" width="{size}" height="{size}" '
|
||||||
|
f'viewBox="0 0 {size} {size}"><defs>{defs}</defs>{body}</svg>\n')
|
||||||
|
|
||||||
|
|
||||||
|
def background(size):
|
||||||
|
defs = (f'<radialGradient id="hb" cx="50%" cy="44%" r="72%">'
|
||||||
|
f'<stop offset="0" stop-color="{BG_CENTER}"/><stop offset="1" stop-color="{BG_EDGE}"/></radialGradient>')
|
||||||
|
return defs, f'<rect width="{size}" height="{size}" fill="url(#hb)"/>'
|
||||||
|
|
||||||
|
|
||||||
|
def pulse(size, scale, mono=False, glow=True, shift=0.0, halo=1.55):
|
||||||
|
"""scale = glyph width as a fraction of the canvas."""
|
||||||
|
w = size * scale
|
||||||
|
amp, stroke = w * 0.42, w * 0.105
|
||||||
|
c = size / 2
|
||||||
|
left = c - shift * w - w / 2
|
||||||
|
pts = [(left + x * w, c + amp * 0.08 + y * amp) for x, y in PULSE]
|
||||||
|
if mono: # no fade in a single colour: start the trace later instead
|
||||||
|
pts = [(left + 0.12 * w, pts[0][1])] + pts[2:]
|
||||||
|
d = 'M' + ' L'.join(f'{x:.1f} {y:.1f}' for x, y in pts)
|
||||||
|
ex, ey = pts[-1]
|
||||||
|
line = (f'<path d="{d}" fill="none" stroke="{{s}}" stroke-width="{stroke:.1f}" '
|
||||||
|
f'stroke-linecap="round" stroke-linejoin="round"/>')
|
||||||
|
if mono:
|
||||||
|
return '', line.format(s='#fff') + f'<circle cx="{ex:.1f}" cy="{ey:.1f}" r="{stroke * 0.95:.1f}" fill="#fff"/>'
|
||||||
|
|
||||||
|
stops = ''.join(f'<stop offset="{p}" stop-color="{col}"/>' for p, col in TRACE)
|
||||||
|
defs = (f'<linearGradient id="pl" gradientUnits="userSpaceOnUse" x1="{left:.1f}" y1="0" x2="{ex:.1f}" y2="0">{stops}</linearGradient>'
|
||||||
|
f'<linearGradient id="fadeg" gradientUnits="userSpaceOnUse" x1="{left:.1f}" y1="0" x2="{left + w * 0.22:.1f}" y2="0">'
|
||||||
|
f'<stop offset="0" stop-color="#fff" stop-opacity="0.05"/><stop offset="1" stop-color="#fff"/></linearGradient>'
|
||||||
|
f'<mask id="fm" maskUnits="userSpaceOnUse" x="0" y="0" width="{size}" height="{size}">'
|
||||||
|
f'<rect width="{size}" height="{size}" fill="url(#fadeg)"/></mask>'
|
||||||
|
f'<filter id="bl" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="{stroke * 0.55:.1f}"/></filter>'
|
||||||
|
f'<filter id="bl2" x="-100%" y="-100%" width="300%" height="300%"><feGaussianBlur stdDeviation="{stroke * 0.9:.1f}"/></filter>'
|
||||||
|
f'<radialGradient id="dot"><stop offset="0" stop-color="#ffffff"/><stop offset="0.55" stop-color="#ffe6f4"/>'
|
||||||
|
f'<stop offset="1" stop-color="{TRACE[-1][1]}"/></radialGradient>')
|
||||||
|
trace = line.format(s='url(#pl)')
|
||||||
|
body = ''
|
||||||
|
if glow:
|
||||||
|
body += f'<g mask="url(#fm)" filter="url(#bl)" opacity="0.75">{trace}</g>'
|
||||||
|
body += f'<circle cx="{ex:.1f}" cy="{ey:.1f}" r="{stroke * 1.9:.1f}" fill="{TRACE[-1][1]}" opacity="0.55" filter="url(#bl2)"/>'
|
||||||
|
body += f'<g mask="url(#fm)">{trace}</g>'
|
||||||
|
body += (f'<circle cx="{ex:.1f}" cy="{ey:.1f}" r="{stroke * halo:.1f}" fill="none" stroke="{TRACE[-1][1]}" '
|
||||||
|
f'stroke-opacity="0.35" stroke-width="{stroke * 0.22:.1f}"/>')
|
||||||
|
body += f'<circle cx="{ex:.1f}" cy="{ey:.1f}" r="{stroke * 0.92:.1f}" fill="url(#dot)"/>'
|
||||||
|
return defs, body
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
bd, bb = background(1024)
|
||||||
|
# iOS: full-bleed, glyph spans 76% (Apple rounds the corners itself)
|
||||||
|
gd, gb = pulse(1024, 0.76)
|
||||||
|
sources = {
|
||||||
|
'icon': (1024, svg(1024, bb + gb, bd + gd)),
|
||||||
|
'background': (1024, svg(1024, bb, bd)),
|
||||||
|
# Android adaptive: shifted left (the trace fades in) so the dot + halo clear the 66dp safe circle
|
||||||
|
'foreground': (1024, svg(1024, *reversed(pulse(1024, 0.55, shift=0.045, halo=1.35)))),
|
||||||
|
# themed icons read best a little smaller than the colour glyph
|
||||||
|
'monochrome': (1024, svg(1024, *reversed(pulse(1024, 0.46, mono=True, glow=False, shift=0.045)))),
|
||||||
|
'splash': (512, svg(512, *reversed(pulse(512, 0.94, glow=False)))),
|
||||||
|
}
|
||||||
|
out = {
|
||||||
|
'icon': 'icon.png', 'background': 'android-icon-background.png',
|
||||||
|
'foreground': 'android-icon-foreground.png', 'monochrome': 'android-icon-monochrome.png',
|
||||||
|
'splash': 'splash-icon.png',
|
||||||
|
}
|
||||||
|
for name, (size, text) in sources.items():
|
||||||
|
src = os.path.join(HERE, f'{name}.svg')
|
||||||
|
with open(src, 'w') as f:
|
||||||
|
f.write(text)
|
||||||
|
png = os.path.join(IMAGES, out[name])
|
||||||
|
subprocess.run(['resvg', '-w', str(size), '-h', str(size), src, png], check=True)
|
||||||
|
# iOS rejects icons with an alpha channel; the web favicon is the icon at 64px
|
||||||
|
icon = os.path.join(IMAGES, 'icon.png')
|
||||||
|
subprocess.run(['magick', icon, '-background', BG_EDGE, '-alpha', 'remove', '-alpha', 'off', icon], check=True)
|
||||||
|
bgp = os.path.join(IMAGES, 'android-icon-background.png')
|
||||||
|
subprocess.run(['magick', bgp, '-alpha', 'off', bgp], check=True)
|
||||||
|
subprocess.run(['magick', icon, '-resize', '64x64', os.path.join(IMAGES, 'favicon.png')], check=True)
|
||||||
|
print('wrote', ', '.join(out.values()), 'favicon.png')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -1,21 +1 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"><defs></defs><path d="M311.8 527.8 L391.9 494.2 L420.1 527.8 L443.7 527.8 L486.1 330.0 L533.2 690.1 L570.9 488.3 L594.4 527.8 L679.2 527.8" fill="none" stroke="#fff" stroke-width="49.5" stroke-linecap="round" stroke-linejoin="round"/><circle cx="679.2" cy="527.8" r="47.0" fill="#fff"/></svg>
|
||||||
<defs>
|
|
||||||
<mask id="cut">
|
|
||||||
<rect width="1024" height="1024" fill="white"/>
|
|
||||||
<polyline points="60,520 330,520 385,520 425,414 478,626 528,368 576,556 608,520 964,520"
|
|
||||||
fill="none" stroke="black" stroke-width="58"
|
|
||||||
stroke-linecap="round" stroke-linejoin="round"/>
|
|
||||||
</mask>
|
|
||||||
</defs>
|
|
||||||
<!-- single-silhouette version: heart with the ECG line cut out (launcher tints it) -->
|
|
||||||
<g transform="translate(512 512) scale(0.62) translate(-512 -512)">
|
|
||||||
<path d="M512 812
|
|
||||||
C 402 726, 232 616, 210 462
|
|
||||||
C 196 360, 268 268, 372 268
|
|
||||||
C 436 268, 486 304, 512 356
|
|
||||||
C 538 304, 588 268, 652 268
|
|
||||||
C 756 268, 828 360, 814 462
|
|
||||||
C 792 616, 622 726, 512 812 Z"
|
|
||||||
fill="#ffffff" mask="url(#cut)"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 881 B After Width: | Height: | Size: 384 B |
1
assets/icon-src/splash.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><defs><linearGradient id="pl" gradientUnits="userSpaceOnUse" x1="15.4" y1="0" x2="448.5" y2="0"><stop offset="0" stop-color="#3fc8f2"/><stop offset="0.5" stop-color="#7c6cf7"/><stop offset="1" stop-color="#f06bc0"/></linearGradient><linearGradient id="fadeg" gradientUnits="userSpaceOnUse" x1="15.4" y1="0" x2="121.2" y2="0"><stop offset="0" stop-color="#fff" stop-opacity="0.05"/><stop offset="1" stop-color="#fff"/></linearGradient><mask id="fm" maskUnits="userSpaceOnUse" x="0" y="0" width="512" height="512"><rect width="512" height="512" fill="url(#fadeg)"/></mask><filter id="bl" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="27.8"/></filter><filter id="bl2" x="-100%" y="-100%" width="300%" height="300%"><feGaussianBlur stdDeviation="45.5"/></filter><radialGradient id="dot"><stop offset="0" stop-color="#ffffff"/><stop offset="0.55" stop-color="#ffe6f4"/><stop offset="1" stop-color="#f06bc0"/></radialGradient></defs><g mask="url(#fm)"><path d="M15.4 272.2 L121.2 272.2 L154.9 237.8 L183.8 272.2 L207.9 272.2 L251.2 70.0 L299.3 437.9 L337.8 231.7 L361.9 272.2 L448.5 272.2" fill="none" stroke="url(#pl)" stroke-width="50.5" stroke-linecap="round" stroke-linejoin="round"/></g><circle cx="448.5" cy="272.2" r="78.3" fill="none" stroke="#f06bc0" stroke-opacity="0.35" stroke-width="11.1"/><circle cx="448.5" cy="272.2" r="46.5" fill="url(#dot)"/></svg>
|
||||||
|
After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 451 B After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 249 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 245 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 21 KiB |
@@ -4,12 +4,10 @@ import React from 'react';
|
|||||||
import { View } from 'react-native';
|
import { View } from 'react-native';
|
||||||
import { AuthProvider, useAuth } from '../lib/api';
|
import { AuthProvider, useAuth } from '../lib/api';
|
||||||
import { C } from '../lib/theme';
|
import { C } from '../lib/theme';
|
||||||
import { LoginScreen } from '../components/login';
|
|
||||||
|
|
||||||
function Gate() {
|
function Gate() {
|
||||||
const { ready, authed } = useAuth();
|
const { ready } = useAuth();
|
||||||
if (!ready) return <View style={{ flex: 1, backgroundColor: C.bg }} />;
|
if (!ready) return <View style={{ flex: 1, backgroundColor: C.bg }} />;
|
||||||
if (!authed) return <LoginScreen />;
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
screenOptions={{
|
screenOptions={{
|
||||||
@@ -27,6 +25,7 @@ function Gate() {
|
|||||||
<Stack.Screen name="body" options={{ title: 'Body Composition' }} />
|
<Stack.Screen name="body" options={{ title: 'Body Composition' }} />
|
||||||
<Stack.Screen name="mind" options={{ title: 'Meditation' }} />
|
<Stack.Screen name="mind" options={{ title: 'Meditation' }} />
|
||||||
<Stack.Screen name="dna" options={{ title: 'Genetic Traits' }} />
|
<Stack.Screen name="dna" options={{ title: 'Genetic Traits' }} />
|
||||||
|
<Stack.Screen name="settings" options={{ title: 'Settings' }} />
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Stack } from 'expo-router';
|
import { Link, Stack } from 'expo-router';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Alert, Pressable, Text, View } from 'react-native';
|
import { Text, View } from 'react-native';
|
||||||
import { NavCard, PriorityCard, Screen, Sec } from '../components/ui';
|
import { NavCard, PriorityCard, Screen, Sec } from '../components/ui';
|
||||||
import { useAuth } from '../lib/api';
|
import { useAuth } from '../lib/api';
|
||||||
import { agoTxt, fmtD, fmtDY, hm, num, cap } from '../lib/format';
|
import { agoTxt, fmtD, fmtDY, hm, num, cap } from '../lib/format';
|
||||||
@@ -13,7 +13,7 @@ import type {
|
|||||||
import { loadAll, useLoad } from '../lib/use-load';
|
import { loadAll, useLoad } from '../lib/use-load';
|
||||||
|
|
||||||
export default function Today() {
|
export default function Today() {
|
||||||
const { logout } = useAuth();
|
const { hasToken } = useAuth();
|
||||||
const { data, loading, refresh } = useLoad(() =>
|
const { data, loading, refresh } = useLoad(() =>
|
||||||
loadAll({
|
loadAll({
|
||||||
meta: 'meta', bio: 'biomarkers', wo: 'workouts', sApi: 'sleepApi',
|
meta: 'meta', bio: 'biomarkers', wo: 'workouts', sApi: 'sleepApi',
|
||||||
@@ -120,16 +120,9 @@ export default function Today() {
|
|||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<Pressable
|
<Link href="/settings">
|
||||||
hitSlop={10}
|
<Text style={{ fontSize: 18, padding: 6 }}>⚙️</Text>
|
||||||
onPress={() =>
|
</Link>
|
||||||
Alert.alert('Lock the dashboard?', 'You will need the password to get back in.', [
|
|
||||||
{ text: 'Cancel', style: 'cancel' },
|
|
||||||
{ text: 'Lock', style: 'destructive', onPress: logout },
|
|
||||||
])
|
|
||||||
}>
|
|
||||||
<Text style={{ fontSize: 16 }}>🔒</Text>
|
|
||||||
</Pressable>
|
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -139,7 +132,11 @@ export default function Today() {
|
|||||||
weekday: 'long', month: 'long', day: 'numeric',
|
weekday: 'long', month: 'long', day: 'numeric',
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
{loading && !r ? (
|
{!hasToken ? (
|
||||||
|
<Link href="/settings" style={{ padding: 24, textAlign: 'center', color: C.accent, fontSize: 15 }}>
|
||||||
|
Add your API token in Settings to load your data →
|
||||||
|
</Link>
|
||||||
|
) : loading && !r ? (
|
||||||
<Text style={{ color: C.muted, fontSize: 13, textAlign: 'center', padding: 24 }}>
|
<Text style={{ color: C.muted, fontSize: 13, textAlign: 'center', padding: 24 }}>
|
||||||
Loading…
|
Loading…
|
||||||
</Text>
|
</Text>
|
||||||
|
|||||||
74
src/app/settings.tsx
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
|
||||||
|
import { Screen } from '../components/ui';
|
||||||
|
import { BASE, useAuth } from '../lib/api';
|
||||||
|
import { C } from '../lib/theme';
|
||||||
|
|
||||||
|
export default function Settings() {
|
||||||
|
const { hasToken, saveToken, clearToken } = useAuth();
|
||||||
|
const [value, setValue] = useState('');
|
||||||
|
const [msg, setMsg] = useState('');
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
|
const save = async () => {
|
||||||
|
setBusy(true);
|
||||||
|
setMsg('');
|
||||||
|
try {
|
||||||
|
if (await saveToken(value)) {
|
||||||
|
setValue('');
|
||||||
|
setMsg('Saved.');
|
||||||
|
} else setMsg('The server rejected that token.');
|
||||||
|
} catch {
|
||||||
|
setMsg('Network error — are you online?');
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Screen>
|
||||||
|
<Text style={s.lbl}>SERVER</Text>
|
||||||
|
<Text style={s.val}>{BASE}</Text>
|
||||||
|
<Text style={s.lbl}>API TOKEN {hasToken ? '· saved' : '· not set'}</Text>
|
||||||
|
<TextInput
|
||||||
|
style={s.input}
|
||||||
|
value={value}
|
||||||
|
onChangeText={setValue}
|
||||||
|
placeholder={hasToken ? '•••••••• (enter a new one to replace)' : 'Paste your API token'}
|
||||||
|
placeholderTextColor={C.dim}
|
||||||
|
autoCapitalize="none"
|
||||||
|
autoCorrect={false}
|
||||||
|
secureTextEntry
|
||||||
|
onSubmitEditing={save}
|
||||||
|
returnKeyType="done"
|
||||||
|
/>
|
||||||
|
<Pressable
|
||||||
|
style={[s.go, (busy || !value.trim()) && { opacity: 0.5 }]}
|
||||||
|
disabled={busy || !value.trim()}
|
||||||
|
onPress={save}>
|
||||||
|
<Text style={s.goTxt}>Save token</Text>
|
||||||
|
</Pressable>
|
||||||
|
{hasToken ? (
|
||||||
|
<Pressable style={s.clear} onPress={clearToken}>
|
||||||
|
<Text style={{ color: C.red, fontSize: 14 }}>Remove token from this device</Text>
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
<View style={{ minHeight: 24 }}>
|
||||||
|
<Text style={s.msg}>{msg}</Text>
|
||||||
|
</View>
|
||||||
|
</Screen>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const s = StyleSheet.create({
|
||||||
|
lbl: { fontSize: 11, color: C.muted, letterSpacing: 0.5, marginTop: 16, marginBottom: 6 },
|
||||||
|
val: { fontSize: 15, color: C.text },
|
||||||
|
input: {
|
||||||
|
paddingVertical: 11, paddingHorizontal: 12, borderRadius: 10, borderWidth: 1,
|
||||||
|
borderColor: C.border, backgroundColor: C.surface2, color: C.text, fontSize: 15,
|
||||||
|
},
|
||||||
|
go: { marginTop: 16, padding: 12, borderRadius: 10, backgroundColor: C.accent, alignItems: 'center' },
|
||||||
|
goTxt: { color: '#fff', fontWeight: '600', fontSize: 15 },
|
||||||
|
clear: { marginTop: 20, alignItems: 'center', padding: 8 },
|
||||||
|
msg: { marginTop: 12, fontSize: 12.5, color: C.muted },
|
||||||
|
});
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
|
||||||
KeyboardAvoidingView, Platform, Pressable, StyleSheet, Text, TextInput, View,
|
|
||||||
} from 'react-native';
|
|
||||||
import { useAuth } from '../lib/api';
|
|
||||||
import { C } from '../lib/theme';
|
|
||||||
|
|
||||||
export function LoginScreen() {
|
|
||||||
const { login } = useAuth();
|
|
||||||
const [user, setUser] = useState('admin');
|
|
||||||
const [pass, setPass] = useState('');
|
|
||||||
const [err, setErr] = useState('');
|
|
||||||
const [busy, setBusy] = useState(false);
|
|
||||||
|
|
||||||
const go = async () => {
|
|
||||||
setBusy(true);
|
|
||||||
setErr('');
|
|
||||||
try {
|
|
||||||
const ok = await login(user.trim(), pass);
|
|
||||||
if (!ok) setErr('Wrong password.');
|
|
||||||
else setPass('');
|
|
||||||
} catch {
|
|
||||||
setErr('Network error — are you online?');
|
|
||||||
} finally {
|
|
||||||
setBusy(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<KeyboardAvoidingView
|
|
||||||
style={s.wrap}
|
|
||||||
behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
|
|
||||||
<View style={s.card}>
|
|
||||||
<Text style={{ fontSize: 34, marginBottom: 10 }}>⚕️</Text>
|
|
||||||
<Text style={s.h1}>Health Dashboard</Text>
|
|
||||||
<Text style={s.sub}>health.rehbock.xyz — private</Text>
|
|
||||||
<Text style={s.lbl}>USER</Text>
|
|
||||||
<TextInput
|
|
||||||
style={s.input}
|
|
||||||
value={user}
|
|
||||||
onChangeText={setUser}
|
|
||||||
autoCapitalize="none"
|
|
||||||
autoCorrect={false}
|
|
||||||
textContentType="username"
|
|
||||||
/>
|
|
||||||
<Text style={s.lbl}>PASSWORD</Text>
|
|
||||||
<TextInput
|
|
||||||
style={s.input}
|
|
||||||
value={pass}
|
|
||||||
onChangeText={setPass}
|
|
||||||
secureTextEntry
|
|
||||||
textContentType="password"
|
|
||||||
onSubmitEditing={go}
|
|
||||||
returnKeyType="go"
|
|
||||||
/>
|
|
||||||
<Pressable style={[s.go, busy && { opacity: 0.5 }]} disabled={busy} onPress={go}>
|
|
||||||
<Text style={{ color: '#fff', fontWeight: '600', fontSize: 15 }}>Unlock</Text>
|
|
||||||
</Pressable>
|
|
||||||
<Text style={s.err}>{err}</Text>
|
|
||||||
</View>
|
|
||||||
</KeyboardAvoidingView>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const s = StyleSheet.create({
|
|
||||||
wrap: {
|
|
||||||
flex: 1, backgroundColor: C.bg, alignItems: 'center', justifyContent: 'center', padding: 24,
|
|
||||||
},
|
|
||||||
card: {
|
|
||||||
width: '100%', maxWidth: 340, backgroundColor: C.surface, borderWidth: 1,
|
|
||||||
borderColor: C.border, borderRadius: 16, paddingVertical: 28, paddingHorizontal: 24,
|
|
||||||
},
|
|
||||||
h1: { fontSize: 18, fontWeight: '600', color: C.text, marginBottom: 4 },
|
|
||||||
sub: { fontSize: 12, color: C.muted, marginBottom: 20 },
|
|
||||||
lbl: { fontSize: 11, color: C.muted, letterSpacing: 0.5, marginTop: 12, marginBottom: 5 },
|
|
||||||
input: {
|
|
||||||
paddingVertical: 11, paddingHorizontal: 12, borderRadius: 10, borderWidth: 1,
|
|
||||||
borderColor: C.border, backgroundColor: C.surface2, color: C.text, fontSize: 15,
|
|
||||||
},
|
|
||||||
go: {
|
|
||||||
marginTop: 20, padding: 12, borderRadius: 10, backgroundColor: C.accent, alignItems: 'center',
|
|
||||||
},
|
|
||||||
err: { marginTop: 12, fontSize: 12.5, color: C.red, minHeight: 18 },
|
|
||||||
});
|
|
||||||
@@ -22,62 +22,33 @@ export const FITBIT_SYNC_URL = `${BASE}/api/health/v1/fitbit/sync`;
|
|||||||
|
|
||||||
/* authenticated POST (fitbit sync) */
|
/* authenticated POST (fitbit sync) */
|
||||||
export async function postJson<T>(url: string, body: unknown): Promise<T> {
|
export async function postJson<T>(url: string, body: unknown): Promise<T> {
|
||||||
|
if (!token) throw new Error(NO_TOKEN);
|
||||||
const r = await fetch(url, {
|
const r = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { Authorization: 'Basic ' + token, 'Content-Type': 'application/json' },
|
headers: { Authorization: 'Bearer ' + token, 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
if (r.status === 401 || r.status === 403) {
|
if (r.status === 401 || r.status === 403) throw new Error(BAD_TOKEN);
|
||||||
onUnauthorized?.();
|
|
||||||
throw new Error('unauthorized');
|
|
||||||
}
|
|
||||||
if (!r.ok) throw new Error(`${url} → ${r.status}`);
|
if (!r.ok) throw new Error(`${url} → ${r.status}`);
|
||||||
return r.json();
|
return r.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EpKey = keyof typeof EP;
|
export type EpKey = keyof typeof EP;
|
||||||
|
|
||||||
const AUTH_KEY = 'hd.auth';
|
const AUTH_KEY = 'hd.token';
|
||||||
|
|
||||||
|
export const NO_TOKEN = 'No API token — add one in Settings.';
|
||||||
|
export const BAD_TOKEN = 'API token rejected — check it in Settings.';
|
||||||
|
|
||||||
let token: string | null = null;
|
let token: string | null = null;
|
||||||
let onUnauthorized: (() => void) | null = null;
|
|
||||||
|
|
||||||
/* base64 without Buffer/btoa dependency quirks across Hermes versions */
|
|
||||||
const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
||||||
export function b64(str: string): string {
|
|
||||||
const bytes: number[] = [];
|
|
||||||
for (let i = 0; i < str.length; i++) {
|
|
||||||
const code = str.codePointAt(i)!;
|
|
||||||
if (code > 0xffff) i++;
|
|
||||||
if (code < 0x80) bytes.push(code);
|
|
||||||
else if (code < 0x800) bytes.push(0xc0 | (code >> 6), 0x80 | (code & 63));
|
|
||||||
else if (code < 0x10000)
|
|
||||||
bytes.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 63), 0x80 | (code & 63));
|
|
||||||
else
|
|
||||||
bytes.push(
|
|
||||||
0xf0 | (code >> 18), 0x80 | ((code >> 12) & 63),
|
|
||||||
0x80 | ((code >> 6) & 63), 0x80 | (code & 63),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
let out = '';
|
|
||||||
for (let i = 0; i < bytes.length; i += 3) {
|
|
||||||
const [a, b, c] = [bytes[i], bytes[i + 1], bytes[i + 2]];
|
|
||||||
out += B64[a >> 2] + B64[((a & 3) << 4) | (b ?? 0) >> 4];
|
|
||||||
out += b === undefined ? '=' : B64[((b & 15) << 2) | (c ?? 0) >> 6];
|
|
||||||
out += c === undefined ? '=' : B64[c & 63];
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function authFetch<T>(url: string): Promise<T> {
|
async function authFetch<T>(url: string): Promise<T> {
|
||||||
|
if (!token) throw new Error(NO_TOKEN);
|
||||||
const r = await fetch(url, {
|
const r = await fetch(url, {
|
||||||
headers: { Authorization: 'Basic ' + token },
|
headers: { Authorization: 'Bearer ' + token },
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
});
|
});
|
||||||
if (r.status === 401 || r.status === 403) {
|
if (r.status === 401 || r.status === 403) throw new Error(BAD_TOKEN);
|
||||||
onUnauthorized?.();
|
|
||||||
throw new Error('unauthorized');
|
|
||||||
}
|
|
||||||
if (!r.ok) throw new Error(`${url} → ${r.status}`);
|
if (!r.ok) throw new Error(`${url} → ${r.status}`);
|
||||||
return r.json();
|
return r.json();
|
||||||
}
|
}
|
||||||
@@ -98,66 +69,67 @@ export function clearCache() {
|
|||||||
cache = {};
|
cache = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* drop specific endpoints from the cache so the next load() refetches */
|
||||||
|
export function invalidate(...keys: EpKey[]) {
|
||||||
|
for (const k of keys) delete cache[k];
|
||||||
|
}
|
||||||
|
|
||||||
/* ---- auth context ---- */
|
/* ---- auth context ---- */
|
||||||
|
|
||||||
interface AuthCtx {
|
interface AuthCtx {
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
authed: boolean;
|
/** an API token is stored (it may still be rejected by the server) */
|
||||||
login: (user: string, pass: string) => Promise<boolean>;
|
hasToken: boolean;
|
||||||
logout: () => void;
|
/** verify against the server, then store; false = server rejected it */
|
||||||
|
saveToken: (t: string) => Promise<boolean>;
|
||||||
|
clearToken: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Ctx = createContext<AuthCtx>({
|
const Ctx = createContext<AuthCtx>({
|
||||||
ready: false,
|
ready: false,
|
||||||
authed: false,
|
hasToken: false,
|
||||||
login: async () => false,
|
saveToken: async () => false,
|
||||||
logout: () => {},
|
clearToken: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useAuth = () => useContext(Ctx);
|
export const useAuth = () => useContext(Ctx);
|
||||||
|
|
||||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState(false);
|
||||||
const [authed, setAuthed] = useState(false);
|
const [hasToken, setHasToken] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
SecureStore.getItemAsync(AUTH_KEY)
|
SecureStore.getItemAsync(AUTH_KEY)
|
||||||
.then((t) => {
|
.then((t) => {
|
||||||
if (t) {
|
if (t) {
|
||||||
token = t;
|
token = t;
|
||||||
setAuthed(true);
|
setHasToken(true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.catch(() => {})
|
||||||
.finally(() => setReady(true));
|
.finally(() => setReady(true));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const logout = useCallback(() => {
|
const clearToken = useCallback(() => {
|
||||||
token = null;
|
token = null;
|
||||||
clearCache();
|
clearCache();
|
||||||
SecureStore.deleteItemAsync(AUTH_KEY).catch(() => {});
|
SecureStore.deleteItemAsync(AUTH_KEY).catch(() => {});
|
||||||
setAuthed(false);
|
setHasToken(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
const saveToken = useCallback(async (raw: string) => {
|
||||||
onUnauthorized = logout;
|
const t = raw.trim();
|
||||||
return () => {
|
|
||||||
onUnauthorized = null;
|
|
||||||
};
|
|
||||||
}, [logout]);
|
|
||||||
|
|
||||||
const login = useCallback(async (user: string, pass: string) => {
|
|
||||||
const tok = b64(`${user}:${pass}`);
|
|
||||||
const r = await fetch(EP.meta, {
|
const r = await fetch(EP.meta, {
|
||||||
headers: { Authorization: 'Basic ' + tok },
|
headers: { Authorization: 'Bearer ' + t },
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
});
|
});
|
||||||
if (!r.ok) return false;
|
if (!r.ok) return false;
|
||||||
token = tok;
|
token = t;
|
||||||
clearCache();
|
clearCache();
|
||||||
await SecureStore.setItemAsync(AUTH_KEY, tok);
|
await SecureStore.setItemAsync(AUTH_KEY, t);
|
||||||
setAuthed(true);
|
setHasToken(true);
|
||||||
return true;
|
return true;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return <Ctx.Provider value={{ ready, authed, login, logout }}>{children}</Ctx.Provider>;
|
return <Ctx.Provider value={{ ready, hasToken, saveToken, clearToken }}>{children}</Ctx.Provider>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Android-only: react-native-health-connect is loaded lazily so the module's
|
Android-only: react-native-health-connect is loaded lazily so the module's
|
||||||
absence (iOS, Expo Go) never crashes the app. */
|
absence (iOS, Expo Go) never crashes the app. */
|
||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
import { FITBIT_SYNC_URL, load, postJson } from './api';
|
import { FITBIT_SYNC_URL, invalidate, load, postJson } from './api';
|
||||||
|
|
||||||
export interface SyncResult {
|
export interface SyncResult {
|
||||||
ok: boolean;
|
ok: boolean;
|
||||||
@@ -90,6 +90,7 @@ export async function syncFitbit(onProgress?: (msg: string) => void): Promise<Sy
|
|||||||
await requestPermission(READ_PERMISSIONS.map((r) => ({ accessType: 'read', recordType: r })));
|
await requestPermission(READ_PERMISSIONS.map((r) => ({ accessType: 'read', recordType: r })));
|
||||||
|
|
||||||
say('Checking server watermark…');
|
say('Checking server watermark…');
|
||||||
|
invalidate('fitbitLatest'); // watermark must be fresh, never the session-cached copy
|
||||||
const latest = await load<{
|
const latest = await load<{
|
||||||
samples: Record<string, string | null>;
|
samples: Record<string, string | null>;
|
||||||
daily: Record<string, string | null>;
|
daily: Record<string, string | null>;
|
||||||
@@ -182,6 +183,9 @@ export async function syncFitbit(onProgress?: (msg: string) => void): Promise<Sy
|
|||||||
ns += res.samples; nd += res.daily; nl += res.sleep;
|
ns += res.samples; nd += res.daily; nl += res.sleep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// new rows exist server-side — cached copies of these are now stale
|
||||||
|
invalidate('fitbitSummary', 'fitbitLatest');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ok: true, samples: ns, daily: nd, sleep: nl,
|
ok: true, samples: ns, daily: nd, sleep: nl,
|
||||||
message: `Synced ${ns} samples, ${nd} daily rows, ${nl} sleep sessions`,
|
message: `Synced ${ns} samples, ${nd} daily rows, ${nl} sleep sessions`,
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ export function useLoad<T>(fn: () => Promise<T>): LoadState<T> & { refresh: () =
|
|||||||
.then((data) => live && setState({ data, loading: false }))
|
.then((data) => live && setState({ data, loading: false }))
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
if (!live) return;
|
if (!live) return;
|
||||||
const msg = e instanceof Error ? e.message : String(e);
|
setState({ err: e instanceof Error ? e.message : String(e), loading: false });
|
||||||
if (msg !== 'unauthorized') setState({ err: msg, loading: false });
|
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
live = false;
|
live = false;
|
||||||
|
|||||||