Skip to content

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.

Phone app: a first-start step for notifications

Duarte Santosa9f3c715f0ca
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index e63f3466e..813efcd0e 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -29,6 +29,7 @@ import TimerFlash from './components/TimerFlash.jsx'
import { openDeviceLinkRedeem } from './components/Passkeys.jsx'
import Login from './views/Login.jsx'
import MobileOnboarding from './views/MobileOnboarding.jsx'
+import PermissionSteps from './views/PermissionSteps.jsx'
import Home from './views/Home.jsx'
import CheckIn from './views/CheckIn.jsx'
import Plan from './views/Plan.jsx'
@@ -83,6 +84,7 @@ function Shell() {
useEffect(() => { if (MOBILE) nativePlatform().then(p => { if (p === 'ios') setNativeBuzzer(buzzAsAlarm) }) }, [])
const isGuest = useStore(s => s.isGuest())
const needsMobileOnboarding = useStore(s => s.needsMobileOnboarding)
+ const permSteps = useStore(s => s.permSteps)
const langV = useLang() // re-renders the whole shell when the language (pack) changes
useEffect(() => { setNav(navigate) }, [navigate])
const lastEditPath = useRef(loc.pathname)
@@ -187,7 +189,7 @@ function Shell() {
}, [inWorkout])
// The chat owns the bottom of the screen as well: its composer sits where the tabs would be.
// The first-launch card has no tabs either: they changed the route behind it.
- const noTabs = inWorkout || loc.pathname === '/coach' || needsMobileOnboarding
+ const noTabs = inWorkout || loc.pathname === '/coach' || needsMobileOnboarding || permSteps
const authed = user || isGuest
if (!ready && !authed) return (
@@ -204,7 +206,7 @@ function Shell() {
re-mounts the boundary, so the tab bar is always a way out */}
<div id="app" className="vfade" key={loc.pathname}>
<ErrorBoundary>
- {!authed ? <Login /> : needsMobileOnboarding ? <MobileOnboarding /> : (
+ {!authed ? <Login /> : needsMobileOnboarding ? <MobileOnboarding /> : permSteps ? <PermissionSteps /> : (
<Routes>
<Route path="/home" element={<Home />} />
{/* Gym check-in — switched off in Settings, the route falls through to the
diff --git a/frontend/src/lib/onboarding-perms.js b/frontend/src/lib/onboarding-perms.js
new file mode 100644
index 000000000..d2d92c2e6
--- /dev/null
+++ b/frontend/src/lib/onboarding-perms.js
@@ -0,0 +1,49 @@
+// The phone app's first-start permission steps: right after "Use on this device" or a finished
+// pairing, one short screen per thing the OS has to be asked about, each with Allow / Not now
+// (views/PermissionSteps.jsx renders them). The OS dialog alone says nothing about why; asked
+// cold, mid-rest, people tap "Don't allow" and the rest timer never reaches the lock screen.
+//
+// A step is { id, state(), request() }. state() answers 'prompt' when there is something to
+// ask, anything else ('granted', 'denied', 'unsupported') skips the step: never a screen for a
+// permission already given, nor for one the OS will not show a dialog for any more. Each step is
+// shown once per device, whatever the answer; "Not now" leaves the in-context ask (the first
+// rest, the reminder switch) to do its job later. Apple Health / Health Connect can join the
+// list as another step without the screen changing.
+import { MOBILE } from './mobile.js'
+import { askNotifPermissionOnce } from './rest-alert.js'
+
+export const SEEN_KEY = 'gym_onboard_perms_seen'
+
+const readSeen = () => { try { return JSON.parse(localStorage.getItem(SEEN_KEY)) || [] } catch { return [] } }
+export function markStepSeen(id) {
+ const seen = readSeen()
+ if (seen.includes(id)) return
+ try { localStorage.setItem(SEEN_KEY, JSON.stringify([...seen, id])) } catch { /* shown again next first start, which is rare */ }
+}
+
+async function notificationState() {
+ try {
+ const { LocalNotifications } = await import('@capacitor/local-notifications')
+ const p = await LocalNotifications.checkPermissions()
+ return p.display === 'granted' ? 'granted' : p.display === 'denied' ? 'denied' : 'prompt'
+ } catch { return 'unsupported' }
+}
+
+export const STEPS = [
+ // The same request the first rest makes (rest-alert.js): it asks through LocalNotifications,
+ // which is POST_NOTIFICATIONS on Android 13+ and the usual alert on iOS, and records the
+ // answer so the first rest does not ask a second time.
+ { id: 'notifications', state: notificationState, request: () => askNotifPermissionOnce() },
+]
+
+/** The steps this device still has to see, in order. Empty off the phone app. */
+export async function pendingSteps(steps = STEPS, mobile = MOBILE) {
+ if (!mobile) return []
+ const seen = readSeen()
+ const out = []
+ for (const s of steps) {
+ if (seen.includes(s.id)) continue
+ if ((await s.state().catch(() => 'unsupported')) === 'prompt') out.push(s)
+ }
+ return out
+}
diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.js
index 35c57bcf8..71af7dd40 100644
--- a/frontend/src/locales/ar.js
+++ b/frontend/src/locales/ar.js
@@ -2322,4 +2322,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'خطتك: الروتينات والتمارين والمجموعات والتكرارات والجدول',
'Your unit and language': 'وحدتك ولغتك',
'Your workouts: weights, reps, times, effort and session notes': 'تمارينك: الأوزان والتكرارات والأوقات والجهد وملاحظات الجلسة',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'لا تفوّت نهاية الراحة أبدًا',
+ 'One quick thing': 'شيء سريع واحد',
+ 'Rest timer, right on the lock screen': 'مؤقت الراحة مباشرة على شاشة القفل',
+ 'Training reminders, only if you switch them on': 'تذكيرات التمرين، فقط إذا فعّلتها',
+ 'You can change it anytime in your phone’s settings.': 'يمكنك تغيير ذلك في أي وقت من إعدادات هاتفك.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'يمكن لـ openGym أن ينقر على كتفك عند انتهاء الراحة، حتى والهاتف مقفل في جيبك.',
}
diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.js
index 9bd0691bf..4994d29bb 100644
--- a/frontend/src/locales/bn.js
+++ b/frontend/src/locales/bn.js
@@ -2346,4 +2346,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'আপনার প্ল্যান: রুটিন, ব্যায়াম, সেট, রেপ ও সময়সূচি',
'Your unit and language': 'আপনার একক ও ভাষা',
'Your workouts: weights, reps, times, effort and session notes': 'আপনার ওয়ার্কআউট: ওজন, রেপ, সময়, পরিশ্রম ও সেশনের নোট',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'বিশ্রামের শেষ আর কখনো মিস করবেন না',
+ 'One quick thing': 'ছোট্ট একটা কথা',
+ 'Rest timer, right on the lock screen': 'বিশ্রামের টাইমার, সরাসরি লক স্ক্রিনে',
+ 'Training reminders, only if you switch them on': 'ট্রেনিংয়ের রিমাইন্ডার, শুধু আপনি চালু করলে',
+ 'You can change it anytime in your phone’s settings.': 'ফোনের সেটিংসে যেকোনো সময় এটি বদলাতে পারেন।',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'ফোন লক করে পকেটে রাখলেও, বিশ্রাম শেষ হলে openGym আপনার কাঁধে টোকা দিতে পারে।',
}
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index 3316b48e5..04b1eaa55 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -2287,4 +2287,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'Dein Plan: Routinen, Übungen, Sätze, Wiederholungen und Wochenplan',
'Your unit and language': 'Deine Einheit und Sprache',
'Your workouts: weights, reps, times, effort and session notes': 'Deine Workouts: Gewichte, Wiederholungen, Zeiten, Anstrengung und Notizen',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Verpass nie das Ende einer Pause',
+ 'One quick thing': 'Kurz noch eins',
+ 'Rest timer, right on the lock screen': 'Pausentimer direkt auf dem Sperrbildschirm',
+ 'Training reminders, only if you switch them on': 'Trainingserinnerungen, nur wenn du sie einschaltest',
+ 'You can change it anytime in your phone’s settings.': 'Du kannst das jederzeit in den Einstellungen deines Handys ändern.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'openGym tippt dir auf die Schulter, wenn eine Pause vorbei ist, auch wenn das Handy gesperrt in der Tasche steckt.',
}
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index faa59bbda..1e824b0e2 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'Tu plan: rutinas, ejercicios, series, repeticiones y calendario',
'Your unit and language': 'Tu unidad e idioma',
'Your workouts: weights, reps, times, effort and session notes': 'Tus entrenamientos: pesos, repeticiones, tiempos, esfuerzo y notas de sesión',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'No te pierdas nunca el final de un descanso',
+ 'One quick thing': 'Una cosita rápida',
+ 'Rest timer, right on the lock screen': 'El temporizador de descanso, en la pantalla de bloqueo',
+ 'Training reminders, only if you switch them on': 'Recordatorios de entreno, solo si los activas',
+ 'You can change it anytime in your phone’s settings.': 'Puedes cambiarlo cuando quieras en los ajustes del móvil.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'openGym puede darte un toque en el hombro cuando acaba un descanso, aunque el móvil esté bloqueado en tu bolsillo.',
}
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index d1fff5c37..d714bf1d2 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'Ton plan : routines, exercices, séries, répétitions et planning',
'Your unit and language': 'Ton unité et ta langue',
'Your workouts: weights, reps, times, effort and session notes': 'Tes séances : charges, répétitions, durées, effort et notes de séance',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Ne rate plus jamais la fin d’un repos',
+ 'One quick thing': 'Juste un petit truc',
+ 'Rest timer, right on the lock screen': 'Le minuteur de repos, directement sur l’écran verrouillé',
+ 'Training reminders, only if you switch them on': 'Des rappels d’entraînement, seulement si tu les actives',
+ 'You can change it anytime in your phone’s settings.': 'Tu peux changer ça à tout moment dans les réglages de ton téléphone.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'openGym peut te taper sur l’épaule quand un repos est fini, même avec le téléphone verrouillé dans ta poche.',
}
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index 99ceeb44e..270140797 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'आपका प्लान: रूटीन, एक्सरसाइज़, सेट, रेप्स और शेड्यूल',
'Your unit and language': 'आपकी इकाई और भाषा',
'Your workouts: weights, reps, times, effort and session notes': 'आपके वर्कआउट: वज़न, रेप्स, समय, मेहनत और सेशन नोट्स',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'रेस्ट का खत्म होना कभी न चूकें',
+ 'One quick thing': 'बस एक छोटी सी बात',
+ 'Rest timer, right on the lock screen': 'रेस्ट टाइमर, सीधे लॉक स्क्रीन पर',
+ 'Training reminders, only if you switch them on': 'ट्रेनिंग रिमाइंडर, सिर्फ़ अगर आप चालू करें',
+ 'You can change it anytime in your phone’s settings.': 'आप इसे कभी भी अपने फ़ोन की सेटिंग्स में बदल सकते हैं।',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'फ़ोन लॉक होकर जेब में हो तब भी, रेस्ट खत्म होने पर openGym आपके कंधे पर थपकी दे सकता है।',
}
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index 0a3021a1d..db3b775d1 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -2270,4 +2270,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'A terved: rutinok, gyakorlatok, sorozatok, ismétlések és beosztás',
'Your unit and language': 'A mértékegységed és a nyelved',
'Your workouts: weights, reps, times, effort and session notes': 'Az edzéseid: súlyok, ismétlések, idők, erőfeszítés és jegyzetek',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Ne maradj le a pihenő végéről',
+ 'One quick thing': 'Még egy gyors dolog',
+ 'Rest timer, right on the lock screen': 'Pihenőidőzítő, egyenesen a lezárási képernyőn',
+ 'Training reminders, only if you switch them on': 'Edzésemlékeztetők, csak ha bekapcsolod',
+ 'You can change it anytime in your phone’s settings.': 'Ezt bármikor megváltoztathatod a telefonod beállításaiban.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'Az openGym megkoppintja a vállad, amikor letelt a pihenő, akkor is, ha a lezárt telefon a zsebedben van.',
}
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index f67e99f46..6760f6804 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'Il tuo piano: routine, esercizi, serie, ripetizioni e calendario',
'Your unit and language': 'La tua unità e la tua lingua',
'Your workouts: weights, reps, times, effort and session notes': 'I tuoi allenamenti: pesi, ripetizioni, tempi, sforzo e note della sessione',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Non perderti mai la fine di un recupero',
+ 'One quick thing': 'Solo una cosa veloce',
+ 'Rest timer, right on the lock screen': 'Il timer di recupero, direttamente sulla schermata di blocco',
+ 'Training reminders, only if you switch them on': 'Promemoria di allenamento, solo se li attivi',
+ 'You can change it anytime in your phone’s settings.': 'Puoi cambiarlo quando vuoi nelle impostazioni del telefono.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'openGym può darti un colpetto sulla spalla quando un recupero è finito, anche con il telefono bloccato in tasca.',
}
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index df2ccf5be..cd60a9909 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': '내 플랜: 루틴, 운동, 세트, 반복 횟수, 일정',
'Your unit and language': '단위와 언어',
'Your workouts: weights, reps, times, effort and session notes': '내 운동: 무게, 반복 횟수, 시간, 강도, 세션 메모',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': '휴식이 끝나는 순간을 놓치지 마세요',
+ 'One quick thing': '잠깐 하나만요',
+ 'Rest timer, right on the lock screen': '휴식 타이머를 잠금 화면에서 바로',
+ 'Training reminders, only if you switch them on': '운동 알림은 켰을 때만',
+ 'You can change it anytime in your phone’s settings.': '언제든 휴대폰 설정에서 바꿀 수 있어요.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': '휴대폰이 잠긴 채 주머니에 있어도 휴식이 끝나면 openGym이 어깨를 톡 쳐 드려요.',
}
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index 20a7226c7..a452e3074 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'Twój plan: rutyny, ćwiczenia, serie, powtórzenia i harmonogram',
'Your unit and language': 'Twoja jednostka i język',
'Your workouts: weights, reps, times, effort and session notes': 'Twoje treningi: ciężary, powtórzenia, czasy, wysiłek i notatki z sesji',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Nigdy nie przegap końca przerwy',
+ 'One quick thing': 'Jeszcze jedna szybka sprawa',
+ 'Rest timer, right on the lock screen': 'Minutnik przerwy prosto na ekranie blokady',
+ 'Training reminders, only if you switch them on': 'Przypomnienia o treningu, tylko jeśli je włączysz',
+ 'You can change it anytime in your phone’s settings.': 'Możesz to zmienić w każdej chwili w ustawieniach telefonu.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'openGym może klepnąć cię w ramię, gdy przerwa się skończy, nawet gdy zablokowany telefon leży w kieszeni.',
}
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index 045075e78..e216f7a19 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -1428,6 +1428,13 @@ export const PT_BR_OVERRIDES = {
'Your plan: routines, exercises, sets, reps and schedule': 'Seu plano: rotinas, exercícios, séries, repetições e agenda',
'Your unit and language': 'Sua unidade e idioma',
'Your workouts: weights, reps, times, effort and session notes': 'Seus treinos: pesos, repetições, tempos, esforço e anotações da sessão',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Nunca perca o fim de um descanso',
+ 'One quick thing': 'Só uma coisa rápida',
+ 'Rest timer, right on the lock screen': 'Timer de descanso, direto na tela de bloqueio',
+ 'Training reminders, only if you switch them on': 'Lembretes de treino, só se você ativar',
+ 'You can change it anytime in your phone’s settings.': 'Você pode mudar isso quando quiser nas configurações do celular.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'O openGym pode te dar um toque no ombro quando um descanso acaba, mesmo com o celular bloqueado no bolso.',
}
export default { ...pt, ...PT_BR_OVERRIDES }
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index 1d41a1d0f..b05e3ee66 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'O teu plano: rotinas, exercícios, séries, repetições e horário',
'Your unit and language': 'A tua unidade e idioma',
'Your workouts: weights, reps, times, effort and session notes': 'Os teus treinos: pesos, repetições, tempos, esforço e notas da sessão',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Nunca percas o fim de um descanso',
+ 'One quick thing': 'Só uma coisa rápida',
+ 'Rest timer, right on the lock screen': 'Temporizador de descanso, direto no ecrã de bloqueio',
+ 'Training reminders, only if you switch them on': 'Lembretes de treino, só se os ligares',
+ 'You can change it anytime in your phone’s settings.': 'Podes mudar isto quando quiseres nas definições do teu telemóvel.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'O openGym pode dar-te um toque no ombro quando um descanso acaba, mesmo com o telemóvel bloqueado no bolso.',
}
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 2ce6f3aff..82f68b39c 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -2271,4 +2271,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'Ваш план: программы, упражнения, подходы, повторы и расписание',
'Your unit and language': 'Ваши единицы и язык',
'Your workouts: weights, reps, times, effort and session notes': 'Ваши тренировки: веса, повторы, время, усилие и заметки',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Не пропустите конец отдыха',
+ 'One quick thing': 'Ещё кое-что, быстро',
+ 'Rest timer, right on the lock screen': 'Таймер отдыха прямо на экране блокировки',
+ 'Training reminders, only if you switch them on': 'Напоминания о тренировках, только если вы их включите',
+ 'You can change it anytime in your phone’s settings.': 'Это можно изменить в любой момент в настройках телефона.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'openGym может похлопать вас по плечу, когда отдых закончится, даже если телефон заблокирован и лежит в кармане.',
}
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index 6f790859c..cc6b00ce5 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -2278,4 +2278,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'แผนของคุณ: รูทีน ท่าออกกำลังกาย เซ็ต จำนวนครั้ง และตาราง',
'Your unit and language': 'หน่วยและภาษาของคุณ',
'Your workouts: weights, reps, times, effort and session notes': 'การฝึกของคุณ: น้ำหนัก จำนวนครั้ง เวลา ความหนัก และบันทึกของเซสชัน',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'ไม่พลาดตอนพักจบอีกเลย',
+ 'One quick thing': 'ขอแป๊บเดียว',
+ 'Rest timer, right on the lock screen': 'ตัวจับเวลาพัก บนหน้าจอล็อกเลย',
+ 'Training reminders, only if you switch them on': 'การแจ้งเตือนการฝึก เฉพาะเมื่อคุณเปิดใช้',
+ 'You can change it anytime in your phone’s settings.': 'เปลี่ยนได้ทุกเมื่อในการตั้งค่าของโทรศัพท์',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'openGym สะกิดไหล่คุณได้เมื่อหมดเวลาพัก แม้โทรศัพท์จะล็อกอยู่ในกระเป๋า',
}
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 9febf3bdd..5af993b83 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'Planın: rutinler, egzersizler, setler, tekrarlar ve program',
'Your unit and language': 'Birimin ve dilin',
'Your workouts: weights, reps, times, effort and session notes': 'Antrenmanların: ağırlıklar, tekrarlar, süreler, efor ve seans notları',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Dinlenmenin bittiğini asla kaçırma',
+ 'One quick thing': 'Kısa bir şey daha',
+ 'Rest timer, right on the lock screen': 'Dinlenme sayacı, doğrudan kilit ekranında',
+ 'Training reminders, only if you switch them on': 'Antrenman hatırlatıcıları, sadece açarsan',
+ 'You can change it anytime in your phone’s settings.': 'Bunu istediğin zaman telefonunun ayarlarından değiştirebilirsin.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'Telefon kilitli halde cebinde olsa bile, dinlenme bitince openGym omzuna dokunabilir.',
}
diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.js
index 762a49d43..f68e38f0f 100644
--- a/frontend/src/locales/uk.js
+++ b/frontend/src/locales/uk.js
@@ -2264,4 +2264,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': 'Твій план: програми, вправи, підходи, повтори й розклад',
'Your unit and language': 'Твої одиниці та мова',
'Your workouts: weights, reps, times, effort and session notes': 'Твої тренування: ваги, повтори, час, зусилля й нотатки',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': 'Не пропусти кінець відпочинку',
+ 'One quick thing': 'Ще одна швидка річ',
+ 'Rest timer, right on the lock screen': 'Таймер відпочинку просто на екрані блокування',
+ 'Training reminders, only if you switch them on': 'Нагадування про тренування, лише якщо ти їх увімкнеш',
+ 'You can change it anytime in your phone’s settings.': 'Це можна змінити будь-коли в налаштуваннях телефона.',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': 'openGym може поплескати тебе по плечу, коли відпочинок скінчиться, навіть якщо телефон заблокований і лежить у кишені.',
}
diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.js
index 4efc24a9e..7dec42772 100644
--- a/frontend/src/locales/zh-TW.js
+++ b/frontend/src/locales/zh-TW.js
@@ -2260,4 +2260,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': '你的計畫:課表、動作、組數、次數和行程',
'Your unit and language': '你的單位和語言',
'Your workouts: weights, reps, times, effort and session notes': '你的訓練:重量、次數、時間、強度和訓練備註',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': '不再錯過休息結束',
+ 'One quick thing': '還有一件小事',
+ 'Rest timer, right on the lock screen': '休息計時,直接顯示在鎖定畫面',
+ 'Training reminders, only if you switch them on': '訓練提醒,只在你開啟時',
+ 'You can change it anytime in your phone’s settings.': '你隨時可以在手機設定裡更改。',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': '就算手機鎖著放在口袋裡,休息結束時 openGym 也能拍拍你的肩膀。',
}
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index 7fcdb1cf0..22578808d 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -2267,4 +2267,11 @@ export default {
'Your plan: routines, exercises, sets, reps and schedule': '你的计划:训练安排、动作、组数、次数和日程',
'Your unit and language': '你的单位和语言',
'Your workouts: weights, reps, times, effort and session notes': '你的训练:重量、次数、时间、强度和训练备注',
+ // --- first-start permission steps ---
+ 'Never miss the end of a rest': '不再错过休息结束',
+ 'One quick thing': '还有一件小事',
+ 'Rest timer, right on the lock screen': '休息计时,直接显示在锁屏上',
+ 'Training reminders, only if you switch them on': '训练提醒,只在你开启时',
+ 'You can change it anytime in your phone’s settings.': '你随时可以在手机设置里更改。',
+ 'openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.': '即使手机锁屏放在口袋里,休息结束时 openGym 也能拍拍你的肩膀。',
}
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index cfb1bd495..0d7be5bde 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -1308,6 +1308,11 @@ export const useStore = create((set, get) => {
always did, and a configured one is the only place any of it appears. */
config: null,
needsMobileOnboarding: false, // mobile build only — set true by boot() on a genuine first launch
+ // Mobile build only: the first-start permission steps (views/PermissionSteps.jsx) are due.
+ // Set when that first launch's choice is made; never persisted, the steps keep their own
+ // once-per-device record (lib/onboarding-perms.js).
+ permSteps: false,
+ finishPermSteps() { set({ permSteps: false }) },
// A one-time device-link code this page was opened with (?link=, #95), until it is redeemed.
// Never persisted: the code is good for minutes and belongs to this one visit.
linkCode: null,
@@ -1741,7 +1746,7 @@ export const useStore = create((set, get) => {
if (typeof ask !== 'function') ask = (await import('../sheets.jsx')).askAddDeviceData
const r = await get().adoptProfile(ask, { alwaysAsk: !!m.alwaysAsk })
// A phone whose pairing ended here: what connectToServer does after its own adoption.
- if (MOBILE) { await nativePersist(true); if (get().needsMobileOnboarding) set({ needsMobileOnboarding: false }) }
+ if (MOBILE) { await nativePersist(true); if (get().needsMobileOnboarding) set({ needsMobileOnboarding: false, permSteps: true }) }
return r
} catch { return null }
},
@@ -1773,7 +1778,7 @@ export const useStore = create((set, get) => {
// asks again.
async chooseLocalMode() {
await chooseLocal()
- set({ needsMobileOnboarding: false })
+ set({ needsMobileOnboarding: false, permSteps: true })
},
// Redeems the pairing code shown in the browser (Settings → "Pair the mobile app") and
// switches this device over to that account, same as signing in on the web does — the same
@@ -1789,7 +1794,9 @@ export const useStore = create((set, get) => {
await get().refreshConfig() // what this server offers (the Coach, guest mode) — see boot()
await get().adoptProfile(ask)
await nativePersist(true) // the file holds this account's copy before anything else can happen
- set({ needsMobileOnboarding: false })
+ // Paired from the first-launch screen: the permission steps come next. From Settings later
+ // on, nothing new is asked here.
+ set(st => ({ needsMobileOnboarding: false, permSteps: st.permSteps || st.needsMobileOnboarding }))
},
// Leaves remote mode and drops back to local-only, the way signOut does: never with changes
// the server has not seen, unless `force` keeps them aside first. Same result as signOut;
diff --git a/frontend/src/store/useStore.mobile-remote.test.jsx b/frontend/src/store/useStore.mobile-remote.test.jsx
index b3bd2836f..736eff948 100644
--- a/frontend/src/store/useStore.mobile-remote.test.jsx
+++ b/frontend/src/store/useStore.mobile-remote.test.jsx
@@ -329,6 +329,8 @@ describe('Disconnect anyway keeps the owed changes for the next pairing', () =>
expect(readFile('opengym-stash.json')).toEqual({})
expect(localStorage.getItem('gym_stash')).toBeNull()
expect(localStorage.getItem('gym_dirty')).toBeNull()
+ // Paired from Settings, not from the first-launch screen: no permission steps.
+ expect(useStore.getState().permSteps).toBe(false)
})
it('killed straight after, the next start is local and empty: the account\'s copy is in the stash, not back on the screen', async () => {
@@ -601,3 +603,31 @@ describe('a request that never answers', () => {
} finally { vi.useRealTimers() }
})
})
+
+describe('the first-start permission steps (views/PermissionSteps.jsx)', () => {
+ const firstLaunch = async () => {
+ h.files.clear(); localStorage.clear()
+ const useStore = await freshStore()
+ await useStore.getState().boot()
+ expect(useStore.getState().needsMobileOnboarding).toBe(true)
+ expect(useStore.getState().permSteps).toBe(false)
+ return useStore
+ }
+
+ it('are due once "Use on this device" is picked', async () => {
+ const useStore = await firstLaunch()
+ await useStore.getState().chooseLocalMode()
+ expect(useStore.getState().needsMobileOnboarding).toBe(false)
+ expect(useStore.getState().permSteps).toBe(true)
+ useStore.getState().finishPermSteps()
+ expect(useStore.getState().permSteps).toBe(false)
+ })
+
+ it('are due once pairing from the first-launch screen has finished', async () => {
+ const useStore = await firstLaunch()
+ serverWith(SERVER_STATE)
+ await useStore.getState().connectToServer('gym.example.com', 'ABCD2345', vi.fn(async () => false))
+ expect(useStore.getState().needsMobileOnboarding).toBe(false)
+ expect(useStore.getState().permSteps).toBe(true)
+ })
+})
diff --git a/frontend/src/views/PermissionSteps.jsx b/frontend/src/views/PermissionSteps.jsx
new file mode 100644
index 000000000..783a460cf
--- /dev/null
+++ b/frontend/src/views/PermissionSteps.jsx
@@ -0,0 +1,54 @@
+// Phone app, first start: the permission steps between the onboarding choice and the app
+// (lib/onboarding-perms.js decides which are due). One step per screen, Allow / Not now, and
+// the app as soon as the list is through. A step with nothing to ask never renders, so a phone
+// that already allowed everything goes straight on without a flash of this screen.
+import { useEffect, useState } from 'react'
+import { useStore } from '../store/useStore.js'
+import { t } from '../lib/i18n.js'
+import { pendingSteps, markStepSeen } from '../lib/onboarding-perms.js'
+import Icon from '../components/Icon.jsx'
+import { Button } from '../components/ui.jsx'
+
+// What each step says. Literal t() calls, so check-source-strings sees them; a new step (Apple
+// Health, Health Connect) adds its own entry here and its check/request in onboarding-perms.js.
+const COPY = {
+ notifications: () => ({
+ icon: 'bell',
+ title: t('Never miss the end of a rest'),
+ body: t('openGym can tap you on the shoulder when a rest is over, even with the phone locked in your pocket.'),
+ lines: [t('Rest timer, right on the lock screen'), t('Training reminders, only if you switch them on')],
+ }),
+}
+
+export default function PermissionSteps() {
+ const done = useStore(s => s.finishPermSteps)
+ const [steps, setSteps] = useState(null)
+ const [i, setI] = useState(0)
+ const [busy, setBusy] = useState(false)
+ useEffect(() => { pendingSteps().then(setSteps).catch(() => setSteps([])) }, [])
+ const step = steps && steps[i]
+ useEffect(() => { if (steps && !step) done() }, [steps, step])
+ if (!step) return null
+
+ const answer = async allow => {
+ setBusy(true)
+ markStepSeen(step.id)
+ if (allow) await Promise.resolve(step.request()).catch(() => false)
+ setBusy(false)
+ setI(i + 1)
+ }
+ const c = (COPY[step.id] || (() => ({ icon: 'info', title: step.id, body: '', lines: [] })))()
+ return <div className="narrow" style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', minHeight: '78vh', textAlign: 'center' }}>
+ <div style={{ fontSize: 54, display: 'flex', justifyContent: 'center', color: 'var(--acc)' }}><Icon name={c.icon} /></div>
+ <div className="dim small" style={{ marginTop: 12, textTransform: 'uppercase', letterSpacing: '.06em' }}>{t('One quick thing')}</div>
+ <h1 style={{ fontSize: 28, fontWeight: 700, letterSpacing: '-.024em', margin: '6px 0 10px' }}>{c.title}</h1>
+ <div className="muted" style={{ lineHeight: 1.5, marginBottom: 18 }}>{c.body}</div>
+ <div style={{ display: 'grid', gap: 8, marginBottom: 28, textAlign: 'start' }}>
+ {c.lines.map(l => <div key={l} className="row" style={{ gap: 10 }}><span style={{ color: 'var(--green)' }}><Icon name="check" /></span><span className="small">{l}</span></div>)}
+ </div>
+ <Button variant="primary" disabled={busy} onClick={() => answer(true)}>{t('Allow')}</Button>
+ <div style={{ height: 10 }} />
+ <Button disabled={busy} onClick={() => answer(false)}>{t('Not now')}</Button>
+ <div className="dim small" style={{ marginTop: 18, lineHeight: 1.5 }}>{t('You can change it anytime in your phone’s settings.')}</div>
+ </div>
+}
diff --git a/frontend/src/views/PermissionSteps.test.jsx b/frontend/src/views/PermissionSteps.test.jsx
new file mode 100644
index 000000000..8a427e165
--- /dev/null
+++ b/frontend/src/views/PermissionSteps.test.jsx
@@ -0,0 +1,95 @@
+// @vitest-environment happy-dom
+// The phone app's first-start permission step (owner request, TestFlight): after "Use on this
+// device" or a finished pairing, one screen explains notifications with Allow / Not now. Shown
+// once per device, never for a permission already granted or one the OS will not ask for again,
+// never off the phone app. Allow goes through the same request the first rest makes
+// (rest-alert.js), so the first rest does not ask a second time; Not now leaves that ask alone.
+import React, { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+globalThis.IS_REACT_ACT_ENVIRONMENT = true
+
+const h = vi.hoisted(() => ({ MOBILE: true, display: 'prompt', after: 'granted', finish: vi.fn(), requests: 0 }))
+vi.mock('../lib/mobile.js', () => ({ get MOBILE() { return h.MOBILE }, nativePlatform: async () => (h.MOBILE ? 'ios' : null) }))
+vi.mock('@capacitor/local-notifications', () => ({
+ LocalNotifications: {
+ checkPermissions: async () => ({ display: h.display }),
+ requestPermissions: async () => { h.requests++; h.display = h.after; return { display: h.after } },
+ },
+}))
+vi.mock('../store/useStore.js', () => {
+ const snap = () => ({ finishPermSteps: h.finish })
+ const useStore = sel => (sel ? sel(snap()) : snap())
+ useStore.getState = snap
+ return { useStore }
+})
+
+const { default: PermissionSteps } = await import('./PermissionSteps.jsx')
+const { pendingSteps, SEEN_KEY } = await import('../lib/onboarding-perms.js')
+const { NOTIF_ASKED_KEY, _resetNotifAsk } = await import('../lib/rest-alert.js')
+
+let host, root
+beforeEach(() => {
+ Object.assign(h, { MOBILE: true, display: 'prompt', after: 'granted', requests: 0 })
+ h.finish.mockReset()
+ localStorage.clear()
+ _resetNotifAsk()
+ host = document.createElement('div'); document.body.appendChild(host); root = createRoot(host)
+})
+afterEach(() => { act(() => root.unmount()); host.remove() })
+
+const settle = () => act(async () => { for (let i = 0; i < 6; i++) await Promise.resolve() })
+const mount = async () => { act(() => root.render(<PermissionSteps />)); await settle() }
+const button = text => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === text)
+const click = async el => { await act(async () => { el.click() }); await settle() }
+
+describe('which steps are due', () => {
+ it('notifications, while the OS would still ask', async () => {
+ expect((await pendingSteps()).map(s => s.id)).toEqual(['notifications'])
+ })
+ it('none once granted, none once denied for good, none off the phone app', async () => {
+ h.display = 'granted'; expect(await pendingSteps()).toEqual([])
+ h.display = 'denied'; expect(await pendingSteps()).toEqual([])
+ h.display = 'prompt'; h.MOBILE = false; expect(await pendingSteps()).toEqual([])
+ })
+})
+
+describe('the screen', () => {
+ it('explains notifications; Allow asks the OS once and goes on to the app', async () => {
+ await mount()
+ expect(host.textContent).toContain('Never miss the end of a rest')
+ expect(host.textContent).toContain('Training reminders, only if you switch them on')
+ expect(host.textContent).not.toMatch(/—/)
+ await click(button('Allow'))
+ expect(h.requests).toBe(1)
+ expect(h.finish).toHaveBeenCalledTimes(1)
+ // The first rest does not ask again: the answer is on record where rest-alert.js looks.
+ expect(localStorage.getItem(NOTIF_ASKED_KEY)).toBe('granted')
+ expect(JSON.parse(localStorage.getItem(SEEN_KEY))).toEqual(['notifications'])
+ })
+
+ it('Not now goes on without asking, and leaves the in-context ask for later', async () => {
+ await mount()
+ await click(button('Not now'))
+ expect(h.requests).toBe(0)
+ expect(h.finish).toHaveBeenCalledTimes(1)
+ expect(localStorage.getItem(NOTIF_ASKED_KEY)).toBeNull()
+ })
+
+ it('is shown once per device', async () => {
+ await mount()
+ await click(button('Not now'))
+ act(() => root.unmount()); root = createRoot(host); h.finish.mockReset()
+ await mount()
+ expect(host.textContent).toBe('')
+ expect(h.finish).toHaveBeenCalledTimes(1)
+ })
+
+ it('with nothing to ask, renders nothing and goes straight on', async () => {
+ h.display = 'granted'
+ await mount()
+ expect(host.textContent).toBe('')
+ expect(h.finish).toHaveBeenCalledTimes(1)
+ })
+})