android: the phone, on the real core — the mockup shell, playback, the media card, the catalog, the resolver, Save, the dev flavour

The same Tauri 2 project builds for Android: mobile.html as a third Vite
entry (src/mobile/, the mockup on real data), tauri.android.conf.json, the
mobile stubs (updater, lyric alignment, vocal separation), rustls reqwest
on Android, the AAudio buffer, and a hand-driven detour build
(src-tauri/android/{env,build,deploy,dev}.sh) while Developer Mode is off.
ANDROID.md is the recipe.

Playback: the media-session plugin crate (lock-screen card, MediaStyle
notification, audio focus, headset buttons, a foreground service that
promotes itself first — Android 14 kills the app otherwise), session
restore across reload and restart, solid chrome after measuring the
backdrop-filter lag.

The catalog: Search is the desktop's top bar (the top-result rule, artist
cards), the artist page and the record page are the desktop's, Home is the
desktop's landing page, Gaps per followed shelf. Playing goes through the
desktop's own source rules, moved verbatim from state.svelte.js into
src/lib/sources.js so both apps share one resolver; the phone readies the
next three tracks and crosses boundaries gapless. Save fetches a record or
a track into the library by the download rules; Transfers shows the
burst. The raw Soulseek search stays, offered on request, a peer's copy
streaming with the lane rising as the bytes arrive. Community is the
Soulseek side (rooms, chat, buddies); the private layer waits.

The opener and storage plugins (social links, the picked library folder,
all-files access), the volume normalization switch, and the harness:
tests/mobile/smoke.mjs walks the mock (a fake network behind
src/lib/events.js) and the real phone over CDP, perf.mjs measures frames.
This commit is contained in:
KeelrLeek committed 2026-09-13 09:30:06 -05:00
1 parent 972dd103cb
commit bb828ff2dc
102 files changed
+12258 -830

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
/* The phone's media session: the lock-screen card, the shade's transport,
the headset buttons, audio focus. The card is a mirror of the bar — fed
on every change of track or transport, topped up now and then so its
progress does not drift — and its buttons come back as actions the
player carries out. Everything real lives in the plugin
(crates/tauri-plugin-media-session); this is the wiring. */
import { invoke, addPluginListener } from "@tauri-apps/api/core";
import { player, hooks, toggle, next, prev, seekSecs } from "./player.svelte.js";
import { art } from "./art.svelte.js";
let lastArtKey = null;
let timer = null;
let bound = false;
async function push() {
timer = null;
const t = player.track;
if (!t) {
lastArtKey = null;
await invoke("plugin:media-session|clear").catch(() => {});
return;
}
const key = player.album?.art_path || null;
const url = key ? art[key] : "";
const state = {
title: t.title,
artist: t.artist || player.album?.artist || "",
album: player.album?.title || "",
playing: player.status === "playing" || player.status === "buffering",
position: player.position,
duration: player.duration,
artKey: key,
art: null,
hasNext: player.qi + 1 < player.queue.length || player.repeat > 0,
hasPrev: true,
};
/* the cover's bytes ride along once per record, and only once they exist */
if (key && key !== lastArtKey && url && url.startsWith("data:image")) {
state.art = url.slice(url.indexOf(",") + 1);
lastArtKey = key;
}
await invoke("plugin:media-session|update", { state }).catch(() => {});
}
/** Coalesce a burst of changes (track, then status, then position) into one card update. */
export function syncMedia() {
if (timer) clearTimeout(timer);
timer = setTimeout(push, 60);
}
/** Wire the card to the player. Harmless where there is no plugin. */
export async function bindMedia() {
if (bound) return;
bound = true;
hooks.mediaSync = syncMedia;
try {
await addPluginListener("media-session", "action", (p) => {
const playing = player.status === "playing" || player.status === "buffering";
switch (p?.action) {
case "play": if (!playing) toggle(); break;
case "pause": if (playing) toggle(); break;
case "toggle": toggle(); break;
case "next": next(); break;
case "prev": prev(); break;
case "seek": if (typeof p.position === "number" && p.position >= 0) seekSecs(p.position); break;
case "stop": if (playing) toggle(); break;
}
});
} catch {
/* not a phone */
}
/* the card interpolates its progress from the last update; a top-up
every half minute keeps a long track honest */
setInterval(() => { if (player.track) syncMedia(); }, 30_000);
}