Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions injector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ const getNeptuneBundle = () =>
? fetchPromise
: Promise.resolve(
fs.readFileSync(path.join(localBundle, "neptune.js"), "utf8") +
`\n//# sourceMappingURL=file:////${path.join(
localBundle,
"neptune.js.map"
)}`
`\n//# sourceMappingURL=file:////${path.join(localBundle, "neptune.js.map")}`,
);
// #endregion

Expand All @@ -64,10 +61,15 @@ electron.ipcMain.on("NEPTUNE_ORIGINAL_PRELOAD", (event) => {
electron.ipcMain.handle("NEPTUNE_BUNDLE_FETCH", getNeptuneBundle);
// #endregion

// #region App Switches
// Allow debugging from remote origins (e.g., Chrome DevTools over localhost)
electron.app.commandLine.appendSwitch("remote-allow-origins", "http://localhost:9222");
// #endregion

// #region Redux Devtools
electron.app.whenReady().then(() => {
electron.session.defaultSession.loadExtension(
path.join(process.resourcesPath, "app", "redux-devtools")
path.join(process.resourcesPath, "app", "redux-devtools"),
);
});
// #endregion
Expand All @@ -77,36 +79,40 @@ electron.app.whenReady().then(() => {
electron.protocol.handle("https", async (req) => {
const url = new URL(req.url);
if (url.pathname === "/" || url.pathname == "/index.html") {
console.log(req.url);
const res = await electron.net.fetch(req, { bypassCustomProtocolHandlers: true })
const res = await electron.net.fetch(req, { bypassCustomProtocolHandlers: true });
let body = await res.text();
body = body.replace(
/<meta http-equiv="Content-Security-Policy"/,
`<meta name="neptune removed csp"`
`<meta name="neptune removed csp"`,
);

body = body.replaceAll(/<script type="module" crossorigin src="(.*?)">/g, `<script type="neptune/quartz" src="$1">`);
body = body.replaceAll(
/<script type="module" crossorigin src="(.*?)">/g,
`<script type="neptune/quartz" src="$1">`,
);

return new Response(body, res);
}
return electron.net.fetch(req, { bypassCustomProtocolHandlers: true });
});
// Force service worker to fetch resources by clearing it's cache.
electron.session.defaultSession.clearStorageData({
storages: ["cachestorage"]
storages: ["cachestorage"],
});
});
// #endregion

// #region Stylesheet bypass
electron.app.whenReady().then(() => {
session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType }, cb) => {
if (responseHeaders && resourceType === "stylesheet") {
const header = Object.keys(responseHeaders).find(h => h.toLowerCase() === "content-type") || "content-type";
responseHeaders[header] = "text/css";
}
cb({ cancel: false, responseHeaders });
});
session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType }, cb) => {
if (responseHeaders && resourceType === "stylesheet") {
const header =
Object.keys(responseHeaders).find((h) => h.toLowerCase() === "content-type") ||
"content-type";
responseHeaders[header] = "text/css";
}
cb({ cancel: false, responseHeaders });
});
});
// #endregion

