From 18ba2ec477d1c7b1624d49130da4c8dff2e2cbd2 Mon Sep 17 00:00:00 2001 From: Ven Date: Tue, 13 Dec 2022 19:02:28 +0100 Subject: [PATCH] Fix github raw css links, make jsons human readable (#299) --- src/extensions/mods.ts | 13 +++++++++++-- src/utils.ts | 11 ++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/extensions/mods.ts b/src/extensions/mods.ts index 83e4b29..061e513 100644 --- a/src/extensions/mods.ts +++ b/src/extensions/mods.ts @@ -4,8 +4,17 @@ import {getConfig} from "../utils"; const unstrictCSP = () => { console.log("Setting up CSP unstricter..."); - electron.session.defaultSession.webRequest.onHeadersReceived(({responseHeaders}, done) => { - delete responseHeaders!["content-security-policy"]; + electron.session.defaultSession.webRequest.onHeadersReceived(({responseHeaders, resourceType}, done) => { + if (!responseHeaders) return done({}); + + if (resourceType === "mainFrame") { + delete responseHeaders["content-security-policy"]; + } else if (resourceType === "stylesheet") { + // Fix hosts that don't properly set the css content type, such as + // raw.githubusercontent.com + responseHeaders["content-type"] = ["text/css"]; + } + done({responseHeaders}); }); }; diff --git a/src/utils.ts b/src/utils.ts index 1226bda..db71f47 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -141,7 +141,7 @@ export async function setLang(language: string) { let rawdata = fs.readFileSync(langConfigFile, "utf-8"); let parsed = JSON.parse(rawdata); parsed["lang"] = language; - let toSave = JSON.stringify(parsed); + let toSave = JSON.stringify(parsed, null, 4); fs.writeFileSync(langConfigFile, toSave, "utf-8"); } var language: string; @@ -209,10 +209,7 @@ export async function setWindowState(object: WindowState) { const userDataPath = app.getPath("userData"); const storagePath = path.join(userDataPath, "/storage/"); const saveFile = storagePath + "window.json"; - if (!fs.existsSync(saveFile)) { - fs.writeFileSync(saveFile, "{}", "utf-8"); - } - let toSave = JSON.stringify(object); + let toSave = JSON.stringify(object, null, 4); fs.writeFileSync(saveFile, toSave, "utf-8"); } export async function getWindowState(object: string) { @@ -267,11 +264,11 @@ export async function setConfig(object: string, toSet: any) { let rawdata = fs.readFileSync(getConfigLocation(), "utf-8"); let parsed = JSON.parse(rawdata); parsed[object] = toSet; - let toSave = JSON.stringify(parsed); + let toSave = JSON.stringify(parsed, null, 4); fs.writeFileSync(getConfigLocation(), toSave, "utf-8"); } export async function setConfigBulk(object: Settings) { - let toSave = JSON.stringify(object); + let toSave = JSON.stringify(object, null, 4); fs.writeFileSync(getConfigLocation(), toSave, "utf-8"); } export async function checkIfConfigExists() {