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 app: the end of a rest plays the louder chime in the background and with the screen off too
Duarte Santos891eed88fa07
diff --git a/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlert.java b/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlert.javaindex 8a5240426..e331deb3d 100644--- a/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlert.java+++ b/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlert.java@@ -10,6 +10,8 @@ import android.content.res.ColorStateList;import android.content.Intent;import android.widget.RemoteViews;import android.media.AudioAttributes;+import android.media.AudioFocusRequest;+import android.media.AudioManager;import android.media.AudioFormat;import android.media.AudioTrack;import android.os.Build;@@ -43,6 +45,7 @@ public final class RestAlert {static final String QUIET_CHANNEL_ID = "rest-over-quiet";private static String lastAlertTitle = "Rest over";private static boolean lastSound = true;+ private static boolean lastClassic = false;private static boolean lastVibrate = true;private static boolean lastAlarmBuzz = false;private static String lastChannel = CHANNEL_ID;@@ -57,7 +60,7 @@ public final class RestAlert {static final int NOTIFICATION_ID = 42;static final String COUNTDOWN_CHANNEL_ID = "rest-countdown";private static final int FLAGS = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE;- private static final int RATE = 22050;+ private static final int RATE = RestTone.RATE;private static final long[] VIBRATE = new long[] {0, 200, 100, 200, 100, 400};private static AudioTrack current;@@ -70,7 +73,7 @@ public final class RestAlert {* alarm, which silent mode lets through, and the notification goes out on the quiet channel so* a phone with its ringer on does not buzz twice.*/- public static void schedule(Context ctx, long at, int id, String title, boolean sound, boolean vibrate,+ public static void schedule(Context ctx, long at, int id, String title, boolean sound, boolean classic, boolean vibrate,boolean alarmBuzz, String channelId, String visibility, String importance,boolean localOnly, String countdownTitle, long totalMs) {alarmBuzz = vibrate && alarmBuzz;@@ -79,6 +82,7 @@ public final class RestAlert {intent.putExtra("id", id);intent.putExtra("title", title == null ? "" : title);intent.putExtra("sound", sound);+ intent.putExtra("classic", classic);intent.putExtra("vibrate", vibrate);intent.putExtra("alarmBuzz", alarmBuzz);intent.putExtra("channelId", channelId);@@ -104,6 +108,7 @@ public final class RestAlert {}lastAlertTitle = title == null ? "Rest over" : title;lastSound = sound;+ lastClassic = classic;lastVibrate = vibrate;lastAlarmBuzz = alarmBuzz;lastChannel = channelId;@@ -145,6 +150,7 @@ public final class RestAlert {intent.putExtra("id", NOTIFICATION_ID);intent.putExtra("title", lastAlertTitle);intent.putExtra("sound", lastSound);+ intent.putExtra("classic", lastClassic);intent.putExtra("vibrate", lastVibrate);intent.putExtra("alarmBuzz", lastAlarmBuzz);intent.putExtra("channelId", lastChannel);@@ -186,12 +192,16 @@ public final class RestAlert {if (alarmBuzz) buzz(ctx, VIBRATE);// Settings → Vibrate off is off here too: without notifications this buzz is the alert.else if (!shown && vibrate) vibrateFallback(ctx);+ // Locked or in the background, the page does not play its chime, so this is the one:+ // the same chime (or classic beeps) as Settings → Sound picks for the page.+ boolean play = intent.getBooleanExtra("sound", true);+ if (play) playSound(ctx, intent.getBooleanExtra("classic", false));// The countdown card is the foreground-service notification. Drop it once the- // "rest over" alert is up, including when the WebView is frozen.+ // "rest over" alert is up and the tone has played, including when the WebView is+ // frozen. Not before the tone: the service is what keeps this process in the+ // foreground, and a process that has just dropped out of it can be frozen or cut+ // off mid-tone with the screen off.stopCountdown(ctx);- // Locked or in the background, the page cannot play its chime, so this is the one.- boolean play = intent.getBooleanExtra("sound", true);- if (play) playSound(ctx);} finally {if (cpu != null && cpu.isHeld()) cpu.release();}@@ -355,6 +365,7 @@ public final class RestAlert {intent.putExtra("id", NOTIFICATION_ID);intent.putExtra("title", lastAlertTitle);intent.putExtra("sound", lastSound);+ intent.putExtra("classic", lastClassic);intent.putExtra("vibrate", lastVibrate);intent.putExtra("alarmBuzz", lastAlarmBuzz);intent.putExtra("channelId", lastChannel);@@ -503,12 +514,26 @@ public final class RestAlert {nm.createNotificationChannel(channel);}- private static void playSound(Context ctx) {- playClip(ctx, renderBeeps());+ private static void playSound(Context ctx, boolean classic) {+ playClip(ctx, RestTone.render(classic));}+ /**+ * Plays a whole clip and returns once it has been heard. Over music the clip asks for a+ * short duck, as a navigation prompt does: the music app turns itself down for the tone+ * and back up after it. A web page cannot do that, which is half of why the chime got lost+ * under music (Discord: "Rest Timer Sound Notification too Quiet").+ *+ * The track used to be let go a fixed 60 ms after the clip's length. With the screen off the+ * output wakes from standby and runs through a low-power buffer first, and Bluetooth adds its+ * own delay, so the last, longest note was cut off or the whole tone never reached the+ * speaker. Now the track is held until the mixer has taken every sample (the clip ends in+ * RestTone.TAIL_SEC of silence for what sits behind the mixer), with a cap.+ */private static void playClip(Context ctx, short[] samples) {AudioTrack track = null;+ AudioManager am = null;+ Object focus = null;try {int bytes = samples.length * 2;int min = AudioTrack.getMinBufferSize(RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);@@ -518,11 +543,12 @@ public final class RestAlert {samples = padded;bytes = samples.length * 2;}+ AudioAttributes attrs = new AudioAttributes.Builder()+ .setUsage(AudioAttributes.USAGE_MEDIA)+ .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)+ .build();track = new AudioTrack.Builder()- .setAudioAttributes(new AudioAttributes.Builder()- .setUsage(AudioAttributes.USAGE_MEDIA)- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)- .build())+ .setAudioAttributes(attrs).setAudioFormat(new AudioFormat.Builder().setEncoding(AudioFormat.ENCODING_PCM_16BIT).setSampleRate(RATE)@@ -532,53 +558,68 @@ public final class RestAlert {.setTransferMode(AudioTrack.MODE_STATIC).build();if (track.getState() != AudioTrack.STATE_INITIALIZED) return;- track.write(samples, 0, samples.length);+ int frames = track.write(samples, 0, samples.length);+ if (frames <= 0) return;track.setVolume(1f);+ am = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);+ focus = duck(am, attrs);stopCurrent();current = track;track.play();- Thread.sleep((samples.length * 1000L / RATE) + 60);+ long clipMs = frames * 1000L / RATE;+ long deadline = System.currentTimeMillis() + clipMs + 3000;+ while (System.currentTimeMillis() < deadline+ && track.getPlayState() == AudioTrack.PLAYSTATE_PLAYING+ && track.getPlaybackHeadPosition() < frames) {+ Thread.sleep(25);+ }} catch (InterruptedException e) {Thread.currentThread().interrupt();} catch (Exception ignored) { /* the notification still posted */ }finally {if (track != null) {- try { track.pause(); } catch (Exception ignored) { /* */ }+ try { track.stop(); } catch (Exception ignored) { /* */ }try { track.release(); } catch (Exception ignored) { /* */ }if (current == track) current = null;}+ unduck(am, focus);}}+ /** Asks other apps to turn down for the tone. Returns what unduck needs, or null. */+ @SuppressWarnings("deprecation")+ private static Object duck(AudioManager am, AudioAttributes attrs) {+ if (am == null) return null;+ try {+ if (Build.VERSION.SDK_INT >= 26) {+ AudioFocusRequest req = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK)+ .setAudioAttributes(attrs)+ .setOnAudioFocusChangeListener(change -> { /* a tone this short just plays on */ })+ .build();+ am.requestAudioFocus(req);+ return req;+ }+ AudioManager.OnAudioFocusChangeListener listener = change -> { /* */ };+ am.requestAudioFocus(listener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);+ return listener;+ } catch (Exception e) {+ return null;+ }+ }++ @SuppressWarnings("deprecation")+ private static void unduck(AudioManager am, Object focus) {+ if (am == null || focus == null) return;+ try {+ if (Build.VERSION.SDK_INT >= 26 && focus instanceof AudioFocusRequest) am.abandonAudioFocusRequest((AudioFocusRequest) focus);+ else if (focus instanceof AudioManager.OnAudioFocusChangeListener) am.abandonAudioFocus((AudioManager.OnAudioFocusChangeListener) focus);+ } catch (Exception ignored) { /* the duck ends with the process anyway */ }+ }+private static synchronized void stopCurrent() {if (current == null) return;try { current.pause(); } catch (Exception ignored) { /* */ }try { current.release(); } catch (Exception ignored) { /* */ }current = null;}-- /** Same three tones the in-page beep uses (880, 880, 1320), at full scale. */- static short[] renderBeeps() {- int[] freq = {880, 880, 1320};- double[] dur = {0.15, 0.15, 0.40};- double[] gap = {0.10, 0.10, 0};- int total = 0;- for (int i = 0; i < freq.length; i++) total += (int) (RATE * (dur[i] + gap[i]));- short[] out = new short[total];- int pos = 0;- for (int i = 0; i < freq.length; i++) {- int n = (int) (RATE * dur[i]);- int g = (int) (RATE * gap[i]);- int fade = Math.max(1, RATE / 200);- for (int s = 0; s < n; s++) {- double env = 1;- if (s < fade) env = s / (double) fade;- else if (s > n - fade) env = (n - s) / (double) fade;- double wave = Math.sin(2 * Math.PI * freq[i] * s / RATE);- out[pos++] = (short) Math.max(-32767, Math.min(32767, wave * env * 0.85 * 32767));- }- pos += g;- }- return out;- }}diff --git a/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlertPlugin.java b/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlertPlugin.javaindex 8fa9ac575..94b88249e 100644--- a/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlertPlugin.java+++ b/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestAlertPlugin.java@@ -16,7 +16,7 @@ import com.getcapacitor.annotation.CapacitorPlugin;* Usage from JS:* import { registerPlugin } from '@capacitor/core';* const RestAlert = registerPlugin('RestAlert');- * await RestAlert.schedule({ id, at, title, sound, vibrate, channelId, visibility, importance, localOnly });+ * await RestAlert.schedule({ id, at, title, sound, classic, vibrate, channelId, visibility, importance, localOnly });* await RestAlert.cancel({ id });* await RestAlert.buzz({ pattern: [200, 100, 200] }); // navigator.vibrate's shape, as an alarm*/@@ -84,6 +84,7 @@ public class RestAlertPlugin extends Plugin {(int) number(call, "id", RestAlert.NOTIFICATION_ID),call.getString("title", "Rest over"),!Boolean.FALSE.equals(call.getBoolean("sound", Boolean.TRUE)),+ Boolean.TRUE.equals(call.getBoolean("classic", Boolean.FALSE)),!Boolean.FALSE.equals(call.getBoolean("vibrate", Boolean.TRUE)),Boolean.TRUE.equals(call.getBoolean("alarmBuzz", Boolean.FALSE)),call.getString("channelId", RestAlert.CHANNEL_ID),diff --git a/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestTone.java b/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestTone.javanew file mode 100644index 000000000..b65a151dd--- /dev/null+++ b/frontend/android/app/src/main/java/ch/duartesantos/opengym/RestTone.java@@ -0,0 +1,115 @@+package ch.duartesantos.opengym;++/**+ * The end-of-rest tone the native side plays while the app is in the background or the screen+ * is off, as 16-bit mono samples. Plain Java with no Android classes, so it has a unit test.+ *+ * The page plays the same two choices through Web Audio (frontend/src/lib/sound.js chime()):+ * the chime, high, low, then high and long, held near full scale in a bright timbre, and the+ * classic three beeps. Until v1.3.11 this side only knew the classic beeps, so a locked phone+ * played the quiet old sound however Settings → Sound was set.+ */+final class RestTone {+ static final int RATE = 22050;++ /**+ * Silence after the tone. The player is let go once the mixer has taken every sample, but+ * Bluetooth earbuds and the screen-off low-power output still hold up to a few hundred+ * milliseconds of audio by then; without this tail the last, longest note got cut.+ */+ static final double TAIL_SEC = 0.6;++ /** lib/sound.js CHIME_PEAK, CHIME and the 0.6 hold. */+ static final double CHIME_PEAK = 0.9;+ private static final double[][] CHIME = {{1319, 0.16, 0}, {988, 0.16, 0.22}, {1319, 0.5, 0.44}};+ private static final double CHIME_HOLD = 0.6;+ /** lib/sound.js setBright: the fundamental and three falling harmonics. */+ private static final double[] BRIGHT = {1, 0.6, 0.35, 0.2};++ private RestTone() {}++ static short[] render(boolean classic) {+ return withTail(classic ? renderBeeps() : renderChime());+ }++ /**+ * The chime as the page renders it: each note ramps up from silence in 20 ms, holds its peak+ * for 60% of the note, then falls away exponentially, in a wave normalised to a peak of 1 as+ * Web Audio normalises a periodic wave.+ */+ static short[] renderChime() {+ double end = 0;+ for (double[] n : CHIME) end = Math.max(end, n[2] + n[1]);+ double[] mix = new double[(int) Math.ceil(end * RATE)];+ double norm = brightPeak();+ for (double[] n : CHIME) {+ double freq = n[0], dur = n[1];+ int start = (int) Math.round(n[2] * RATE);+ int len = (int) (dur * RATE);+ for (int s = 0; s < len && start + s < mix.length; s++) {+ double t = s / (double) RATE;+ double wave = 0;+ for (int k = 0; k < BRIGHT.length; k++) wave += BRIGHT[k] * Math.sin(2 * Math.PI * freq * (k + 1) * t);+ mix[start + s] += wave / norm * chimeGain(t, dur);+ }+ }+ short[] out = new short[mix.length];+ for (int i = 0; i < mix.length; i++) out[i] = (short) Math.max(-32767, Math.min(32767, Math.round(mix[i] * 32767)));+ return out;+ }++ /** The gain curve of lib/sound.js tone() with peak CHIME_PEAK and hold CHIME_HOLD. */+ static double chimeGain(double t, double dur) {+ double floor = 0.001, attack = 0.02, holdEnd = dur * CHIME_HOLD;+ if (t < 0) return 0;+ if (t < attack) return floor * Math.pow(CHIME_PEAK / floor, t / attack);+ if (t < holdEnd) return CHIME_PEAK;+ if (t < dur) return CHIME_PEAK * Math.pow(floor / CHIME_PEAK, (t - holdEnd) / (dur - holdEnd));+ return 0;+ }++ private static double brightPeak() {+ double max = 0;+ for (int i = 0; i < 4096; i++) {+ double x = 2 * Math.PI * i / 4096;+ double v = 0;+ for (int k = 0; k < BRIGHT.length; k++) v += BRIGHT[k] * Math.sin((k + 1) * x);+ max = Math.max(max, Math.abs(v));+ }+ return max;+ }++ /**+ * The classic beeps (880, 880, 1320). Flat at 0.85 of full scale rather than the page's fade+ * from 0.35: this is what the locked phone has always played for "Classic".+ */+ static short[] renderBeeps() {+ int[] freq = {880, 880, 1320};+ double[] dur = {0.15, 0.15, 0.40};+ double[] gap = {0.10, 0.10, 0};+ int total = 0;+ for (int i = 0; i < freq.length; i++) total += (int) (RATE * (dur[i] + gap[i]));+ short[] out = new short[total];+ int pos = 0;+ for (int i = 0; i < freq.length; i++) {+ int n = (int) (RATE * dur[i]);+ int g = (int) (RATE * gap[i]);+ int fade = Math.max(1, RATE / 200);+ for (int s = 0; s < n; s++) {+ double env = 1;+ if (s < fade) env = s / (double) fade;+ else if (s > n - fade) env = (n - s) / (double) fade;+ double wave = Math.sin(2 * Math.PI * freq[i] * s / RATE);+ out[pos++] = (short) Math.max(-32767, Math.min(32767, wave * env * 0.85 * 32767));+ }+ pos += g;+ }+ return out;+ }++ static short[] withTail(short[] tone) {+ short[] out = new short[tone.length + (int) (TAIL_SEC * RATE)];+ System.arraycopy(tone, 0, out, 0, tone.length);+ return out;+ }+}diff --git a/frontend/android/app/src/test/java/ch/duartesantos/opengym/RestToneTest.java b/frontend/android/app/src/test/java/ch/duartesantos/opengym/RestToneTest.javanew file mode 100644index 000000000..7bb2dc524--- /dev/null+++ b/frontend/android/app/src/test/java/ch/duartesantos/opengym/RestToneTest.java@@ -0,0 +1,54 @@+package ch.duartesantos.opengym;++import static org.junit.Assert.*;++import org.junit.Test;++/** The tone a locked phone plays at the end of a rest (RestTone). */+public class RestToneTest {+ private static int peak(short[] s, double from, double to) {+ int max = 0;+ for (int i = (int) (from * RestTone.RATE); i < Math.min(s.length, (int) (to * RestTone.RATE)); i++) {+ max = Math.max(max, Math.abs(s[i]));+ }+ return max;+ }++ @Test+ public void chimeIsThePagesChimeNotTheClassicBeeps() {+ short[] chime = RestTone.render(false);+ short[] classic = RestTone.render(true);+ assertNotEquals(chime.length, classic.length);+ // E6 B5 E6: notes at 0, 0.22 and 0.44 s, the last one half a second long.+ assertTrue(peak(chime, 0.03, 0.09) > 0.85 * 32767);+ assertTrue(peak(chime, 0.25, 0.31) > 0.85 * 32767);+ assertTrue(peak(chime, 0.47, 0.70) > 0.85 * 32767);+ // Gaps between the notes are quiet: the notes never add up past the peak.+ assertTrue(peak(chime, 0.165, 0.215) < 300);+ }++ @Test+ public void chimeHoldsItsPeakForMostOfEachNote() {+ assertEquals(RestTone.CHIME_PEAK, RestTone.chimeGain(0.25, 0.5), 1e-9);+ assertTrue(RestTone.chimeGain(0.01, 0.5) < RestTone.CHIME_PEAK);+ assertTrue(RestTone.chimeGain(0.45, 0.5) < RestTone.CHIME_PEAK / 2);+ assertEquals(0, RestTone.chimeGain(0.6, 0.5), 0);+ }++ @Test+ public void bothEndInSilenceSoTheLastNoteIsNotCutOff() {+ for (boolean classic : new boolean[] {false, true}) {+ short[] s = RestTone.render(classic);+ double secs = s.length / (double) RestTone.RATE;+ assertEquals(0, peak(s, secs - RestTone.TAIL_SEC + 0.01, secs));+ }+ }++ @Test+ public void neverClips() {+ for (boolean classic : new boolean[] {false, true}) {+ for (short v : RestTone.render(classic)) assertTrue(Math.abs(v) <= 32767);+ }+ assertTrue(peak(RestTone.renderChime(), 0, 1) < 32767);+ }+}diff --git a/frontend/src/lib/rest-alert.js b/frontend/src/lib/rest-alert.jsindex d304ebfff..72a7fe443 100644--- a/frontend/src/lib/rest-alert.js+++ b/frontend/src/lib/rest-alert.js@@ -28,7 +28,7 @@ export function accentColors(key) {return { accent: argb(accent), ink: argb(ink) }}-export function buildRestAlert({ at, title, countdownTitle, totalSec, accent, sound = true, vibrate = true, alarmBuzz = false, now = Date.now() } = {}) {+export function buildRestAlert({ at, title, countdownTitle, totalSec, accent, sound = true, classic = false, vibrate = true, alarmBuzz = false, now = Date.now() } = {}) {if (typeof at !== 'number' || !(at > now)) return nullconst totalMs = Math.max(1000, Math.round((totalSec > 0 ? totalSec : (at - now) / 1000) * 1000))const colors = accentColors(accent)@@ -48,6 +48,9 @@ export function buildRestAlert({ at, title, countdownTitle, totalSec, accent, soat,allowWhileIdle: true,sound: !!sound,+ // Settings → Sound: the native side plays the same end tone the page does, the chime by+ // default or the classic beeps. Only `true` means classic, as in lib/sound.js chime().+ classic: classic === true,vibrate: !!vibrate,// Settings → "Vibrate when the phone is on silent" (#375): the end buzzes as an alarm, which// silent mode lets through, instead of through the notification channel, which it mutes.@@ -87,7 +90,7 @@ const restPlugin = () => pluginP || (pluginP = (async () => {export function armRestAlert(at, opts = {}) {if (!MOBILE) return Promise.resolve(false)const mine = ++token- const alert = buildRestAlert({ at, title: opts.title, countdownTitle: opts.countdownTitle, totalSec: opts.totalSec, accent: opts.accent, sound: opts.sound, vibrate: opts.vibrate !== false, alarmBuzz: !!opts.alarmBuzz })+ const alert = buildRestAlert({ at, title: opts.title, countdownTitle: opts.countdownTitle, totalSec: opts.totalSec, accent: opts.accent, sound: opts.sound, classic: opts.classic === true, vibrate: opts.vibrate !== false, alarmBuzz: !!opts.alarmBuzz })if (!alert) return Promise.resolve(false)// Outside the chain and never awaited: the alarm, its tone and the alarm buzz do not need the// notification permission, and a dialog left open while the phone is put away must not hold@@ -204,6 +207,7 @@ async function deliver(alert) {at: alert.at,title: alert.title,sound: alert.sound,+ classic: alert.classic,// The end of a rest the app is not in front for: the notification, or the buzz standing in// for it where notifications are off. With the app in front the page buzzes (lib/sound.js).vibrate: alert.vibrate,diff --git a/frontend/src/lib/rest-alert.native.test.js b/frontend/src/lib/rest-alert.native.test.jsindex d8fa2ccd8..48265def8 100644--- a/frontend/src/lib/rest-alert.native.test.js+++ b/frontend/src/lib/rest-alert.native.test.js@@ -144,6 +144,16 @@ describe('the alarm buzz in the Android app', () => {expect(calls.schedule.at(-1)).toMatchObject({ alarmBuzz: false })})+ it('hands the plugin the end tone Settings → Sound picked', async () => {+ h.platform = 'android'+ const calls = capture()+ const alert = await import('./rest-alert.js')+ await alert.armRestAlert(Date.now() + 90_000, { totalSec: 90, sound: true })+ expect(calls.schedule.at(-1)).toMatchObject({ sound: true, classic: false })+ await alert.armRestAlert(Date.now() + 90_000, { totalSec: 90, sound: true, classic: true })+ expect(calls.schedule.at(-1)).toMatchObject({ sound: true, classic: true })+ })+it('buzzAsAlarm reaches the plugin with the pattern and answers true', async () => {h.platform = 'android'const calls = capture()diff --git a/frontend/src/lib/rest-alert.test.js b/frontend/src/lib/rest-alert.test.jsindex f36f3965a..196e3ae4f 100644--- a/frontend/src/lib/rest-alert.test.js+++ b/frontend/src/lib/rest-alert.test.js@@ -31,6 +31,14 @@ describe('buildRestAlert', () => {expect(buildRestAlert({ at: now + 1000, sound: false, now }).sound).toBe(false)})+ // Discord "Rest Timer Sound Notification too Quiet": the locked phone played the old beeps+ // whatever Settings → Sound said. The chime is the default; only `true` picks the classic beeps.+ it('carries Settings → Sound to the native tone, chime by default', () => {+ expect(buildRestAlert({ at: now + 1000, now }).classic).toBe(false)+ expect(buildRestAlert({ at: now + 1000, classic: true, now }).classic).toBe(true)+ expect(buildRestAlert({ at: now + 1000, classic: 'kind', now }).classic).toBe(false)+ })+// A channel keeps the vibration it was created with, so Vibrate off cannot switch 'rest-over'// off: that end goes out on a channel that never buzzes.it('buzzes on the rest channel by default, and uses the quiet one when Vibrate is off', () => {diff --git a/frontend/src/lib/sound.js b/frontend/src/lib/sound.jsindex e81b00f7a..b7711ba41 100644--- a/frontend/src/lib/sound.js+++ b/frontend/src/lib/sound.js@@ -102,6 +102,8 @@ export function beep(enabled, freq, dur, when) {// sound" (S.classicChime) picks between the two without reviving the three separate beep() calls// this replaced: CLASSIC is the exact same three tones, just driven through the same tone() path// as the chime below, so both share one gating/try-catch and one sleepAfter bookkeeping.+// The Android app plays this end tone natively while the app is in the background or the screen+// is off (android/.../RestTone.java). Change the notes or the shape here, change them there too.export const CHIME_PEAK = 0.9const CHIME = [[1319, 0.16, 0], [988, 0.16, 0.22], [1319, 0.5, 0.44]]const CLASSIC = [[880, 0.15, 0], [880, 0.15, 0.25], [1320, 0.4, 0.5]]diff --git a/frontend/src/store/useUI.js b/frontend/src/store/useUI.jsindex 5884c3eb7..fab0fc9c0 100644--- a/frontend/src/store/useUI.js+++ b/frontend/src/store/useUI.js@@ -26,7 +26,7 @@ const bookRestEnd = (endsAt, totalSec, kind) => {const switching = kind === 'switch'if (!MOBILE) { if (!switching) pushRestTimer(Math.max(1, Math.round((endsAt - Date.now()) / 1000))); return }const { S } = useStore.getState()- armRestAlert(endsAt, { title: switching ? t('Switch sides') : t('Rest’s over. Next set!'), countdownTitle: switching ? t('Switch sides') : t('Rest'), totalSec, accent: accentValue(S), sound: !!S.sound, vibrate: S.vibrate !== false, alarmBuzz: S.vibrate !== false && !!S.vibrateOnSilent })+ armRestAlert(endsAt, { title: switching ? t('Switch sides') : t('Rest’s over. Next set!'), countdownTitle: switching ? t('Switch sides') : t('Rest'), totalSec, accent: accentValue(S), sound: !!S.sound, classic: S.classicChime === true, vibrate: S.vibrate !== false, alarmBuzz: S.vibrate !== false && !!S.vibrateOnSilent }).then(ok => {// Only for the rest that asked: one skipped or moved since then has booked its own end.const tm = useUI.getState().timerdiff --git a/frontend/src/store/useUI.silent-buzz.test.js b/frontend/src/store/useUI.silent-buzz.test.jsindex b1760d0e7..e54852b78 100644--- a/frontend/src/store/useUI.silent-buzz.test.js+++ b/frontend/src/store/useUI.silent-buzz.test.js@@ -51,6 +51,16 @@ describe('vibrate on silent', () => {expect(armRestAlert).toHaveBeenLastCalledWith(expect.any(Number), expect.objectContaining({ alarmBuzz: false }))})+ // Discord "Rest Timer Sound Notification too Quiet": the locked phone's tone follows Settings → Sound.+ it('tells the native alarm which end tone to play', () => {+ withSettings({ sound: true })+ useUI.getState().startRest(60)+ expect(armRestAlert).toHaveBeenLastCalledWith(expect.any(Number), expect.objectContaining({ sound: true, classic: false }))+ withSettings({ sound: true, classicChime: true })+ useUI.getState().startRest(60)+ expect(armRestAlert).toHaveBeenLastCalledWith(expect.any(Number), expect.objectContaining({ sound: true, classic: true }))+ })+it('the end of a rest seen on screen buzzes through alertBuzz', async () => {withSettings({ vibrate: true, vibrateOnSilent: true })useUI.getState().startRest(2)