Skip to content

Commit

Permalink
fix(routes): TIDAL did internal changes to routing (and 404) handling,
Browse files Browse the repository at this point in the history
this solve isn't perfect but it's a fairly simple hotfix nonetheless
  • Loading branch information
twnlink committed Nov 27, 2024
1 parent c6f530e commit 13d0bc6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/api/registerRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 17 additions & 9 deletions src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function appendStyle(style) {
} else {
document.addEventListener("DOMContentLoaded", () => {
document.head.appendChild(styleTag);
})
});
}

return (newStyle) => {
Expand Down Expand Up @@ -60,24 +60,32 @@ 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;
let b = 0;

// 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,
});
}
5 changes: 2 additions & 3 deletions src/ui/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -45,6 +46,4 @@ registerRoute(
</div>`,
);

hookContextMenu("USER_PROFILE", "neptune settings", () =>
neptune.actions.router.push({ pathname: "/neptune/settings", replace: true }),
);
hookContextMenu("USER_PROFILE", "neptune settings", () => pushVirtualRoute("settings"));

0 comments on commit 13d0bc6

Please sign in to comment.