Fix onHeadersReceived clashes when using OpenAsar (fix github raw styles)
This commit is contained in:
parent
906c265aea
commit
ff16513f21
1 changed files with 9 additions and 4 deletions
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { onceDefined } from "@utils/onceDefined";
|
import { onceDefined } from "@utils/onceDefined";
|
||||||
import electron, { app, BrowserWindowConstructorOptions, Menu } from "electron";
|
import electron, { app, BrowserWindowConstructorOptions, Menu, protocol, session } from "electron";
|
||||||
import { dirname, join } from "path";
|
import { dirname, join } from "path";
|
||||||
|
|
||||||
import { initIpc } from "./ipcMain";
|
import { initIpc } from "./ipcMain";
|
||||||
|
@ -118,10 +118,10 @@ if (!process.argv.includes("--vanilla")) {
|
||||||
|
|
||||||
process.env.DATA_DIR = join(app.getPath("userData"), "..", "Vencord");
|
process.env.DATA_DIR = join(app.getPath("userData"), "..", "Vencord");
|
||||||
|
|
||||||
electron.app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
// Source Maps! Maybe there's a better way but since the renderer is executed
|
// Source Maps! Maybe there's a better way but since the renderer is executed
|
||||||
// from a string I don't think any other form of sourcemaps would work
|
// from a string I don't think any other form of sourcemaps would work
|
||||||
electron.protocol.registerFileProtocol("vencord", ({ url: unsafeUrl }, cb) => {
|
protocol.registerFileProtocol("vencord", ({ url: unsafeUrl }, cb) => {
|
||||||
let url = unsafeUrl.slice("vencord://".length);
|
let url = unsafeUrl.slice("vencord://".length);
|
||||||
if (url.endsWith("/")) url = url.slice(0, -1);
|
if (url.endsWith("/")) url = url.slice(0, -1);
|
||||||
switch (url) {
|
switch (url) {
|
||||||
|
@ -177,7 +177,7 @@ if (!process.argv.includes("--vanilla")) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType }, cb) => {
|
session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, resourceType }, cb) => {
|
||||||
if (responseHeaders) {
|
if (responseHeaders) {
|
||||||
if (resourceType === "mainFrame")
|
if (resourceType === "mainFrame")
|
||||||
patchCsp(responseHeaders, "content-security-policy");
|
patchCsp(responseHeaders, "content-security-policy");
|
||||||
|
@ -189,6 +189,11 @@ if (!process.argv.includes("--vanilla")) {
|
||||||
}
|
}
|
||||||
cb({ cancel: false, responseHeaders });
|
cb({ cancel: false, responseHeaders });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// assign a noop to onHeadersReceived to prevent other mods from adding their own incompatible ones.
|
||||||
|
// For instance, OpenAsar adds their own that doesn't fix content-type for stylesheets which makes it
|
||||||
|
// impossible to load css from github raw despite our fix above
|
||||||
|
session.defaultSession.webRequest.onHeadersReceived = () => { };
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("[Vencord] Running in vanilla mode. Not loading Vencord");
|
console.log("[Vencord] Running in vanilla mode. Not loading Vencord");
|
||||||
|
|
Loading…
Reference in a new issue