mirror of
https://github.com/pvrzz/atmosphere.git
synced 2026-11-29 05:22:26 +00:00
Responsive mini player, set details, cleaner titles, featured artists
- Mini player reflows by size: portrait card, wide strip with art left and controls right, or tiny - Lyrics preview in the mini player when there's room; lyrics and queue are exclusive - Mini player can't be maximised and remembers its size - SoundCloud sets read track details in parallel and split "Artist - Title" - YouTube titles drop (Official Music Video) and similar tags; Topic/VEVO channels become the artist - Comma lists and feat. credits in titles count as separate artists - Artist profiles show Featured on with the release type and which song - Downloaded files keep the source description and link in their notes - Opus is labelled Opus; DRC-compressed YouTube audio is avoided
This commit is contained in:
+210
-65
@@ -1,19 +1,27 @@
|
||||
// atmosphere · miniplayer.js · Compact always-on-top player with optional cover, blurred backdrop and an editable queue
|
||||
// atmosphere · miniplayer.js · Compact always-on-top player that reflows by size: portrait card, wide strip or tiny, with a lyrics or queue panel when there's room
|
||||
const Mini = {
|
||||
on: false,
|
||||
restore: null,
|
||||
prefs: { cover: true, blur: true, queue: false, pin: true },
|
||||
prefs: { cover: true, blur: true, panel: "none", pin: true },
|
||||
dragFrom: null,
|
||||
layout: "",
|
||||
panelShown: false,
|
||||
sizeTimer: 0,
|
||||
lyricsFor: null,
|
||||
};
|
||||
|
||||
const MINI_W = 340;
|
||||
const MINI_BASE = 168;
|
||||
const MINI_COVER = 300;
|
||||
const MINI_QUEUE = 232;
|
||||
const MINI_MIN = { w: 260, h: 96 };
|
||||
const MINI_MAX = { w: 900, h: 900 };
|
||||
const MINI_CORE = 168;
|
||||
const MINI_STRIP = 112;
|
||||
const MINI_PANEL = 232;
|
||||
|
||||
function miniLoad() {
|
||||
try {
|
||||
Object.assign(Mini.prefs, JSON.parse(localStorage.getItem("atmo.mini") || "{}"));
|
||||
const saved = JSON.parse(localStorage.getItem("atmo.mini") || "{}");
|
||||
if (saved.queue && !saved.panel) saved.panel = "queue";
|
||||
delete saved.queue;
|
||||
Object.assign(Mini.prefs, saved);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
@@ -23,19 +31,34 @@ function miniSave() {
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const miniWin = () => window.__TAURI__?.window?.getCurrentWindow?.();
|
||||
|
||||
function miniHeight() {
|
||||
return MINI_BASE + (Mini.prefs.cover ? MINI_COVER : 0) + (Mini.prefs.queue ? MINI_QUEUE : 0);
|
||||
function miniSavedSize() {
|
||||
try {
|
||||
const s = JSON.parse(localStorage.getItem("atmo.miniSize") || "null");
|
||||
if (s && s.w >= MINI_MIN.w && s.h >= MINI_MIN.h) return s;
|
||||
} catch {}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function miniResize() {
|
||||
const miniWin = () => window.__TAURI__?.window?.getCurrentWindow?.();
|
||||
|
||||
function miniIdealHeight(w, wide) {
|
||||
const panel = Mini.prefs.panel !== "none";
|
||||
if (wide) return MINI_STRIP + (panel ? MINI_PANEL : 0);
|
||||
return MINI_CORE + (Mini.prefs.cover ? Math.min(w - 40, 300) : 0) + (panel ? MINI_PANEL : 0);
|
||||
}
|
||||
|
||||
async function miniSetSize(w, h) {
|
||||
const win = miniWin();
|
||||
const dpi = window.__TAURI__?.dpi;
|
||||
if (!win || !dpi) return;
|
||||
const min = MINI_BASE + (Mini.prefs.queue ? 120 : 0);
|
||||
await win.setMinSize(new dpi.LogicalSize(300, min)).catch(() => {});
|
||||
await win.setSize(new dpi.LogicalSize(MINI_W, miniHeight())).catch(() => {});
|
||||
const cw = Math.max(MINI_MIN.w, Math.min(MINI_MAX.w, Math.round(w)));
|
||||
const ch = Math.max(MINI_MIN.h, Math.min(MINI_MAX.h, Math.round(h)));
|
||||
await win.setSize(new dpi.LogicalSize(cw, ch)).catch(() => {});
|
||||
}
|
||||
|
||||
async function miniFit() {
|
||||
const w = innerWidth;
|
||||
await miniSetSize(w, miniIdealHeight(w, Mini.layout === "wide"));
|
||||
}
|
||||
|
||||
async function openMini() {
|
||||
@@ -45,16 +68,22 @@ async function openMini() {
|
||||
closeFx();
|
||||
Mini.on = true;
|
||||
document.body.classList.add("mini-mode");
|
||||
$("#mini").hidden = false;
|
||||
$("#mini").classList.toggle("mac", isMac);
|
||||
const box = $("#mini");
|
||||
box.hidden = false;
|
||||
box.classList.toggle("mac", isMac);
|
||||
const win = miniWin();
|
||||
if (win) {
|
||||
const dpi = window.__TAURI__?.dpi;
|
||||
if (win && dpi) {
|
||||
Mini.restore = { pos: await win.outerPosition().catch(() => null), size: await win.outerSize().catch(() => null), max: await win.isMaximized().catch(() => false) };
|
||||
if (Mini.restore.max) await win.unmaximize().catch(() => {});
|
||||
await miniResize();
|
||||
await win.setMaximizable(false).catch(() => {});
|
||||
await win.setMinSize(new dpi.LogicalSize(MINI_MIN.w, MINI_MIN.h)).catch(() => {});
|
||||
await win.setMaxSize(new dpi.LogicalSize(MINI_MAX.w, MINI_MAX.h)).catch(() => {});
|
||||
const saved = miniSavedSize();
|
||||
await miniSetSize(saved?.w || 340, saved?.h || miniIdealHeight(340, false));
|
||||
await win.setAlwaysOnTop(!!Mini.prefs.pin).catch(() => {});
|
||||
}
|
||||
renderMini();
|
||||
buildMini();
|
||||
}
|
||||
|
||||
async function closeMini() {
|
||||
@@ -62,12 +91,16 @@ async function closeMini() {
|
||||
Mini.on = false;
|
||||
document.body.classList.remove("mini-mode");
|
||||
$("#mini").hidden = true;
|
||||
$("#mini").replaceChildren();
|
||||
Mini.lyricsFor = null;
|
||||
const win = miniWin();
|
||||
const dpi = window.__TAURI__?.dpi;
|
||||
const r = Mini.restore;
|
||||
Mini.restore = null;
|
||||
if (!win || !dpi) return;
|
||||
await win.setAlwaysOnTop(false).catch(() => {});
|
||||
await win.setMaxSize(null).catch(() => {});
|
||||
await win.setMaximizable(true).catch(() => {});
|
||||
await win.setMinSize(new dpi.LogicalSize(900, 620)).catch(() => {});
|
||||
if (r?.size) await win.setSize(new dpi.PhysicalSize(r.size.width, r.size.height)).catch(() => {});
|
||||
if (r?.pos) await win.setPosition(new dpi.PhysicalPosition(r.pos.x, r.pos.y)).catch(() => {});
|
||||
@@ -75,15 +108,17 @@ async function closeMini() {
|
||||
}
|
||||
|
||||
async function miniToggle(key) {
|
||||
Mini.prefs[key] = !Mini.prefs[key];
|
||||
if (key === "lyrics" || key === "queue") {
|
||||
Mini.prefs.panel = Mini.prefs.panel === key ? "none" : key;
|
||||
} else Mini.prefs[key] = !Mini.prefs[key];
|
||||
miniSave();
|
||||
if (key === "pin") await miniWin()?.setAlwaysOnTop(Mini.prefs.pin).catch(() => {});
|
||||
if (key === "cover" || key === "queue") await miniResize();
|
||||
renderMini();
|
||||
const needsFit = key === "lyrics" || key === "queue" || (key === "cover" && Mini.layout !== "wide");
|
||||
buildMini();
|
||||
if (needsFit) await miniFit();
|
||||
}
|
||||
|
||||
function miniButton(key, iconName, label) {
|
||||
const on = !!Mini.prefs[key];
|
||||
function miniButton(key, iconName, label, on) {
|
||||
return h("button", { class: "icon-btn mini-opt", "aria-pressed": String(on), "aria-label": label, title: label, onclick: () => miniToggle(key) }, icon(iconName));
|
||||
}
|
||||
|
||||
@@ -129,56 +164,143 @@ function moveInQueue(from, to) {
|
||||
Player.persist();
|
||||
}
|
||||
|
||||
function renderMini() {
|
||||
function buildMini() {
|
||||
const box = $("#mini");
|
||||
if (!box || !Mini.on) return;
|
||||
const t = Player.current;
|
||||
const art = t?.art ? artUrl(t.art) : null;
|
||||
box.classList.toggle("with-cover", !!Mini.prefs.cover);
|
||||
box.classList.toggle("with-blur", !!Mini.prefs.blur && !!art);
|
||||
box.classList.toggle("with-queue", !!Mini.prefs.queue);
|
||||
box.style.setProperty("--mini-art", art ? `url("${art}")` : "none");
|
||||
const playing = !Player.audio.paused;
|
||||
const next = Player.queue.slice(Player.index + 1);
|
||||
const parts = [
|
||||
h("div", { class: "mini-bg", "aria-hidden": "true" }),
|
||||
h("div", { class: "mini-top", "data-tauri-drag-region": "" },
|
||||
h("span", { class: "mini-brand", "data-tauri-drag-region": "" }, "Atmosphere"),
|
||||
h("div", { class: "mini-opts" },
|
||||
miniButton("cover", "photo", Mini.prefs.cover ? "Hide cover art" : "Show cover art"),
|
||||
miniButton("blur", "droplet", Mini.prefs.blur ? "Turn off blurred backdrop" : "Blurred cover backdrop"),
|
||||
miniButton("queue", "list", Mini.prefs.queue ? "Hide queue" : "Show queue"),
|
||||
miniButton("pin", Mini.prefs.pin ? "pinned" : "pin", Mini.prefs.pin ? "Always on top: on" : "Always on top: off"),
|
||||
h("button", { class: "icon-btn", "aria-label": "Back to full window", title: "Back to full window (P)", onclick: closeMini }, icon("arrows-maximize")))),
|
||||
Mini.prefs.cover ? h("div", { class: "mini-art", "data-tauri-drag-region": "" }, art ? h("img", { src: art, alt: "", draggable: "false", "data-tauri-drag-region": "" }) : h("div", { class: "mini-art-empty" }, icon("music"))) : null,
|
||||
h("div", { class: "mini-meta" },
|
||||
h("span", { class: "mini-title", title: t?.title || "" }, t?.title || "Nothing playing"),
|
||||
h("span", { class: "mini-artist" }, t?.artist || "Pick something from your library")),
|
||||
h("div", { class: "mini-seek" },
|
||||
h("span", { class: "mini-t", id: "miniCur" }, "0:00"),
|
||||
h("input", { type: "range", class: "range", id: "miniSeek", min: "0", max: "1000", value: "0", "aria-label": "Seek" }),
|
||||
h("span", { class: "mini-t", id: "miniDur" }, "0:00")),
|
||||
h("div", { class: "mini-ctl" },
|
||||
h("button", { class: "icon-btn", "aria-label": "Previous", onclick: () => Player.prev() }, icon("player-skip-back-filled")),
|
||||
h("button", { class: "mini-play", "aria-label": playing ? "Pause" : "Play", onclick: () => Player.toggle() }, icon(playing ? "player-pause-filled" : "player-play-filled")),
|
||||
h("button", { class: "icon-btn", "aria-label": "Next", onclick: () => Player.next() }, icon("player-skip-forward-filled"))),
|
||||
Mini.prefs.queue
|
||||
? h("div", { class: "mini-queue" },
|
||||
h("div", { class: "mq-head" }, h("span", {}, next.length ? `Up next · ${next.length}` : "Up next"), next.length ? h("button", { class: "btn small ghost", onclick: () => Player.clearUpNext() }, "Clear") : null),
|
||||
next.length ? h("div", { class: "mq-list" }, ...next.slice(0, 200).map((q, k) => miniQueueRow(q, Player.index + 1 + k))) : h("p", { class: "mq-empty" }, "Nothing queued. Add songs from your library."))
|
||||
: null,
|
||||
];
|
||||
box.replaceChildren(...parts.filter(Boolean));
|
||||
const seek = $("#miniSeek");
|
||||
const p = Mini.prefs;
|
||||
box.classList.toggle("with-cover", !!p.cover);
|
||||
const art = h("div", { class: "mini-art", "data-tauri-drag-region": "" });
|
||||
const seek = h("input", { type: "range", class: "range", id: "miniSeek", min: "0", max: "1000", value: "0", "aria-label": "Seek" });
|
||||
seek.addEventListener("input", () => {
|
||||
rangeFill(seek);
|
||||
const d = Player.audio.duration;
|
||||
if (isFinite(d)) $("#miniCur").textContent = fmtDur((seek.value / 1000) * d * 1000);
|
||||
});
|
||||
seek.addEventListener("change", () => Player.seek((seek.value / 1000) * Player.audio.duration));
|
||||
box.replaceChildren(
|
||||
h("div", { class: "mini-bg", "aria-hidden": "true" }),
|
||||
h("div", { class: "mini-top", "data-tauri-drag-region": "" },
|
||||
h("span", { class: "mini-brand", "data-tauri-drag-region": "" }, "Atmosphere"),
|
||||
h("div", { class: "mini-opts" },
|
||||
miniButton("cover", "photo", p.cover ? "Hide cover art" : "Show cover art", p.cover),
|
||||
miniButton("blur", "droplet", p.blur ? "Turn off blurred backdrop" : "Blurred cover backdrop", p.blur),
|
||||
miniButton("lyrics", "microphone", p.panel === "lyrics" ? "Hide lyrics" : "Show lyrics", p.panel === "lyrics"),
|
||||
miniButton("queue", "list", p.panel === "queue" ? "Hide queue" : "Show queue", p.panel === "queue"),
|
||||
miniButton("pin", p.pin ? "pinned" : "pin", p.pin ? "Always on top: on" : "Always on top: off", p.pin),
|
||||
h("button", { class: "icon-btn", "aria-label": "Back to full window", title: "Back to full window (P)", onclick: closeMini }, icon("arrows-maximize")))),
|
||||
h("div", { class: "mini-body", "data-tauri-drag-region": "" },
|
||||
art,
|
||||
h("div", { class: "mini-info", "data-tauri-drag-region": "" },
|
||||
h("div", { class: "mini-meta", "data-tauri-drag-region": "" },
|
||||
h("span", { class: "mini-title", id: "miniTitle", "data-tauri-drag-region": "" }),
|
||||
h("span", { class: "mini-artist", id: "miniArtist", "data-tauri-drag-region": "" })),
|
||||
h("div", { class: "mini-seek" }, h("span", { class: "mini-t", id: "miniCur" }, "0:00"), seek, h("span", { class: "mini-t", id: "miniDur" }, "0:00"))),
|
||||
h("div", { class: "mini-ctl" },
|
||||
h("button", { class: "icon-btn", "aria-label": "Previous", onclick: () => Player.prev() }, icon("player-skip-back-filled")),
|
||||
h("button", { class: "mini-play", id: "miniPlay", onclick: () => Player.toggle() }),
|
||||
h("button", { class: "icon-btn", "aria-label": "Next", onclick: () => Player.next() }, icon("player-skip-forward-filled")))),
|
||||
h("div", { class: "mini-panel", id: "miniPanel" })
|
||||
);
|
||||
Mini.lyricsFor = null;
|
||||
Mini.layout = "";
|
||||
miniLayout();
|
||||
updateMini();
|
||||
renderMiniPanel();
|
||||
}
|
||||
|
||||
function updateMini() {
|
||||
const box = $("#mini");
|
||||
if (!box || !Mini.on || !$("#miniTitle")) return;
|
||||
const t = Player.current;
|
||||
const art = t?.art ? artUrl(t.art) : null;
|
||||
box.classList.toggle("with-blur", !!Mini.prefs.blur && !!art);
|
||||
box.style.setProperty("--mini-art", art ? `url("${art}")` : "none");
|
||||
$("#miniTitle").textContent = t?.title || "Nothing playing";
|
||||
$("#miniTitle").title = t?.title || "";
|
||||
$("#miniArtist").textContent = t?.artist || "Pick something from your library";
|
||||
const artBox = box.querySelector(".mini-art");
|
||||
const img = artBox.querySelector("img");
|
||||
if (art && img?.getAttribute("src") !== art) artBox.replaceChildren(h("img", { src: art, alt: "", draggable: "false", "data-tauri-drag-region": "" }));
|
||||
else if (!art && !artBox.querySelector(".mini-art-empty")) artBox.replaceChildren(h("div", { class: "mini-art-empty", "data-tauri-drag-region": "" }, icon("music")));
|
||||
const playing = !Player.audio.paused;
|
||||
const pb = $("#miniPlay");
|
||||
pb.setAttribute("aria-label", playing ? "Pause" : "Play");
|
||||
pb.replaceChildren(icon(playing ? "player-pause-filled" : "player-play-filled"));
|
||||
miniTime();
|
||||
}
|
||||
|
||||
function renderMiniPanel() {
|
||||
const panel = $("#miniPanel");
|
||||
if (!panel || !Mini.on) return;
|
||||
const kind = Mini.panelShown ? Mini.prefs.panel : "none";
|
||||
panel.dataset.kind = kind;
|
||||
if (kind === "queue") {
|
||||
Mini.lyricsFor = null;
|
||||
const next = Player.queue.slice(Player.index + 1);
|
||||
panel.replaceChildren(
|
||||
h("div", { class: "mq-head" }, h("span", {}, next.length ? `Up next · ${next.length}` : "Up next"), next.length ? h("button", { class: "btn small ghost", onclick: () => Player.clearUpNext() }, "Clear") : null),
|
||||
next.length ? h("div", { class: "mq-list" }, ...next.slice(0, 200).map((q, k) => miniQueueRow(q, Player.index + 1 + k))) : h("p", { class: "mq-empty" }, "Nothing queued. Add songs from your library."));
|
||||
return;
|
||||
}
|
||||
if (kind !== "lyrics") {
|
||||
Mini.lyricsFor = null;
|
||||
panel.replaceChildren();
|
||||
return;
|
||||
}
|
||||
const t = Player.current;
|
||||
if (t && Lyr.trackId !== t.id) loadLyrics();
|
||||
const key = `${t?.id || ""}|${Lyr.loading}|${!!Lyr.data}|${Lyr.data?.synced}`;
|
||||
if (Mini.lyricsFor === key) return;
|
||||
Mini.lyricsFor = key;
|
||||
let content;
|
||||
if (!t) content = h("p", { class: "mini-lyr-note" }, "Play something to see its lyrics.");
|
||||
else if (Lyr.loading) content = h("p", { class: "mini-lyr-note" }, "Finding lyrics…");
|
||||
else if (!Lyr.data) content = h("p", { class: "mini-lyr-note" }, "No lyrics found for this song.");
|
||||
else {
|
||||
content = h("div", { class: "mini-lyr-scroll" }, lyricLines(Lyr.data, false));
|
||||
Lyr.active = -1;
|
||||
startTick();
|
||||
}
|
||||
panel.replaceChildren(content);
|
||||
}
|
||||
|
||||
function miniLayout() {
|
||||
const box = $("#mini");
|
||||
if (!box || !Mini.on) return;
|
||||
const w = innerWidth;
|
||||
const ht = innerHeight;
|
||||
const tiny = w < 290 || ht < 132;
|
||||
const wide = !tiny && w >= 400 && w >= ht * 1.3;
|
||||
const layout = tiny ? "tiny" : wide ? "wide" : "portrait";
|
||||
const panelWant = Mini.prefs.panel !== "none";
|
||||
let panelShown = false;
|
||||
let artSize = 0;
|
||||
if (layout === "wide") {
|
||||
panelShown = panelWant && ht >= MINI_STRIP + 120;
|
||||
const strip = panelShown ? MINI_STRIP : ht;
|
||||
artSize = Math.max(56, Math.min(strip - 24, Math.round(w * 0.32), 300));
|
||||
} else if (layout === "portrait") {
|
||||
const room = ht - MINI_CORE;
|
||||
panelShown = panelWant && room - (Mini.prefs.cover ? 120 : 0) >= 120;
|
||||
const forArt = room - (panelShown ? Math.max(MINI_PANEL, room * 0.45) : 0);
|
||||
artSize = Mini.prefs.cover ? Math.max(0, Math.min(w - 40, forArt - 14, 420)) : 0;
|
||||
if (artSize < 96) artSize = 0;
|
||||
}
|
||||
box.classList.toggle("wide", layout === "wide");
|
||||
box.classList.toggle("tiny", layout === "tiny");
|
||||
box.classList.toggle("portrait", layout === "portrait");
|
||||
box.classList.toggle("has-panel", panelShown);
|
||||
box.classList.toggle("no-art", !Mini.prefs.cover || (layout === "portrait" && !artSize) || layout === "tiny");
|
||||
box.style.setProperty("--art", `${artSize}px`);
|
||||
const changed = layout !== Mini.layout || panelShown !== Mini.panelShown;
|
||||
Mini.layout = layout;
|
||||
Mini.panelShown = panelShown;
|
||||
if (changed) {
|
||||
Mini.lyricsFor = null;
|
||||
renderMiniPanel();
|
||||
}
|
||||
}
|
||||
|
||||
function miniTime() {
|
||||
if (!Mini.on) return;
|
||||
const seek = $("#miniSeek");
|
||||
@@ -191,6 +313,13 @@ function miniTime() {
|
||||
$("#miniDur").textContent = d ? fmtDur(d * 1000) : "0:00";
|
||||
}
|
||||
|
||||
function renderMini() {
|
||||
if (!Mini.on) return;
|
||||
if (!$("#miniTitle")) return buildMini();
|
||||
updateMini();
|
||||
renderMiniPanel();
|
||||
}
|
||||
|
||||
function bindMini() {
|
||||
miniLoad();
|
||||
$("#miniBtn")?.addEventListener("click", () => (Mini.on ? closeMini() : openMini()));
|
||||
@@ -199,7 +328,23 @@ function bindMini() {
|
||||
const type = e.detail.type;
|
||||
if (type === "time") return miniTime();
|
||||
if (type === "volume" || type === "fx") return;
|
||||
renderMini();
|
||||
updateMini();
|
||||
if (type === "queue" || type === "track") {
|
||||
if (Mini.prefs.panel === "queue" || type === "track") Mini.lyricsFor = null;
|
||||
renderMiniPanel();
|
||||
}
|
||||
});
|
||||
window.addEventListener("resize", () => {
|
||||
if (!Mini.on) return;
|
||||
miniLayout();
|
||||
clearTimeout(Mini.sizeTimer);
|
||||
Mini.sizeTimer = setTimeout(async () => {
|
||||
const win = miniWin();
|
||||
if (win && (await win.isMaximized().catch(() => false))) await win.unmaximize().catch(() => {});
|
||||
try {
|
||||
localStorage.setItem("atmo.miniSize", JSON.stringify({ w: innerWidth, h: innerHeight }));
|
||||
} catch {}
|
||||
}, 300);
|
||||
});
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.target.closest("input, textarea, select, [contenteditable]") || e.altKey || e.ctrlKey || e.metaKey) return;
|
||||
|
||||
Reference in New Issue
Block a user