summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/music-player.js10
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/platform.js10
-rw-r--r--packages/meshbay-hub/tests/test_android_cast.py10
3 files changed, 26 insertions, 4 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/music-player.js b/packages/meshbay-hub/src/meshbay_hub/static/music-player.js
index f0f7c47..500f518 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/music-player.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/music-player.js
@@ -6,6 +6,7 @@ import { t } from './i18n.js';
import { Icon } from './icon.js';
import { useStickyBand } from './sticky.js';
import { CHUNK_SIZE, pipelinedDownload } from './file-utils.js';
+import { playback } from './platform.js';
/**
* The Music app's persistent player bar (docs/MESHBAY_DESIGN.md §9.8).
@@ -279,6 +280,15 @@ function MusicPlayerBar({ getConnection, queue, onClose, userPrefs, onSaveQueue
for (const { url } of blobCacheRef.current.values()) URL.revokeObjectURL(url);
}, []);
+ // Held for as long as a track plays, through the advance to the next one:
+ // without it a phone freezes the page a minute after the screen goes off,
+ // and the next track never loads.
+ useEffect(() => {
+ if (!playing) return;
+ playback.keepAlive(true);
+ return () => playback.keepAlive(false);
+ }, [playing]);
+
// Screen Wake Lock, opt-in only (Settings → music_keep_screen_on) and only
// while a track is actually playing — off by default because the ordinary
// expectation, matching Spotify/Deezer, is that the phone locks on its own
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/platform.js b/packages/meshbay-hub/src/meshbay_hub/static/platform.js
index c131495..0174edc 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/platform.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/platform.js
@@ -204,6 +204,16 @@ export const folder = {
async forget() { return bridge && bridge.folder ? bridge.folder.forget() : false; },
};
+/**
+ * Music is playing: the shell keeps what playback needs awake (on a phone, the
+ * page itself with the screen off). A no-op in a browser.
+ */
+export const playback = {
+ keepAlive(on) {
+ if (bridge && bridge.playback) bridge.playback.keepAlive(on).catch(() => {});
+ },
+};
+
/** Pick a directory to add as a group root. Returns { path, name } or null. */
export const rootPicker = {
available: Boolean(bridge && bridge.rootPicker),
diff --git a/packages/meshbay-hub/tests/test_android_cast.py b/packages/meshbay-hub/tests/test_android_cast.py
index a346d15..bc5264e 100644
--- a/packages/meshbay-hub/tests/test_android_cast.py
+++ b/packages/meshbay-hub/tests/test_android_cast.py
@@ -111,11 +111,13 @@ def test_relay_calls_keep_their_order():
SRC / "bridge" / "Channels.kt")
-def test_screen_off_survival_is_switched_on_only_while_casting():
+def test_screen_off_survival_is_switched_on_only_while_casting_or_playing():
activity = _read(SRC / "MainActivity.kt")
- casting = activity.split("private fun casting(on: Boolean)", 1)[1].split("\n }", 1)[0]
- assert "web.keepVisible = on" in casting
- assert "startForegroundService(service) else stopService(service)" in casting
+ keep = activity.split("private fun keepAlive()", 1)[1].split("\n }\n", 1)[0]
+ assert "val on = casting || playing" in keep
+ assert "web.keepVisible = on" in keep
+ assert "if (!on) { stopService(service); return }" in keep
+ assert "startForegroundService(service)" in keep
assert activity.count("keepVisible =") == 1, "the page is kept visible from one place only"
view = _read(SRC / "shell" / "ShellWebView.kt")
assert "var keepVisible = false" in view