From 13d0bc6197a798d1c98876601be0c3f59bd4fd3c Mon Sep 17 00:00:00 2001 From: toonlink Date: Wed, 27 Nov 2024 08:58:49 -0500 Subject: [PATCH] fix(routes): TIDAL did internal changes to routing (and 404) handling, this solve isn't perfect but it's a fairly simple hotfix nonetheless --- src/api/registerRoute.js | 6 +++--- src/api/utils.js | 26 +++++++++++++++++--------- src/ui/settings.js | 5 ++--- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/api/registerRoute.js b/src/api/registerRoute.js index bbbbdd8..da50bc8 100644 --- a/src/api/registerRoute.js +++ b/src/api/registerRoute.js @@ -14,14 +14,14 @@ const replacePage = (page, component) => { neptunePage.appendChild(ReactiveRoot({ children: component })); }; -intercept("ROUTER_LOCATION_CHANGED", () => { +intercept("router/NAVIGATED", () => { for (const page of document.getElementsByClassName("__NEPTUNE_PAGE")) page.parentElement.removeChild(page); }); export default function registerRoute(path, component) { - return intercept("ROUTER_LOCATION_CHANGED", ([payload]) => { - if (payload.pathname != `/neptune/${path}`) return; + return intercept("router/NAVIGATED", ([payload]) => { + if (payload.search != `?neptuneRoute=${path}`) return; const pageNotFound = document.querySelector(pageNotFoundSelector); if (pageNotFound) return replacePage(pageNotFound, component); diff --git a/src/api/utils.js b/src/api/utils.js index 308302b..99e1eb4 100644 --- a/src/api/utils.js +++ b/src/api/utils.js @@ -11,7 +11,7 @@ export function appendStyle(style) { } else { document.addEventListener("DOMContentLoaded", () => { document.head.appendChild(styleTag); - }) + }); } return (newStyle) => { @@ -60,7 +60,6 @@ export const parseManifest = (manifest) => { export const getMediaURLFromID = (id, path = "/1280x1280.jpg") => "https://resources.tidal.com/images/" + id.split("-").join("/") + path; - export function convertHexToRGB(h) { let r = 0; let g = 0; @@ -68,16 +67,25 @@ export function convertHexToRGB(h) { // 3 digits if (h.length === 4) { - r = Number('0x' + h[1] + h[1]); - g = Number('0x' + h[2] + h[2]); - b = Number('0x' + h[3] + h[3]); + r = Number("0x" + h[1] + h[1]); + g = Number("0x" + h[2] + h[2]); + b = Number("0x" + h[3] + h[3]); // 6 digits } else if (h.length === 7) { - r = Number('0x' + h[1] + h[2]); - g = Number('0x' + h[3] + h[4]); - b = Number('0x' + h[5] + h[6]); + r = Number("0x" + h[1] + h[2]); + g = Number("0x" + h[3] + h[4]); + b = Number("0x" + h[5] + h[6]); } - return `${r}, ${g}, ${b}` + return `${r}, ${g}, ${b}`; +} + +// this impl can be changed when things (probably) break again, lol +export function pushVirtualRoute(route) { + neptune.actions.router.push({ + pathname: `/not-found`, + search: `?neptuneRoute=${route}`, + replace: true, + }); } diff --git a/src/ui/settings.js b/src/ui/settings.js index 51d3055..ff1e30f 100644 --- a/src/ui/settings.js +++ b/src/ui/settings.js @@ -3,6 +3,7 @@ import { PluginTab } from "./pluginsTab.js"; import { ThemesTab } from "./themesTab.js"; import registerRoute from "../api/registerRoute.js"; import hookContextMenu from "../api/hookContextMenu.js"; +import { pushVirtualRoute } from "../api/utils.js"; let selectedTab = $(0); const tabs = [ @@ -45,6 +46,4 @@ registerRoute( `, ); -hookContextMenu("USER_PROFILE", "neptune settings", () => - neptune.actions.router.push({ pathname: "/neptune/settings", replace: true }), -); +hookContextMenu("USER_PROFILE", "neptune settings", () => pushVirtualRoute("settings"));