Skip to content

Commit

Permalink
Merge pull request #30 from n1ckoates/themes
Browse files Browse the repository at this point in the history
Theme improvements
  • Loading branch information
twnlink authored Aug 25, 2024
2 parents f060a81 + 548f93b commit 15b1d90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 12 additions & 0 deletions injector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ electron.app.whenReady().then(() => {
});
// #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 });
});
});
// #endregion

// #region IPC Bullshit
let evalHandleCount = 0;
let evalHandles = {};
Expand Down
24 changes: 15 additions & 9 deletions src/api/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@ export function toggleTheme(url) {

export async function importTheme(url, enabled = true) {
let manifest;
let text;

try {
manifest = parseManifest(await (await fetch(url)).text());
text = await (await fetch(url)).text();
} catch {
throw "Failed to parse theme manifest!";
throw "Failed to fetch theme!";
}

if (!["name", "author", "description"].every((i) => typeof manifest[i] === "string"))
throw "Manifest doesn't contain required properties!";

const { name, author, description } = manifest;
try {
manifest = parseManifest(text);
} catch (e) {
manifest = {
name: url.split("/").pop(),
author: "Unknown",
description: "No description provided.",
}
}

themesStore.unshift({
name,
author,
description,
name: manifest.name,
author: manifest.author,
description: manifest.description,
enabled,
url,
});
Expand Down

0 comments on commit 15b1d90

Please sign in to comment.