juicewrld-desktopuibar.js
1.4.2Released Nov 21, 2026
bar.js
152 lines6.3 KBJavaScript// The title bar's controls. Every button asks the app (the `bar` command) to act on the window or on the// site below, or opens the app's menu; the app pushes state back through window.jw (maximized, focus, history,// loading, what's playing, an update ready, the site asking to use this PC's plugins, the site lying under the bar),// and `bar_state` fills it in when the bar first loads."use strict";const invoke = (cmd, args) => window.__TAURI_INTERNALS__.invoke(cmd, args);const bar = document.querySelector(".bar");const now = document.querySelector(".now");const maxButton = document.querySelector("[data-max]");const reload = document.querySelector(".reload");const updateButton = document.querySelector(".update");const updateLabel = updateButton.querySelector(".update-label");for (const button of document.querySelectorAll("[data-act]")) { button.addEventListener("click", () => { const action = button.dataset.act; if (action === "reload") spin(); // The app closes to install it: one press, and the button says so until it goes. if (action === "update") { if (updateButton.hasAttribute("data-busy")) return; updateButton.toggleAttribute("data-busy", true); updateLabel.textContent = "Restarting…"; } // The menu opens under its button (the app draws it: a native menu can leave the bar's 36 pixels). let place = {}; if (action === "menu") { const r = button.getBoundingClientRect(); place = { x: r.left, y: r.bottom }; } if (action === "plugins-on" || action === "plugins-not-now") jw.ask(null); invoke("bar", { action, ...place }).catch(() => { if (action === "update") { updateButton.removeAttribute("data-busy"); updateLabel.textContent = "Update ready"; } }); });}// The bar is chrome, not a page: no context menu, no text selection, no zoom.document.addEventListener("contextmenu", (e) => e.preventDefault());document.addEventListener("wheel", (e) => e.ctrlKey && e.preventDefault(), { passive: false });function spin() { reload.classList.remove("spin"); void reload.offsetWidth; reload.classList.add("spin");}reload.addEventListener("animationend", () => reload.classList.remove("spin"));let blurTimer = 0;let noticeTimer = 0;const notice = document.querySelector(".notice");const ask = document.querySelector(".ask");window.jw = { /** Maximized: the middle button offers Restore. */ max(on) { maxButton.textContent = on ? "\uE923" : "\uE922"; maxButton.title = on ? "Restore" : "Maximize"; maxButton.setAttribute("aria-label", maxButton.title); }, /** The window gained or lost focus. Focus moving between the bar and the page reads as a blink, so a loss waits a moment. */ focus(on) { clearTimeout(blurTimer); if (on) bar.classList.remove("blur"); else blurTimer = setTimeout(() => bar.classList.add("blur"), 120); }, /** Whether the page can go back or forward. */ nav({ back, forward }) { document.querySelector('[data-nav="back"]').disabled = !back; document.querySelector('[data-nav="forward"]').disabled = !forward; }, /** A full page load started or finished. */ loading(on) { bar.toggleAttribute("data-loading", !!on); }, /** The site lies under the bar (main.rs site_under_bar): see-through over the page's colour, else solid. */ overlay(on) { document.documentElement.toggleAttribute("data-overlay", !!on); }, /** Below the bar, the colour along the page's top edge ("rgb(r g b)"), which the solid bar takes; null for its own. */ tint(c) { const root = document.documentElement; const ok = typeof c === "string" && /^rgb\(\d{1,3} \d{1,3} \d{1,3}\)$/.test(c); if (ok) root.style.setProperty("--bar", c); else root.style.removeProperty("--bar"); root.toggleAttribute("data-tinted", ok); }, /** The site asks to use this PC's plugins: { text, yes, no }, or nothing to take the question away. */ ask(q) { const shown = !!(q && q.text); if (shown) { ask.querySelector(".ask-text").textContent = q.text; ask.querySelector(".ask-yes").textContent = q.yes || "Turn on"; ask.querySelector(".ask-no").textContent = q.no || "Not now"; notice.removeAttribute("data-on"); } ask.toggleAttribute("data-on", shown); ask.setAttribute("aria-hidden", String(!shown)); for (const b of ask.querySelectorAll("button")) b.tabIndex = shown ? 0 : -1; }, /** * A short message in the middle of the bar for a few seconds; { text, stay: true } keeps it until the next one (a * plugin scan says which module is loading for as long as it loads, so an activation window that opens can be put * down to its plugin). */ notice(n) { clearTimeout(noticeTimer); notice.textContent = typeof n === "string" ? n : (n && n.text) || ""; notice.toggleAttribute("data-on", !!notice.textContent); if (!(n && n.stay)) noticeTimer = setTimeout(() => notice.removeAttribute("data-on"), 8000); }, /** What's playing: { state: "playing" | "paused", title, artist }, or nothing. */ now(n) { const shown = !!(n && n.title && (n.state === "playing" || n.state === "paused")); if (shown) { now.querySelector(".now-title").textContent = n.title; now.querySelector(".now-artist").textContent = n.artist || ""; now.title = `${n.title}${n.artist ? ` by ${n.artist}` : ""}\nGo to song`; now.dataset.state = n.state; } else { delete now.dataset.state; } now.tabIndex = shown ? 0 : -1; now.setAttribute("aria-hidden", String(!shown)); }, /** An update has downloaded: { version, installed } (installed: false for the portable app, whose update installs it), or nothing. */ update(u) { const shown = !!(u && u.version); if (shown) { updateButton.title = u.installed ? `Restart to update to version ${u.version}` : `Install version ${u.version} and restart`; updateButton.setAttribute("aria-label", `Update ready. ${updateButton.title}`); } updateButton.toggleAttribute("data-on", shown); updateButton.tabIndex = shown ? 0 : -1; updateButton.setAttribute("aria-hidden", String(!shown)); },};invoke("bar_state") .then((s) => { jw.max(s.maximized); jw.nav(s.nav); jw.loading(s.loading); jw.overlay(s.overlay); jw.tint(s.tint); jw.now(s.now); jw.update(s.update); }) .catch(() => {});