Fix github raw css links, make jsons human readable (#299)

This commit is contained in:
Ven 2022-12-13 19:02:28 +01:00 committed by GitHub
parent 1f369dae11
commit 18ba2ec477
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View file

@ -4,8 +4,17 @@ import {getConfig} from "../utils";
const unstrictCSP = () => { const unstrictCSP = () => {
console.log("Setting up CSP unstricter..."); console.log("Setting up CSP unstricter...");
electron.session.defaultSession.webRequest.onHeadersReceived(({responseHeaders}, done) => { electron.session.defaultSession.webRequest.onHeadersReceived(({responseHeaders, resourceType}, done) => {
delete responseHeaders!["content-security-policy"]; 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}); done({responseHeaders});
}); });
}; };

View file

@ -141,7 +141,7 @@ export async function setLang(language: string) {
let rawdata = fs.readFileSync(langConfigFile, "utf-8"); let rawdata = fs.readFileSync(langConfigFile, "utf-8");
let parsed = JSON.parse(rawdata); let parsed = JSON.parse(rawdata);
parsed["lang"] = language; parsed["lang"] = language;
let toSave = JSON.stringify(parsed); let toSave = JSON.stringify(parsed, null, 4);
fs.writeFileSync(langConfigFile, toSave, "utf-8"); fs.writeFileSync(langConfigFile, toSave, "utf-8");
} }
var language: string; var language: string;
@ -209,10 +209,7 @@ export async function setWindowState(object: WindowState) {
const userDataPath = app.getPath("userData"); const userDataPath = app.getPath("userData");
const storagePath = path.join(userDataPath, "/storage/"); const storagePath = path.join(userDataPath, "/storage/");
const saveFile = storagePath + "window.json"; const saveFile = storagePath + "window.json";
if (!fs.existsSync(saveFile)) { let toSave = JSON.stringify(object, null, 4);
fs.writeFileSync(saveFile, "{}", "utf-8");
}
let toSave = JSON.stringify(object);
fs.writeFileSync(saveFile, toSave, "utf-8"); fs.writeFileSync(saveFile, toSave, "utf-8");
} }
export async function getWindowState(object: string) { 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 rawdata = fs.readFileSync(getConfigLocation(), "utf-8");
let parsed = JSON.parse(rawdata); let parsed = JSON.parse(rawdata);
parsed[object] = toSet; parsed[object] = toSet;
let toSave = JSON.stringify(parsed); let toSave = JSON.stringify(parsed, null, 4);
fs.writeFileSync(getConfigLocation(), toSave, "utf-8"); fs.writeFileSync(getConfigLocation(), toSave, "utf-8");
} }
export async function setConfigBulk(object: Settings) { export async function setConfigBulk(object: Settings) {
let toSave = JSON.stringify(object); let toSave = JSON.stringify(object, null, 4);
fs.writeFileSync(getConfigLocation(), toSave, "utf-8"); fs.writeFileSync(getConfigLocation(), toSave, "utf-8");
} }
export async function checkIfConfigExists() { export async function checkIfConfigExists() {