armcord/utils/theme.js

54 lines
3 KiB
JavaScript
Raw Normal View History

2021-05-14 16:01:52 +00:00
const fs = require("fs");
2021-05-25 10:24:42 +00:00
const {shell} = require('electron');
const electron = require("electron");
2021-05-25 10:24:42 +00:00
const ArmCord = require("./ArmCord.js");
const userDataPath = (electron.app || electron.remote.app).getPath("userData");
const themeFolder = userDataPath + "/themes/";
if (!fs.existsSync(themeFolder)) {
fs.mkdirSync(themeFolder);
console.log("Created theme folder");
}
2021-05-14 19:47:01 +00:00
window.addEventListener("DOMContentLoaded", () => {
2021-07-15 13:45:56 +00:00
console.log("Theme Module Loaded"); // I KNOW THIS IS A MESS BUT IT'S WORKING MESS, XOXO
2021-05-14 19:47:01 +00:00
fs.readdirSync(themeFolder).forEach((file) => {
try {
2021-07-15 13:45:56 +00:00
if (file.includes('DISABLED')) {
console.log(`Skipping ${file}.`)
const manifest = fs.readFileSync(`${userDataPath}/themes/${file}/manifest.json`, "utf8");
var themeFile = JSON.parse(manifest);
var html = `<div id="tm-list-item"><div id="theme-name">${themeFile.name}</div><div id="theme-author">By ${themeFile.author}</div><div id="theme-description">${themeFile.description}</div></div><br><br>`;
document.getElementById("tm-disabled").innerHTML = html + document.getElementById("tm-disabled").innerHTML;
}
const manifest = fs.readFileSync(`${userDataPath}/themes/${file}/manifest.json`, "utf8");
2021-05-14 20:54:40 +00:00
var themeFile = JSON.parse(manifest);
const theme = fs.readFileSync(`${userDataPath}/themes/${file}/${themeFile.theme}`, "utf8");
if (themeFile.theme.endsWith(".scss")) {
console.log(
2021-05-22 12:39:46 +00:00
`%cCouldn't load ${themeFile.name} made by ${themeFile.author}. ArmCord doesn't support SCSS files! If you want to have this theme ported, feel free to reach out https://discord.gg/F25bc4RYDt `,
"color:red; font-weight: bold; font-size: 50px;color: red;"
);
}
2021-05-25 10:24:42 +00:00
ArmCord.addStyle(theme);
2021-05-22 12:39:46 +00:00
var html = `<div id="tm-list-item"><div id="theme-name">${themeFile.name}</div><div id="theme-author">By ${themeFile.author}</div><div id="theme-description">${themeFile.description}</div></div><br><br>`;
document.getElementById("tm-list").innerHTML = html + document.getElementById("tm-list").innerHTML;
2021-05-15 10:35:22 +00:00
console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red");
2021-05-14 19:47:01 +00:00
} catch (err) {
console.error(err);
}
});
document.getElementById("open-themes-btn").onclick = function () {shell.openPath(`${userDataPath}/themes`);};
2021-05-28 16:00:30 +00:00
document.getElementsByClassName("back-btn")[0].onclick = function () {
if (document.getElementById("ac-channel").innerHTML == "stable") {
window.location.href = "https://discord.com/app";
} else if (document.getElementById("ac-channel").innerHTML == "canary") {
window.location.href = "https://canary.discord.com/app";
} else if (document.getElementById("ac-channel").innerHTML == "ptb") {
window.location.href = "https://ptb.discord.com/app";
} else if (document.getElementById("ac-channel").innerHTML == "foss") {
window.location.href = "https://dev.fosscord.com/app";
} else {
window.location.href = "https://discord.com/app";
};
};
2021-05-14 16:01:52 +00:00
});