Skip to content

XP event5x XPListening, games, ratings, comments and chat earn five times the XP

leftLeaderboard

juicewrld-desktopuiplugins.js

1.4.2Released Nov 21, 2026

plugins.js

610 lines23.8 KBJavaScript
// The plugin manager (plugins.html): the app's own window for the user's plugins, like FL Studio's Plugin Manager.// Everything here asks the app through the manager's own commands (manager_*, src-tauri/src/plugins/manager.rs), which// only this window may call. The app tells it of every change (the scan's progress, the lists, what the user chose,// here or in the title bar's menu) and it reads its state again."use strict";const T = window.__TAURI_INTERNALS__;const invoke = (cmd, args) =>  T.invoke(cmd, args).catch((e) => {    throw new Error(typeof e === "string" ? e : (e && e.message) || "The app refused");  });const $ = (sel) => document.querySelector(sel);const app = $(".app");const summary = $(".summary");const toggle = $(".switch");const folderList = $(".folders");const addButton = $('[data-act="add-folder"]');const folderNote = $(".folder-note");const scanButton = $(".scan");const rescanButton = $('[data-act="rescan"]');const retryButton = $(".retry-failed");const progress = $(".progress");const progressWhat = $(".progress-what");const progressCount = $(".progress-count");const meter = $(".meter");const meterBar = $(".meter i");const last = $(".last");const scanNote = $(".scan-note");const find = $(".find input");const count = $(".count");const table = $(".table");const tbody = $(".tbody");const empty = $(".empty");const menu = $(".menu");const STAR = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m12 3.6 2.6 5.3 5.8.85-4.2 4.1 1 5.8L12 16.9l-5.2 2.75 1-5.8-4.2-4.1 5.8-.85z" /></svg>';const CROSS = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18 6 6 18" /><path d="m6 6 12 12" /></svg>';const DASH = '<span class="dash">–</span>';const STATUS = { ok: "OK", hidden: "Hidden", activation: "Needs activation", failed: "Failed", unsupported: "Unsupported" };const RANK = { ok: 0, hidden: 1, activation: 2, failed: 3, unsupported: 4 };const TYPE = { effect: "Effect", instrument: "Instrument", other: "Other" };const BITS = { x64: "64", x86: "32", arm64: "ARM64", arm: "ARM" };const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);const plural = (n, one, many) => `${n.toLocaleString()} ${n === 1 ? one : many}`;const collator = new Intl.Collator(undefined, { sensitivity: "base", numeric: true });/** What the app last said (manager_state), and the table's rows made from it. */let state = null;let stateText = "";let rows = [];const byKey = new Map();/** The table's order: a column and a direction (1 up, -1 down). */const view = { sort: "name", dir: 1 };// ---- the app's events and the state ----let next = 0;const early = new Map();const callback = T.transformCallback((m) => {  // A channel's messages carry their order; take them in it.  if (!m || typeof m.index !== "number") return;  early.set(m.index, m);  while (early.has(next)) {    const msg = early.get(next).message;    early.delete(next);    next++;    if (msg) heard(msg);  }});invoke("manager_subscribe", { events: `__CHANNEL__:${callback}` }).catch(() => {});function heard(ev) {  // The scan's progress shows at once; the rest when the state is read again.  if (ev.type === "status" && ev.status && state && "scanning" in ev.status) {    state.scanning = !!ev.status.scanning;    state.progress = ev.status.progress || null;    renderScan();  }  soon();}let timer = 0;let loading = false;let again = false;function soon() {  if (!timer) {    timer = setTimeout(() => {      timer = 0;      load(false);    }, 120);  }}/** Reads the state again (`fresh`: the app looks for the default folders again too) and shows what changed. */async function load(fresh) {  if (loading) {    again = true;    return;  }  loading = true;  try {    const s = await invoke("manager_state", { fresh });    // The progress alone changes with every module: the table is drawn again only when something in it did.    const { progress: _progress, ...rest } = s;    const text = JSON.stringify(rest);    if (text !== stateText) {      stateText = text;      state = s;      render();    } else if (state) {      state.scanning = s.scanning;      state.progress = s.progress;      renderScan();    }  } catch (e) {    say(scanNote, e.message);  } finally {    loading = false;    app.removeAttribute("data-loading");    if (again) {      again = false;      soon();    }  }}function render() {  renderHead();  renderFolders();  renderScan();  rows = rowsOf(state);  byKey.clear();  for (const r of rows) byKey.set(r.key, r);  renderTable();  $(".tm").textContent = state.trademark || "";}// ---- the header: the switch and where things stand ----function renderHead() {  const s = state;  toggle.disabled = !s.supported;  toggle.setAttribute("aria-checked", String(!!(s.supported && s.enabled)));  if (!s.supported) {    summary.textContent = "Plugins need the installed app: this copy is the portable one";    return;  }  const shown = s.plugins.filter((p) => !p.hidden).length;  const hidden = s.plugins.length - shown;  const parts = [s.enabled ? `${plural(shown, "plugin", "plugins")} in the studio` : "Off: the studio doesn't use your plugins"];  if (hidden) parts.push(`${hidden.toLocaleString()} hidden`);  if (s.failed.length) parts.push(`${s.failed.length.toLocaleString()} need activation or didn't load`);  if (s.unsupported.length) parts.push(`${s.unsupported.length.toLocaleString()} can't be used here`);  summary.textContent = parts.join(" · ");}toggle.addEventListener("click", async () => {  const on = toggle.getAttribute("aria-checked") !== "true";  toggle.setAttribute("aria-checked", String(on));  try {    await invoke("manager_enable", { on });  } catch (e) {    say(scanNote, e.message);  }  stateText = "";  soon();});// ---- the search paths ----function renderFolders() {  const s = state;  const busy = !!s.scanning;  keepFocus(folderList, () => {    if (!s.folders.length) {      folderList.innerHTML = '<li class="none">No plugin folders on this PC yet: add yours.</li>';      return;    }    folderList.innerHTML = s.folders      .map((f, i) => {        const parts = String(f.path).split(/[\\/]+/).filter(Boolean);        const name = parts[parts.length - 1] || f.path;        const on = f.on && f.exists;        const kind = f.exists ? f.kind : `${f.kind}, missing`;        const title = `${f.path}\n${f.exists ? (on ? "Searched" : "Not searched") : "Not there now"} (${f.from})${busy ? "\nFolders can be changed once the scan ends" : ""}`;        const remove = f.added          ? `<button type="button" class="remove" data-act="remove" title="Remove this folder from the list" aria-label="Remove ${esc(f.path)}"${busy ? " disabled" : ""}>${CROSS}</button>`          : "";        return (          `<li data-i="${i}">` +          `<label class="folder"${on ? "" : " data-off"} title="${esc(title)}">` +          `<input type="checkbox" data-act="tick"${on ? " checked" : ""}${busy || !f.exists ? " disabled" : ""} aria-label="Search ${esc(f.path)}" />` +          `<span class="folder-text"><span class="folder-name">${esc(name)}</span><span class="folder-path">${esc(f.path)}</span></span>` +          `<span class="kind"${f.exists ? "" : " data-missing"}>${esc(kind)}</span>` +          `</label>${remove}</li>`        );      })      .join("");  });  addButton.disabled = busy || !s.supported;  addButton.title = busy ? "Folders can be added once the scan ends" : "Pick a folder your plugins are in";}folderList.addEventListener("change", (e) => {  const input = e.target.closest('input[data-act="tick"]');  const f = input && folderAt(input);  if (!f) return;  invoke("manager_folder", { path: f.path, on: input.checked }).catch((err) => {    say(folderNote, err.message);    stateText = "";    soon();  });});folderList.addEventListener("click", (e) => {  const b = e.target.closest('button[data-act="remove"]');  const f = b && folderAt(b);  if (f) invoke("manager_remove_folder", { path: f.path }).catch((err) => say(folderNote, err.message));});function folderAt(el) {  const li = el.closest("li[data-i]");  return li && state ? state.folders[Number(li.dataset.i)] : null;}addButton.addEventListener("click", async () => {  addButton.disabled = true;  say(folderNote, "");  try {    await invoke("manager_add_folder");  } catch (e) {    say(folderNote, e.message);  } finally {    addButton.disabled = !state || !!state.scanning || !state.supported;    soon();  }});// ---- the scan ----function renderScan() {  const s = state;  const on = s.supported && s.enabled;  const busy = !!s.scanning;  scanButton.disabled = !on;  scanButton.toggleAttribute("data-stop", busy);  scanButton.dataset.act = busy ? "stop" : "scan";  scanButton.textContent = busy ? "Stop" : "Scan for plugins";  scanButton.title = busy ? "Stops once the plugin loading now is done with; what was read so far is kept" : "Reads the plugins that are new or changed since the last scan";  rescanButton.disabled = !on || busy;  const failed = s.failed.length;  retryButton.disabled = !on || busy || !failed;  retryButton.textContent = failed ? `Retry failed (${failed.toLocaleString()})` : "Retry failed";  retryButton.title = failed    ? "Loads every plugin that needs activation or didn't load again, one at a time. One that opens a window is closed after 2 s: Try again on its row gives you time for it"    : "Nothing has failed";  progress.toggleAttribute("data-on", busy);  if (busy) {    const p = s.progress;    if (p && p.total > 0 && p.done < p.total) {      progressWhat.textContent = `Loading ${p.module}`;      progressCount.textContent = `${(p.done + 1).toLocaleString()} of ${p.total.toLocaleString()}`;      meter.removeAttribute("data-busy");      meterBar.style.width = `${Math.max(2, (p.done / p.total) * 100)}%`;    } else if (p && p.total > 0) {      progressWhat.textContent = "Finishing";      progressCount.textContent = "";      meter.removeAttribute("data-busy");      meterBar.style.width = "100%";    } else {      progressWhat.textContent = "Looking in the folders";      progressCount.textContent = "";      meter.setAttribute("data-busy", "");      meterBar.style.width = "";    }  }  if (!s.supported || busy) last.textContent = "";  else if (!s.enabled) last.textContent = "Turn on Use my plugins in the studio to scan.";  else if (s.scan) last.textContent = lastScan(s.scan);  else last.textContent = "Not scanned yet.";  // A row's Try again waits for the scan too.  for (const b of tbody.querySelectorAll('[data-act="retry"]')) b.disabled = busy || !on;}function lastScan(sc) {  const at = new Date(sc.at);  const today = new Date().toDateString() === at.toDateString();  const time = at.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit" });  const day = today ? "today" : at.toLocaleDateString(undefined, { day: "numeric", month: "short" });  const took = sc.millis < 1000 ? `${sc.millis} ms` : `${(sc.millis / 1000).toFixed(1)} s`;  const what = sc.read ? `${sc.read.toLocaleString()} read, ${sc.loaded.toLocaleString()} loaded` : "nothing new";  return `Last scan ${day} at ${time}: ${what}, ${took}${sc.stopped ? ", stopped" : ""}.`;}async function run(cmd, args) {  try {    await invoke(cmd, args);  } catch (e) {    say(scanNote, e.message);  }  soon();}scanButton.addEventListener("click", () => (scanButton.dataset.act === "stop" ? run("manager_stop", {}) : run("manager_scan", { what: "changed" })));rescanButton.addEventListener("click", () => run("manager_scan", { what: "everything" }));retryButton.addEventListener("click", () => run("manager_scan", { what: "failed" }));// ---- the table ----/** Every row: the plugins found, the modules that failed, and the plugins that can't run here. */function rowsOf(s) {  const out = [];  const vendorHidden = new Set(s.plugins.filter((p) => p.hidden === "vendor").map((p) => p.vendor.toLowerCase()));  for (const p of s.plugins) {    const why =      p.hidden === "vendor"        ? `Hidden from the studio, with every plugin by ${p.vendor}`        : p.hidden          ? "Hidden from the studio"          : p.surround            ? "In the studio's list (made for surround: the studio's mixer is stereo)"            : "In the studio's list";    out.push({      kind: "plugin",      key: `p:${p.id}`,      id: p.id,      name: p.name,      version: p.version,      status: p.hidden ? "hidden" : "ok",      why,      format: "VST 3",      bits: "64",      type: TYPE[p.kind] || "Other",      vendor: p.vendor,      file: p.file,      path: p.path,      copies: p.copies || [],      categories: p.categories || [],      fav: !!p.favourite,      hidden: p.hidden,      vendorHidden: vendorHidden.has(p.vendor.toLowerCase()),    });  }  for (const f of s.failed) {    out.push({ kind: "failed", key: `f:${f.path}`, name: f.name, version: "", status: f.activation ? "activation" : "failed", why: f.why, format: "VST 3", bits: "64", type: "", vendor: "", file: f.file, path: f.path, copies: [], categories: [] });  }  for (const u of s.unsupported) {    const format = u.format === "vst2" ? "VST 2" : "VST 3";    out.push({ kind: "unsupported", key: `u:${u.path}`, name: u.name, version: "", status: "unsupported", why: u.why, format, bits: BITS[u.arch] || u.arch, type: "", vendor: "", file: u.file, path: u.path, copies: [], categories: [] });  }  for (const r of out) r.text = [r.name, r.vendor, r.file, STATUS[r.status], r.type, r.format, r.bits, ...r.categories].join(" ").toLowerCase();  return out;}const SORT = {  fav: (r) => (r.fav ? 0 : r.kind === "plugin" ? 1 : 2),  name: (r) => r.name,  status: (r) => RANK[r.status],  format: (r) => r.format,  bits: (r) => r.bits,  type: (r) => r.type,  vendor: (r) => r.vendor,  file: (r) => r.file,};function compare(a, b) {  const x = SORT[view.sort](a);  const y = SORT[view.sort](b);  let c;  if (typeof x === "number") c = x - y;  else if (!x !== !y) return x ? -1 : 1; // a blank cell goes last, whichever way  else c = collator.compare(x, y);  return c * view.dir || collator.compare(a.name, b.name) || collator.compare(a.file, b.file);}/** The rows Find leaves (every word typed, in the name, vendor, file, status, type or categories), in order. */function shownRows() {  const words = find.value.trim().toLowerCase().split(/\s+/).filter(Boolean);  const list = words.length ? rows.filter((r) => words.every((w) => r.text.includes(w))) : rows.slice();  return list.sort(compare);}function rowHtml(r) {  const idle = !state.scanning && state.enabled;  const star =    r.kind === "plugin"      ? `<button type="button" class="star" data-act="fav" aria-pressed="${r.fav}" aria-label="Favourite: ${esc(r.name)}" title="${r.fav ? "A favourite: first in the studio's add-effect menu" : "Add to favourites"}">${STAR}</button>`      : "";  let act = "";  if (r.kind === "plugin") {    act = r.hidden      ? `<button type="button" class="act" data-act="show" title="Show it in the studio's list" aria-label="Show ${esc(r.name)}">Show</button>`      : `<button type="button" class="act" data-act="hide" title="Hide it from the studio's list" aria-label="Hide ${esc(r.name)}">Hide</button>`;  } else if (r.kind === "failed") {    act = `<button type="button" class="act" data-act="retry" title="Loads it again, with time to deal with its activation window" aria-label="Try again: ${esc(r.name)}"${idle ? "" : " disabled"}>Try again</button>`;  }  const copies = r.copies.length ? `<span class="copies">+${r.copies.length}</span>` : "";  const fileTitle = [r.path, ...r.copies.map((c) => `Also installed, not used: ${c}`)].join("\n");  const attrs = (r.hidden ? " data-hidden" : "") + (r.kind === "unsupported" ? " data-dim" : "");  return (    `<div class="row" role="row" data-key="${esc(r.key)}"${attrs}>` +    `<div class="cell c-fav" role="cell">${star}</div>` +    `<div class="cell c-name" role="cell" title="${esc(r.version ? `${r.name} ${r.version}` : r.name)}">${esc(r.name)}</div>` +    `<div class="cell" role="cell" title="${esc(r.why)}"><span class="st st-${r.status}"><i aria-hidden="true"></i>${STATUS[r.status]}</span></div>` +    `<div class="cell" role="cell">${r.format}</div>` +    `<div class="cell" role="cell">${esc(r.bits)}</div>` +    `<div class="cell" role="cell">${r.type ? esc(r.type) : DASH}</div>` +    `<div class="cell" role="cell" title="${esc(r.vendor)}">${r.vendor ? esc(r.vendor) : DASH}</div>` +    `<div class="cell c-file" role="cell" title="${esc(fileTitle)}">${esc(r.file)}${copies}</div>` +    `<div class="cell c-act" role="cell">${act}</div>` +    `</div>`  );}function renderTable() {  if (!state) return;  const list = shownRows();  const q = find.value.trim();  keepFocus(tbody, () => {    tbody.innerHTML = list.map(rowHtml).join("");  });  const total = rows.length;  count.textContent = q ? `${list.length.toLocaleString()} of ${plural(total, "plugin", "plugins")}` : plural(total, "plugin", "plugins");  let title = "";  let text = "";  if (!state.supported) {    title = "Plugins need the installed app";    text = "This copy of the app is the portable one. Install the app from juicewrld.io/app to use your plugins in the studio.";  } else if (!total && !state.enabled && !state.scanned) {    title = "Your plugins, in the studio";    text = "Turn on Use my plugins in the studio and the app looks in the folders on the left, one plugin at a time. A plugin may show its licence window the first time.";  } else if (!total && state.scanning) {    title = "Looking for plugins";    text = "They show up here as they're found.";  } else if (!total) {    title = "No plugins found";    text = "Nothing in the ticked folders yet. Add the folder your plugins are in, or press Scan for plugins.";  } else if (!list.length) {    title = `Nothing matches “${q}”`;    text = "Find looks in names, vendors, files, status and type.";  }  empty.toggleAttribute("data-on", !!title);  $(".empty-title").textContent = title;  $(".empty-text").textContent = text;  for (const th of document.querySelectorAll(".th[data-sort]")) {    th.setAttribute("aria-sort", th.dataset.sort === view.sort ? (view.dir > 0 ? "ascending" : "descending") : "none");  }}/** Draws `container` again and puts the focus back where it was (the same row's same control), if it was inside. */function keepFocus(container, draw) {  const a = document.activeElement;  const inside = a && a !== container && container.contains(a);  const holder = inside ? a.closest("[data-key],[data-i]") : null;  const sel = holder && (holder.dataset.key !== undefined ? `[data-key="${CSS.escape(holder.dataset.key)}"]` : `[data-i="${CSS.escape(holder.dataset.i)}"]`);  const what = inside ? (a.classList[0] ? `.${CSS.escape(a.classList[0])}` : a.tagName.toLowerCase()) : "";  draw();  if (sel) container.querySelector(`${sel} ${what}`)?.focus({ preventScroll: true });}for (const th of document.querySelectorAll(".th[data-sort]")) {  th.querySelector("button").addEventListener("click", () => {    const k = th.dataset.sort;    if (view.sort === k) view.dir = -view.dir;    else {      view.sort = k;      view.dir = 1;    }    renderTable();  });}let findTimer = 0;find.addEventListener("input", () => {  clearTimeout(findTimer);  findTimer = setTimeout(renderTable, rows.length > 800 ? 60 : 0);});find.addEventListener("keydown", (e) => {  if (e.key === "Escape" && find.value) {    e.preventDefault();    find.value = "";    renderTable();  }});tbody.addEventListener("click", (e) => {  const b = e.target.closest("button[data-act]");  const row = b && b.closest(".row");  const r = row && byKey.get(row.dataset.key);  if (r) act(b.dataset.act, r, b);});/** A row's action: from its own buttons or its menu. */async function act(what, r, button) {  try {    if (what === "fav") {      // The star shows at once; the app's answer follows.      r.fav = !r.fav;      if (button) button.setAttribute("aria-pressed", String(r.fav));      await invoke("manager_favourite", { id: r.id, on: r.fav });    } else if (what === "hide" || what === "show") {      await invoke("manager_hide", { id: r.id, vendor: null, on: what === "hide" });    } else if (what === "hide-vendor" || what === "show-vendor") {      await invoke("manager_hide", { id: null, vendor: r.vendor, on: what === "hide-vendor" });    } else if (what === "retry") {      await invoke("manager_retry", { module: r.path });    }  } catch (e) {    say(scanNote, e.message);    stateText = "";    soon();  }}// ---- a row's menu (right-click, or the keyboard's menu key) ----let menuFor = null;document.addEventListener("contextmenu", (e) => {  if (e.target === find) return;  e.preventDefault();  const row = e.target.closest(".tbody .row");  const r = row && byKey.get(row.dataset.key);  if (!r) return closeMenu();  // From the keyboard there's no pointer: under the row's name.  const box = row.getBoundingClientRect();  const fromKeys = e.clientX === 0 && e.clientY === 0;  openMenu(r, fromKeys ? box.left + 44 : e.clientX, fromKeys ? box.bottom : e.clientY);});function openMenu(r, x, y) {  const items = [];  if (r.kind === "plugin") {    items.push(["fav", r.fav ? "Remove from favourites" : "Add to favourites"]);    items.push(r.hidden ? ["show", "Show in the studio"] : ["hide", "Hide from the studio"]);    if (r.vendor) items.push(null, r.vendorHidden ? ["show-vendor", `Show every plugin by ${r.vendor}`] : ["hide-vendor", `Hide every plugin by ${r.vendor}`]);  } else if (r.kind === "failed") {    items.push(["retry", "Try again"]);  }  if (!items.length) return closeMenu();  menu.innerHTML = items.map((it) => (it ? `<button type="button" role="menuitem" data-act="${it[0]}">${esc(it[1])}</button>` : '<hr role="separator" />')).join("");  const retry = menu.querySelector('[data-act="retry"]');  if (retry) retry.disabled = !!state.scanning || !state.enabled;  menuFor = r;  menu.setAttribute("data-on", "");  const w = menu.offsetWidth;  const h = menu.offsetHeight;  menu.style.left = `${Math.max(6, Math.min(x, innerWidth - w - 6))}px`;  menu.style.top = `${Math.max(6, Math.min(y, innerHeight - h - 6))}px`;  menu.querySelector("button:not(:disabled)")?.focus({ preventScroll: true });}function closeMenu(refocus) {  if (!menu.hasAttribute("data-on")) return;  menu.removeAttribute("data-on");  const r = menuFor;  menuFor = null;  if (refocus && r) tbody.querySelector(`[data-key="${CSS.escape(r.key)}"] button`)?.focus({ preventScroll: true });}menu.addEventListener("click", (e) => {  const b = e.target.closest("button[data-act]");  const r = menuFor;  if (!b || !r) return;  closeMenu(true);  act(b.dataset.act, r, null);});menu.addEventListener("keydown", (e) => {  const items = [...menu.querySelectorAll("button:not(:disabled)")];  const i = items.indexOf(document.activeElement);  if (e.key === "ArrowDown" || e.key === "ArrowUp") {    e.preventDefault();    const n = items.length;    items[(i + (e.key === "ArrowDown" ? 1 : -1) + n) % n]?.focus();  } else if (e.key === "Escape" || e.key === "Tab") {    e.preventDefault();    closeMenu(true);  }});document.addEventListener("pointerdown", (e) => {  if (!menu.contains(e.target)) closeMenu();});window.addEventListener("blur", () => closeMenu());window.addEventListener("resize", () => closeMenu());table.addEventListener("scroll", () => closeMenu(), { passive: true });// ---- the rest ----/** A word under a part of the side about what went wrong (a folder in the list already), for a few seconds. */const noteTimers = new Map();function say(el, text) {  clearTimeout(noteTimers.get(el));  el.textContent = text || "";  el.toggleAttribute("data-on", !!text);  if (text) noteTimers.set(el, setTimeout(() => el.removeAttribute("data-on"), 8000));}document.addEventListener("keydown", (e) => {  if ((e.ctrlKey && e.key.toLowerCase() === "f") || e.key === "F3") {    e.preventDefault();    find.focus();    find.select();  }});load(true);