Expand All @@ -127,12 +133,7 @@ electron.ipcMain.on("NEPTUNE_CREATE_EVAL_SCOPE", (ev, code) => {
ev.returnValue = { type: "success", value: id };
} catch (err) {
electron.BrowserWindow.getAllWindows().forEach((e) =>
e.webContents.send(
"NEPTUNE_RENDERER_LOG",
"error",
"[NEPTUNE NATIVE ERROR]",
err
)
e.webContents.send("NEPTUNE_RENDERER_LOG", "error", "[NEPTUNE NATIVE ERROR]", err),
);

ev.returnValue = { type: "error", value: err };
Expand All @@ -152,14 +153,14 @@ electron.ipcMain.on("NEPTUNE_RUN_IN_EVAL_SCOPE", (ev, scopeId, code) => {

retVal.then((v) =>
getAllWindows().forEach((w) =>
w.webContents.send(promiseId, { type: "resolve", value: v })
)
w.webContents.send(promiseId, { type: "resolve", value: v }),
),
);

retVal.catch((v) =>
getAllWindows().forEach((w) =>
w.webContents.send(promiseId, { type: "reject", value: v })
)
w.webContents.send(promiseId, { type: "reject", value: v }),
),
);
} catch {}
}
Expand Down Expand Up @@ -188,8 +189,11 @@ const ProxiedBrowserWindow = new Proxy(electron.BrowserWindow, {
let originalPreload;

// tidal-hifi does not set the title, rely on dev tools instead.
const isTidalWindow =
options.title == "TIDAL" || options.webPreferences?.devTools;
const isTidalWindow = options.title == "TIDAL" || options.webPreferences?.devTools;

// Improve memory limits
options.webPreferences.nodeOptions = "--max-old-space-size=8192";
options.webPreferences.smoothScrolling = true;

if (isTidalWindow) {
originalPreload = options.webPreferences?.preload;
Expand Down Expand Up @@ -245,12 +249,9 @@ electron.Menu.buildFromTemplate = (template) => {
logger.log("Starting original...");

let originalPath = path.join(process.resourcesPath, "app.asar");
if (!fs.existsSync(originalPath))
originalPath = path.join(process.resourcesPath, "original.asar");
if (!fs.existsSync(originalPath)) originalPath = path.join(process.resourcesPath, "original.asar");

const originalPackage = require(path.resolve(
path.join(originalPath, "package.json")
));
const originalPackage = require(path.resolve(path.join(originalPath, "package.json")));
const startPath = path.join(originalPath, originalPackage.main);

require.main.filename = startPath;
Expand Down
34 changes: 10 additions & 24 deletions injector/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,24 @@ electron.ipcRenderer.invoke("NEPTUNE_BUNDLE_FETCH").then((bundle) => {
});

function createEvalScope(code) {
const { type, value } = electron.ipcRenderer.sendSync(
"NEPTUNE_CREATE_EVAL_SCOPE",
code
);
const { type, value } = electron.ipcRenderer.sendSync("NEPTUNE_CREATE_EVAL_SCOPE", code);
if (type == "error") throw new Error(value);

return value;
}

function getNativeValue(id, name) {
if (
electron.ipcRenderer.sendSync(
"NEPTUNE_RUN_IN_EVAL_SCOPE",
id,
`typeof neptuneExports.${name}`
).value == "function"
electron.ipcRenderer.sendSync("NEPTUNE_RUN_IN_EVAL_SCOPE", id, `typeof neptuneExports.${name}`)
.value == "function"
)
return (...args) => {
funcReturn = electron.ipcRenderer.sendSync(
"NEPTUNE_RUN_IN_EVAL_SCOPE",
id,
`neptuneExports.${name}(${args
.map((arg) =>
typeof arg != "function" ? JSON.stringify(arg) : arg.toString()
)
.join(",")})`
.map((arg) => (typeof arg != "function" ? JSON.stringify(arg) : arg.toString()))
.join(",")})`,
);

if (funcReturn.type == "promise") {
Expand All @@ -48,11 +40,7 @@ function getNativeValue(id, name) {
return funcReturn.value;
};

return electron.ipcRenderer.sendSync(
"NEPTUNE_RUN_IN_EVAL_SCOPE",
id,
`neptuneExports.${name}`
);
return electron.ipcRenderer.sendSync("NEPTUNE_RUN_IN_EVAL_SCOPE", id, `neptuneExports.${name}`);
}

function deleteEvalScope(id) {
Expand All @@ -68,7 +56,7 @@ electron.contextBridge.exposeInMainWorld("NeptuneNative", {
getNativeValue,
deleteEvalScope,
startDebugging,
VITE_ACTIVE: true
VITE_ACTIVE: true,
});

electron.ipcRenderer.on("NEPTUNE_RENDERER_LOG", (ev, type, ...logs) => {
Expand All @@ -89,12 +77,10 @@ electron.contextBridge.exposeInMainWorld("electron", {
"sendSync",
"postMessage",
"sendToHost",
].map((n) => [n, (...args) => electron.ipcRenderer[n](...args)])
].map((n) => [n, (...args) => electron.ipcRenderer[n](...args)]),
),
});

const originalPreload = electron.ipcRenderer.sendSync(
"NEPTUNE_ORIGINAL_PRELOAD"
);
const originalPreload = electron.ipcRenderer.sendSync("NEPTUNE_ORIGINAL_PRELOAD");

if (originalPreload) require(originalPreload);
if (originalPreload) require(originalPreload);
3 changes: 3 additions & 0 deletions src/windowObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import showModal from "./api/showModal.js";
// TODO: AWFUL VOMIT VOMIT KILL MURDER DIE KILL KILL DIE MURDER VOMIT
import { store } from "./handleExfiltrations.js";

import quartz from "@uwu/quartz";

let currentMediaItem = {};

try {
Expand Down Expand Up @@ -45,4 +47,5 @@ export default {
themes,
components,
currentMediaItem,
quartz
};
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare const neptune: {
loaded: boolean;
exports: any;
}>;
quartz: typeof import("@uwu/quartz").default;
};
interface Window {
neptune: typeof neptune;
Expand Down