Linked playlist folders, local API, installer agreement

- Add existing folders as playlists; they're never moved or deleted by Atmosphere
- Missing linked folders show Locate and Remove, and return when the drive reconnects
- Opt-in local API for other apps: loopback only, hashed token, per-permission access,
  browser and DNS-rebinding requests refused, lockout after repeated bad tokens
- Live now-playing events, library browsing, playback and queue control, links to Get
- API guide in docs/api.md
- Agreeing on the Windows installer's licence page counts as the rights agreement
- Drop the redundant DRM line from the welcome screen
This commit is contained in:
Christian
2026-11-18 21:03:56 -05:00
parent 7329bd673b
commit a5c6c2503b
17 changed files with 1301 additions and 42 deletions
+3 -1
View File
@@ -156,6 +156,7 @@ async function init() {
bindLyrics();
bindBackup();
bindMini();
bindConnect();
bindStats();
await listen("atmosphere://job", (e) => onJob(e.payload));
await listen("atmosphere://probe", (e) => onProbe(e.payload));
@@ -1384,9 +1385,10 @@ function renderSettings() {
$("#concValue").textContent = String(s.concurrency);
$$("[data-seg=theme] button").forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.value === s.theme)));
const at = s.rightsAcceptedAt ? new Intl.DateTimeFormat(undefined, { dateStyle: "long" }).format(new Date(s.rightsAcceptedAt * 1000)) : "";
$("#rightsInfo").textContent = at ? `You confirmed it on ${at}. Withdrawing it cancels downloads and asks again.` : "Not confirmed yet.";
$("#rightsInfo").textContent = at ? `You agreed on ${at}. Withdrawing it cancels downloads and asks again in the app.` : "Not confirmed yet.";
renderTemplatePreview();
renderSignin();
if (typeof renderApiSettings === "function") renderApiSettings();
renderToolSettings();
renderLibrarySettings();
renderLyricsSettings();
+124
View File
@@ -0,0 +1,124 @@
// atmosphere · connect.js · Settings and player bridge for the opt-in local API other apps can use
const Connect = { timer: null, beat: null };
const API_DOCS = "https://github.com/pvrzz/atmosphere/blob/main/docs/api.md";
function apiSnapshot() {
const t = Player.current;
const a = Player.audio;
return {
playing: !!t && !a.paused,
track: t ? { id: t.id, title: t.title, artist: t.artist, album: t.album, albumArtist: t.albumArtist, durationMs: t.durationMs, artwork: t.art ? `/v1/artwork/${t.id}` : null } : null,
positionMs: Math.round((a.currentTime || 0) * 1000),
updatedAt: Date.now(),
volume: Player.volume,
muted: !!Player.muted,
shuffle: !!Player.shuffle,
repeat: Player.repeat || "off",
queue: { index: Player.index, length: Player.queue.length },
};
}
function apiPublishSoon() {
if (!state.settings?.apiEnabled) return;
clearTimeout(Connect.timer);
Connect.timer = setTimeout(() => invoke("api_publish", { state: apiSnapshot() }).catch(() => {}), 120);
}
function ago(secs) {
const d = Math.max(0, Date.now() / 1000 - secs);
if (d < 60) return "just now";
if (d < 3600) return `${Math.round(d / 60)} min ago`;
if (d < 86400) return `${Math.round(d / 3600)} h ago`;
return new Intl.DateTimeFormat(undefined, { dateStyle: "medium" }).format(new Date(secs * 1000));
}
async function renderApiSettings() {
const el = $("#apiStatus");
if (!el || !state.settings) return;
const st = await invoke("api_status").catch(() => null);
if (!st) return;
const s = state.settings;
el.dataset.kind = "";
if (!s.apiEnabled) el.textContent = "Off. No other app can reach Atmosphere.";
else if (st.error) {
el.textContent = st.error;
el.dataset.kind = "err";
} else if (st.running) {
el.textContent = `On at http://127.0.0.1:${st.port}${st.lastUsed ? ` · last used ${ago(st.lastUsed)}${st.lastClient ? ` by ${st.lastClient}` : ""}` : " · not used yet"}`;
el.dataset.kind = "ok";
} else el.textContent = "Starting…";
$("#apiTokenBtn").textContent = st.hasToken ? "Replace token" : "Create token";
$("#apiTokenNote").textContent = st.hasToken
? `Created ${ago(st.tokenCreated)}. Replacing it disconnects every app using the old one.`
: "Apps send this token with every request. It's shown once; Atmosphere keeps only a fingerprint.";
const port = $("#apiPort");
if (document.activeElement !== port) port.value = String(s.apiPort || 47823);
$$(".api-scope").forEach((row) => row.classList.toggle("dim", !s.apiEnabled));
}
async function newApiToken() {
const had = (await invoke("api_status").catch(() => null))?.hasToken;
if (had && !(await confirmBox("Replace the access token?", "Apps using the current token stop working until you give them the new one.", "Replace"))) return;
try {
const token = await invoke("api_new_token");
$("#apiTokenValue").textContent = token;
$("#apiTokenBox").hidden = false;
renderApiSettings();
} catch (e) {
toast(errText(e), "err");
}
}
function runApiAction(p) {
switch (p.action) {
case "status": return renderApiSettings();
case "play": return Player.play();
case "pause": return Player.pause();
case "toggle": return Player.toggle();
case "next": return Player.next();
case "previous": return Player.prev();
case "seek": return Player.seek(p.position);
case "volume": Player.muted = false; return Player.setVolume(p.volume);
case "queue": {
const tracks = (p.ids || []).map((id) => Lib.byId.get(id)).filter(Boolean);
if (!tracks.length) return;
if (p.mode === "now") return Player.setQueue(tracks, 0);
if (p.mode === "next") return Player.playNext(tracks);
return Player.addToQueue(tracks);
}
case "link":
if (Mini?.on) closeMini();
go("get");
fetchText(p.url);
return toast("Another app sent a link. Review it before saving anything.", "");
}
}
function bindConnect() {
listen("atmosphere://api", (e) => runApiAction(e.payload || {}));
window.addEventListener("player", (e) => {
if (e.detail.type !== "time") apiPublishSoon();
});
Player.audio.addEventListener("seeked", apiPublishSoon);
Connect.beat = setInterval(() => {
if (!Player.audio.paused) apiPublishSoon();
}, 10000);
$("#apiTokenBtn")?.addEventListener("click", newApiToken);
$("#apiTokenCopy")?.addEventListener("click", async () => {
await invoke("clipboard_write", { text: $("#apiTokenValue").textContent }).catch(() => {});
toast("Token copied", "ok");
});
$("#apiDocs")?.addEventListener("click", () => invoke("open_link", { url: API_DOCS }).catch(() => {}));
$("#apiEnabledToggle")?.addEventListener("change", () => setTimeout(() => { renderApiSettings(); apiPublishSoon(); }, 400));
$("#apiPort")?.addEventListener("change", async (e) => {
const n = parseInt(e.target.value, 10);
if (!(n >= 1024 && n <= 65535)) {
toast("Choose a port between 1024 and 65535.", "err");
e.target.value = String(state.settings.apiPort || 47823);
return;
}
await patch({ apiPort: n });
setTimeout(renderApiSettings, 400);
});
renderApiSettings();
}
+19 -3
View File
@@ -44,10 +44,10 @@
<div class="nav-group grow">
<div class="nav-heading-row">
<h2 class="nav-heading">Playlists</h2>
<button class="icon-btn" id="newPlaylistBtn" aria-label="New playlist" title="New playlist"><span class="i" data-icon="plus"></span></button>
<button class="icon-btn" id="newPlaylistBtn" aria-label="New playlist or add a folder" title="New playlist or add a folder" aria-haspopup="menu"><span class="i" data-icon="plus"></span></button>
</div>
<nav class="nav playlist-nav" id="playlistNav" aria-label="Playlists"></nav>
<p class="fetched-empty" id="playlistEmpty">Playlists are folders on this device. Drag songs onto one to add them.</p>
<p class="fetched-empty" id="playlistEmpty">Playlists are folders on this device. Use + to make one or add a folder you already have.</p>
</div>
<div class="sidebar-foot">
@@ -265,6 +265,22 @@
<label class="setting"><div><strong>Offer copied links</strong><span>When you switch to Atmosphere with a link copied, offer to fetch it.</span></div><input type="checkbox" class="switch" data-key="watchClipboard" /></label>
</div>
<h2 id="set-api">Connections</h2>
<p class="set-note">Let other apps on this computer, like stream overlays, status tools or your own scripts, see what's playing and control Atmosphere. It stays off unless you turn it on.</p>
<div class="group">
<label class="setting"><div><strong>Let other apps connect</strong><span class="api-status" id="apiStatus" role="status">Off</span></div><input type="checkbox" class="switch" data-key="apiEnabled" id="apiEnabledToggle" /></label>
<div class="setting">
<div><strong>Access token</strong><span id="apiTokenNote">Apps send this token with every request. It's shown once; Atmosphere keeps only a fingerprint.</span>
<div class="api-token" id="apiTokenBox" hidden><code id="apiTokenValue"></code><button class="btn small" id="apiTokenCopy" type="button">Copy</button><p class="muted small">Copy it now. It won't be shown again.</p></div>
</div>
<button class="btn" id="apiTokenBtn" type="button">Create token</button>
</div>
<label class="setting api-scope"><div><strong>See what's playing and browse the library</strong><span>Song details, artwork, playlists and live updates.</span></div><input type="checkbox" class="switch" data-key="apiRead" /></label>
<label class="setting api-scope"><div><strong>Control playback and the queue</strong><span>Play, pause, skip, seek, volume and queueing songs.</span></div><input type="checkbox" class="switch" data-key="apiControl" /></label>
<label class="setting api-scope"><div><strong>Send links to Get</strong><span>Opens the link in Atmosphere. Nothing is saved until you review and confirm it.</span></div><input type="checkbox" class="switch" data-key="apiLinks" /></label>
<div class="setting api-scope"><div><strong>Port</strong><span>Only reachable from this computer. <button class="link" id="apiDocs" type="button">How apps connect</button></span></div><input class="text short" id="apiPort" inputmode="numeric" spellcheck="false" aria-label="API port" /></div>
</div>
<h2 id="set-storage">Storage</h2>
<p class="set-note">Temporary files are removed automatically on every launch and exit. Here's everything else Atmosphere keeps.</p>
<div class="group" id="storageList"></div>
@@ -333,7 +349,6 @@
<label class="pledge"><input type="checkbox" class="pledge-check" /><span>I'll only download media I <b>own</b>, that the <b>rights holder has allowed</b> me to download, or that's under a licence that permits it, such as artist-enabled downloads or Creative Commons.</span></label>
<label class="pledge"><input type="checkbox" class="pledge-check" /><span>I understand that downloading without permission can infringe copyright and break a site's terms, and that <b>I'm responsible</b> for how I use Atmosphere.</span></label>
<label class="pledge"><input type="checkbox" class="pledge-check" /><span>I won't share downloaded media unless its licence or the rights holder allows it.</span></label>
<p class="fine">Atmosphere never bypasses DRM or paywalls, and skips preview-only media.</p>
<button class="btn primary big wide" id="obAccept" disabled>Agree and continue</button>
</section>
@@ -359,5 +374,6 @@
<script src="lyrics.js"></script>
<script src="stats.js"></script>
<script src="miniplayer.js"></script>
<script src="connect.js"></script>
</body>
</html>
+89 -6
View File
@@ -335,7 +335,7 @@ function renderPlaylistNav() {
const lists = Lib.data?.playlists || [];
nav.replaceChildren(
...lists.map((p) => {
const b = h("button", { class: "nav-item small", "data-playlist": p.name, onclick: () => openLib("playlist", p.name) }, icon("playlist"), h("span", { class: "nav-label" }, p.name), h("span", { class: "nav-meta" }, String(p.order.length)));
const b = h("button", { class: `nav-item small ${p.missing ? "missing" : ""}`, "data-playlist": p.name, title: p.missing ? `Folder not found: ${p.path}` : p.linked ? p.path : null, onclick: () => openLib("playlist", p.name) }, icon(p.missing ? "alert-circle" : p.linked ? "folder" : "playlist"), h("span", { class: "nav-label" }, p.name), h("span", { class: "nav-meta" }, p.missing ? "Missing" : String(p.order.length)));
b.addEventListener("dragover", (e) => { if (e.dataTransfer.types.includes("application/x-atmo-tracks")) { e.preventDefault(); b.classList.add("drop"); } });
b.addEventListener("dragleave", () => b.classList.remove("drop"));
b.addEventListener("drop", (e) => {
@@ -362,7 +362,11 @@ async function addToPlaylist(name, tracks) {
}
async function removeFromPlaylist(name, tracks) {
const ok = await confirmBox(`Remove ${tracks.length === 1 ? `“${tracks[0].title}”` : plural(tracks.length, "song")} from ${name}?`, `The playlist's copy goes to your ${isMac ? "Trash" : "Recycle Bin"}. The song stays in your library.`, "Remove");
const pl = (Lib.data?.playlists || []).find((x) => x.name === name);
const bin = isMac ? "Trash" : "Recycle Bin";
const ok = pl?.linked
? await confirmBox(`Remove ${tracks.length === 1 ? `“${tracks[0].title}”` : plural(tracks.length, "song")} from ${name}?`, `This is your own folder, so the file itself moves from it to your ${bin}. If it's the only copy, it leaves your library too. You can restore it from the ${bin}.`, "Move to " + bin)
: await confirmBox(`Remove ${tracks.length === 1 ? `“${tracks[0].title}”` : plural(tracks.length, "song")} from ${name}?`, `The playlist's copy goes to your ${isMac ? "Trash" : "Recycle Bin"}. The song stays in your library.`, "Remove");
if (!ok) return;
try {
await invoke("playlist_remove", { name, ids: tracks.map((t) => t.id) });
@@ -409,6 +413,49 @@ function modal(title, body, actions) {
const confirmBox = (title, text, label) => modal(title, h("p", { class: "muted" }, text), [{ label: "Cancel", value: false }, { label, value: true, primary: true }]);
async function linkFolder() {
try {
const name = await invoke("playlist_link");
if (!name) return;
toast(`Added “${name}” as a playlist. Atmosphere won't move or delete the folder.`, "ok");
await loadLibrary();
openLib("playlist", name);
} catch (e) {
toast(errText(e), "err");
}
}
async function relocateFolder(name) {
try {
if (await invoke("playlist_relocate", { name })) {
toast(`Found “${name}” again`, "ok");
await loadLibrary();
}
} catch (e) {
toast(errText(e), "err");
}
}
async function unlinkFolder(name) {
const ok = await confirmBox(`Remove “${name}” from Atmosphere?`, "The folder and every song in it stay exactly where they are on your device. Atmosphere just stops showing it as a playlist.", "Remove");
if (!ok) return;
try {
await invoke("playlist_unlink", { name });
openLib("songs", null, false);
} catch (e) {
toast(errText(e), "err");
}
}
function playlistAddMenu(e) {
e.stopPropagation();
const r = e.currentTarget.getBoundingClientRect();
menuAt(r.left, r.bottom + 4, [
{ label: "New playlist", run: () => newPlaylist() },
{ label: "Add existing folder…", run: linkFolder },
]);
}
async function newPlaylist(tracks = []) {
const input = h("input", { class: "text wide", placeholder: "Playlist name", "aria-label": "Playlist name" });
const ok = await modal("New playlist", h("div", { class: "stack" }, input, h("p", { class: "muted small" }, "It's a folder of songs on this device. Phones, USB drives and other players can use it as-is.")), [{ label: "Cancel", value: false }, { label: "Create", value: true, primary: true }]);
@@ -608,6 +655,20 @@ function mosaic(tracks) {
function playlistView(root, name) {
const p = (Lib.data?.playlists || []).find((x) => x.name === name);
if (!p) return root.append(libHead("Playlist not found", "Its folder may have been moved or deleted."));
if (p.missing) {
root.append(
libHead(p.name, "Linked folder"),
h("div", { class: "lib-empty missing-folder" },
icon("alert-circle"),
h("h2", {}, "This folder can't be found"),
h("p", {}, "It may have been moved or renamed, or it's on a drive that isn't connected. Atmosphere checks again every few seconds and brings it back as soon as it's there."),
h("code", { class: "path" }, p.path),
h("div", { class: "row center" },
h("button", { class: "btn primary", onclick: () => relocateFolder(p.name) }, icon("folder-open"), "Locate folder…"),
h("button", { class: "btn ghost", onclick: () => unlinkFolder(p.name) }, "Remove from Atmosphere")))
);
return;
}
const tracks = p.order.map((id) => Lib.byId.get(id)).filter(Boolean);
const dur = tracks.reduce((n, t) => n + (t.durationMs || 0), 0);
const title = h("h1", { class: "hero-title editable", contenteditable: "plaintext-only", spellcheck: "false", "aria-label": "Playlist name", onkeydown: (e) => { if (e.key === "Enter") { e.preventDefault(); e.target.blur(); } } }, p.name);
@@ -627,17 +688,19 @@ function playlistView(root, name) {
h("div", { class: "hero-bg", style: tracks[0]?.art ? `background-image:url("${artUrl(tracks[0].art)}")` : "" }),
mosaic(tracks),
h("div", { class: "hero-meta" },
h("div", { class: "kind-line" }, h("span", { class: "kind-btn", style: "cursor:default" }, icon("folder"), "Playlist folder")),
h("div", { class: "kind-line" }, h("span", { class: "kind-btn", style: "cursor:default" }, icon(p.linked ? "link" : "folder"), p.linked ? "Your folder" : "Playlist folder")),
title,
h("p", { class: "view-sub" }, `${plural(tracks.length, "song")}${dur ? " · " + fmtLong(dur) : ""}`),
h("button", { class: "link path", title: "Open this folder", onclick: () => invoke("reveal", { path: p.path }) }, p.path),
h("div", { class: "row" }, ...playBtns(tracks),
h("button", { class: "btn ghost", onclick: async () => { try { const n = await invoke("playlist_add_files", { name: p.name }); if (n) toast(`Added ${plural(n, "song")}`, "ok"); } catch (e) { toast(errText(e), "err"); } } }, icon("plus"), "Add files…"),
h("button", { class: "btn ghost danger", onclick: async () => { if (await confirmBox(`Delete “${p.name}”?`, "The playlist folder goes to your Recycle Bin or Trash. Songs in your library aren't touched.", "Delete")) { await invoke("playlist_delete", { name: p.name }).catch((e) => toast(errText(e), "err")); openLib("songs", null, false); } } }, icon("trash"), "Delete"))))
p.linked
? h("button", { class: "btn ghost", onclick: () => unlinkFolder(p.name) }, icon("x"), "Remove from Atmosphere")
: h("button", { class: "btn ghost danger", onclick: async () => { if (await confirmBox(`Delete “${p.name}”?`, "The playlist folder goes to your Recycle Bin or Trash. Songs in your library aren't touched.", "Delete")) { await invoke("playlist_delete", { name: p.name }).catch((e) => toast(errText(e), "err")); openLib("songs", null, false); } } }, icon("trash"), "Delete"))))
);
if (Lib.back.length) root.firstChild.prepend(h("button", { class: "icon-btn back on-hero", "aria-label": "Back", onclick: libBack }, icon("arrow-left")));
if (!tracks.length) return root.append(h("div", { class: "lib-empty slim" }, h("p", {}, "Drag songs onto this playlist in the sidebar, use “Add to playlist” from any song's menu, or add files from your computer.")));
root.append(h("div", { class: "pad-x" }, h("p", { class: "muted small hint-line" }, "Drag rows to reorder. The order is saved in the folder's playlist.m3u8, so other players see it too."), trackList(tracks, { cover: true, playlist: p.name })));
root.append(h("div", { class: "pad-x" }, h("p", { class: "muted small hint-line" }, p.linked ? "This is your own folder; songs in subfolders are included. Drag rows to reorder, saved in a playlist.m3u8 inside it." : "Drag rows to reorder. The order is saved in the folder's playlist.m3u8, so other players see it too."), trackList(tracks, { cover: true, playlist: p.name })));
}
function likedView(root) {
@@ -755,7 +818,7 @@ async function cleanStorage(ids) {
/* boot */
function bindLibrary() {
$$("[data-lib]").forEach((b) => b.addEventListener("click", () => { Lib.back = []; openLib(b.dataset.lib, null, false); }));
$("#newPlaylistBtn").addEventListener("click", () => newPlaylist());
$("#newPlaylistBtn").addEventListener("click", playlistAddMenu);
$("#libScroll").addEventListener("scroll", () => Lib.drawSongs && requestAnimationFrame(Lib.drawSongs), { passive: true });
window.addEventListener("resize", () => Lib.drawSongs && Lib.drawSongs());
window.addEventListener("player", (e) => { if (e.detail.type === "track") markPlaying(); });
@@ -844,6 +907,26 @@ function playlistMenu(e, name) {
const p = (Lib.data?.playlists || []).find((x) => x.name === name);
if (!p) return;
const tracks = p.order.map((id) => Lib.byId.get(id)).filter(Boolean);
if (p.missing) {
return menuAt(e.clientX, e.clientY, [
{ label: "Locate folder…", run: () => relocateFolder(name) },
"-",
{ label: "Remove from Atmosphere…", run: () => unlinkFolder(name) },
]);
}
if (p.linked) {
return menuAt(e.clientX, e.clientY, [
{ label: "Play", disabled: !tracks.length, run: () => playList(tracks, 0, false) },
{ label: "Shuffle", disabled: !tracks.length, run: () => playList(tracks, Math.floor(Math.random() * tracks.length), true) },
"-",
{ label: "Add files…", run: () => invoke("playlist_add_files", { name }).catch((err) => toast(errText(err), "err")) },
{ label: "Rename in Atmosphere…", run: () => renamePlaylist(name) },
{ label: "Show in folder", run: () => invoke("reveal", { path: p.path }) },
{ label: "Locate a different folder…", run: () => relocateFolder(name) },
"-",
{ label: "Remove from Atmosphere…", run: () => unlinkFolder(name) },
]);
}
menuAt(e.clientX, e.clientY, [
{ label: "Play", disabled: !tracks.length, run: () => playList(tracks, 0, false) },
{ label: "Shuffle", disabled: !tracks.length, run: () => playList(tracks, Math.floor(Math.random() * tracks.length), true) },
+20
View File
@@ -949,3 +949,23 @@ body.mini-mode > *:not(#mini):not(.toasts):not(.modal-wrap):not(script) { displa
@media (prefers-reduced-motion: reduce) { .mini-bg, .mini-play { transition: none; } }
.mini.mac .mini-top { padding-left: 78px; }
.mini.mac .mini-brand { display: none; }
/* linked playlist folders */
.nav-item.missing { color: var(--text-3); }
.nav-item.missing .nav-meta { color: var(--warn, #d9a441); font-size: 11px; }
.missing-folder { max-width: 520px; margin: var(--s6) auto; text-align: center; gap: var(--s3); }
.missing-folder > .i svg { width: 36px; height: 36px; color: var(--warn, #d9a441); }
.missing-folder h2 { font: 650 18px/1.3 var(--font-display); margin: 0; }
.missing-folder p { margin: 0; color: var(--text-2); }
.missing-folder code.path { font-size: 12px; color: var(--text-3); overflow-wrap: anywhere; padding: 6px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--hairline); }
.row.center { justify-content: center; }
/* connections */
.api-status[data-kind="ok"] { color: var(--ok); }
.api-status[data-kind="err"] { color: var(--err); }
.api-token { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s2); }
.api-token code { font: 12px/1.4 ui-monospace, "Cascadia Code", Consolas, monospace; padding: 6px 10px; border-radius: 8px; background: var(--surface-2, var(--surface)); border: 1px solid var(--border); user-select: all; overflow-wrap: anywhere; max-width: 100%; }
.api-token p { flex-basis: 100%; margin: 0; }
.api-scope.dim { opacity: 0.55; }
#apiDocs { color: var(--accent); font: inherit; padding: 0; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); }
#apiDocs:hover { text-decoration-color: currentColor; }