Add --vanilla flag, strip csp on mainFrame only

This commit is contained in:
Vendicated 2022-12-02 14:10:40 +01:00
parent daf3a1dcac
commit b9e9d9bd64
No known key found for this signature in database
GPG Key ID: EC781ADFB93EFFA3

@ -42,6 +42,7 @@ require.main!.filename = join(asarPath, discordPkg.main);
// @ts-ignore Untyped method? Dies from cringe // @ts-ignore Untyped method? Dies from cringe
app.setAppPath(asarPath); app.setAppPath(asarPath);
if (!process.argv.includes("--vanilla")) {
// Repatch after host updates on Windows // Repatch after host updates on Windows
if (process.platform === "win32") if (process.platform === "win32")
require("./patchWin32Updater"); require("./patchWin32Updater");
@ -121,19 +122,22 @@ electron.app.whenReady().then(() => {
} }
} }
electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, url }, cb) => { electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType }, cb) => {
if (responseHeaders) { if (responseHeaders) {
if (resourceType === "mainFrame")
patchCsp(responseHeaders, "content-security-policy"); patchCsp(responseHeaders, "content-security-policy");
patchCsp(responseHeaders, "content-security-policy-report-only");
// Fix hosts that don't properly set the content type, such as // Fix hosts that don't properly set the css content type, such as
// raw.githubusercontent.com // raw.githubusercontent.com
if (url.endsWith(".css")) if (resourceType === "stylesheet")
responseHeaders["content-type"] = ["text/css"]; responseHeaders["content-type"] = ["text/css"];
} }
cb({ cancel: false, responseHeaders }); cb({ cancel: false, responseHeaders });
}); });
}); });
} else {
console.log("[Vencord] Running in vanilla mode. Not loading Vencord");
}
console.log("[Vencord] Loading original Discord app.asar"); console.log("[Vencord] Loading original Discord app.asar");
// Legacy Vencord Injector requires "../app.asar". However, because we // Legacy Vencord Injector requires "../app.asar". However, because we