fix(nav): show request panel on home tab select

Jellyfin HomeView only handles Home/Favorites; stop its tabchange handler for Request and sync .hide/is-active so the embedded UI is visible.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Michael SloanandCursor committed 2026-08-02 17:03:57 -04:00
1 parent 0a5ea07838
commit 2a1fcf0588
8 files changed
+127 -25

No files matched your search

+108 -7
View File
@@ -8,6 +8,7 @@
let ensuring = null;
let assetsPromise = null;
let guardAttached = false;
function ensureStyle() {
if (document.getElementById(STYLE_ID)) {
@@ -17,7 +18,7 @@
const style = document.createElement("style");
style.id = STYLE_ID;
style.textContent = [
".jf-request-tab-panel{padding:1rem 1.25rem 2rem;box-sizing:border-box;}",
".jf-request-tab-panel{padding:1rem 1.25rem 2rem;box-sizing:border-box;min-height:50vh;}",
".jf-request-tab-panel .req-embed{max-width:1400px;margin:0 auto;}",
".jf-request-menu-item{align-items:center;color:inherit;display:flex!important;gap:1rem;min-height:3rem;padding:.75rem 1.25rem;text-decoration:none;cursor:pointer;background:none;border:0;width:100%;text-align:left;font:inherit;}",
".jf-request-menu-item:hover,.jf-request-menu-item:focus{color:#00a4dc;}",
@@ -99,8 +100,10 @@
function createTabPanel() {
const panel = document.createElement("div");
// Match SeerrFin: start without .hide; visibility is synced on tab change.
panel.className = "tabContent pageTabContent hide jf-request-tab-panel";
panel.setAttribute(TAB_ATTR, "request");
panel.id = "jellyfinRequestTab";
const mount = document.createElement("div");
mount.className = "sections jf-request-sections";
@@ -110,7 +113,14 @@
}
function findNativeButtons(tabsSlider) {
return Array.from(tabsSlider.querySelectorAll(".emby-tab-button")).filter((btn) => !btn.hasAttribute(TAB_ATTR));
return Array.from(tabsSlider.querySelectorAll(".emby-tab-button")).filter((btn) => {
if (btn.hasAttribute(TAB_ATTR)) {
return false;
}
const id = btn.id || "";
return id.indexOf("customTabButton_") !== 0;
});
}
function placeInOrder(parent, nodes) {
@@ -147,7 +157,6 @@
return;
}
// Native home/favorites panels.
if (index === 0) {
page.querySelector("#homeTab")?.setAttribute("data-index", "0");
} else if (index === 1) {
@@ -156,18 +165,100 @@
});
}
function syncPanelVisibility(selectedIndex) {
const page = document.getElementById("indexPage");
if (!page || isNaN(selectedIndex)) {
return;
}
page.querySelectorAll(".tabContent[data-index]").forEach((panel) => {
const panelIndex = parseInt(panel.getAttribute("data-index"), 10);
const active = panelIndex === selectedIndex;
panel.classList.toggle("hide", !active);
panel.classList.toggle("is-active", active);
});
}
async function mountRequestUi(panel) {
const mount = panel.querySelector('[data-role="request-mount"]');
if (!mount) {
return;
}
await loadAssets();
try {
await loadAssets();
} catch (error) {
mount.textContent = "Failed to load Request UI.";
console.error("[Jellyfin.Plugin.Request]", error);
return;
}
if (window.JellyfinRequestUI) {
window.JellyfinRequestUI.mount(mount, { embed: true });
} else {
mount.textContent = "Request UI failed to initialize.";
}
}
function isRequestTabButton(button) {
return !!(button && button.getAttribute(TAB_ATTR) === "request");
}
function attachPluginTabGuard(tabsEl) {
if (!tabsEl || guardAttached || tabsEl.dataset.jfRequestTabGuard === "true") {
return;
}
guardAttached = true;
tabsEl.dataset.jfRequestTabGuard = "true";
tabsEl.addEventListener("beforetabchange", (event) => {
if (!isHomeTabContext()) {
return;
}
const index = parseInt(event.detail && event.detail.selectedTabIndex, 10);
if (isNaN(index)) {
return;
}
// Jellyfin activates panels by NodeList order; keep data-index panels in sync.
syncPanelVisibility(index);
const selectedButton = tabsEl.querySelector(`.emby-tab-button[data-index="${index}"]`);
if (isRequestTabButton(selectedButton)) {
const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`);
if (panel) {
mountRequestUi(panel);
}
}
}, true);
// HomeView only knows Home/Favorites. Stop its handler for our tab so content is not cleared.
tabsEl.addEventListener("tabchange", (event) => {
if (!isHomeTabContext()) {
return;
}
const index = parseInt(event.detail && event.detail.selectedTabIndex, 10);
if (isNaN(index)) {
return;
}
const selectedButton = tabsEl.querySelector(`.emby-tab-button[data-index="${index}"]`);
if (!isRequestTabButton(selectedButton)) {
return;
}
event.stopImmediatePropagation();
syncPanelVisibility(index);
const panel = document.querySelector(`.tabContent[${TAB_ATTR}="request"]`);
if (panel) {
mountRequestUi(panel);
}
}, true);
}
function activateRequestTab() {
if (!isHomeTabContext()) {
window.location.hash = "#/home";
@@ -259,6 +350,8 @@
return;
}
attachPluginTabGuard(tabsEl);
let button = tabsSlider.querySelector(`[${TAB_ATTR}="request"]`);
if (!button) {
button = createTabButton();
@@ -290,7 +383,8 @@
}
}
await mountRequestUi(panel);
// Preload assets so the first click is instant; do not force-show the panel.
await loadAssets().catch(() => { /* surfaced on mount */ });
})().finally(() => {
ensuring = null;
});
@@ -306,11 +400,18 @@
}
});
window.addEventListener("hashchange", () => ensureRequestTab());
setInterval(() => ensureRequestTab(), 1500);
setInterval(() => ensureRequestTab(), 2000);
const headerTabs = document.querySelector(".headerTabs");
if (headerTabs) {
new MutationObserver(() => ensureRequestTab()).observe(headerTabs, { childList: true, subtree: true });
let timer = null;
new MutationObserver(() => {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => ensureRequestTab(), 250);
}).observe(headerTabs, { childList: true, subtree: true });
}
}