This commit is contained in:
smartfrigde 2023-05-14 13:51:11 +02:00
parent 4f31bcb32e
commit ab60e43bf1
2 changed files with 18 additions and 18 deletions

View file

@ -1,4 +1,4 @@
import {BrowserWindow, app, ipcMain, shell, dialog} from "electron"; import {BrowserWindow, app, dialog, ipcMain, shell} from "electron";
import {sleep} from "../utils"; import {sleep} from "../utils";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
@ -141,22 +141,22 @@ export function createTManagerWindow(): void {
mainWindow.webContents.reload(); mainWindow.webContents.reload();
}); });
ipcMain.on("addToDisabled", async (_event, name: string) => { ipcMain.on("addToDisabled", async (_event, name: string) => {
fs.appendFileSync(path.join(userDataPath, "/disabled.txt"), name + "\n"); fs.appendFileSync(path.join(userDataPath, "/disabled.txt"), `${name}\n`);
sleep(1000); sleep(1000);
}); });
ipcMain.on("disabled", async (e) => { ipcMain.on("disabled", async (e) => {
e.returnValue = fs.readFileSync(path.join(userDataPath, "/disabled.txt")).toString(); e.returnValue = fs.readFileSync(path.join(userDataPath, "/disabled.txt")).toString();
}); });
ipcMain.on("removeFromDisabled", async (_event, name: string) => { ipcMain.on("removeFromDisabled", async (_event, name: string) => {
var e = await fs.readFileSync(path.join(userDataPath, "/disabled.txt")).toString(); let e = await fs.readFileSync(path.join(userDataPath, "/disabled.txt")).toString();
fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), e.replace(name, "")); fs.writeFileSync(path.join(userDataPath, "/disabled.txt"), e.replace(name, ""));
sleep(1000); sleep(1000);
}); });
ipcMain.on("installBDTheme", async (_event, link: string) => { ipcMain.on("installBDTheme", async (_event, link: string) => {
try { try {
var code = await (await fetch(link)).text(); let code = await (await fetch(link)).text();
var manifest = parseBDManifest(code); let manifest = parseBDManifest(code);
var themePath = path.join(themesFolder, manifest.name?.replace(" ", "-") + "-BD"); let themePath = path.join(themesFolder, `${manifest.name?.replace(" ", "-")}-BD`);
if (!fs.existsSync(themePath)) { if (!fs.existsSync(themePath)) {
fs.mkdirSync(themePath); fs.mkdirSync(themePath);
console.log(`Created ${manifest.name} folder`); console.log(`Created ${manifest.name} folder`);

View file

@ -1,17 +1,17 @@
import {ipcRenderer} from "electron"; import {ipcRenderer} from "electron";
import {sleep} from "../utils"; import {sleep} from "../utils";
ipcRenderer.on("themeManifest", (_event, json) => { ipcRenderer.on("themeManifest", (_event, json) => {
var manifest = JSON.parse(json); let manifest = JSON.parse(json);
console.log(manifest); console.log(manifest);
sleep(1000); sleep(1000);
var e = document.getElementById("cardBox"); let e = document.getElementById("cardBox");
var id = manifest.name.replace(" ", "-"); let id = manifest.name.replace(" ", "-");
e?.insertAdjacentHTML( e?.insertAdjacentHTML(
"beforeend", "beforeend",
` `
<div class="card"> <div class="card">
<div class="flex-box"> <div class="flex-box">
<h3 id="${id + "header"}">${manifest.name}</h3> <h3 id="${`${id}header`}">${manifest.name}</h3>
<input id="${id}" class="tgl tgl-light left" type="checkbox" /> <input id="${id}" class="tgl tgl-light left" type="checkbox" />
<label class="tgl-btn left" for="${id}"></label> <label class="tgl-btn left" for="${id}"></label>
</div> </div>
@ -20,10 +20,10 @@ ipcRenderer.on("themeManifest", (_event, json) => {
</div> </div>
` `
); );
document.getElementById(id + "header")!.addEventListener("click", () => { document.getElementById(`${id}header`)!.addEventListener("click", () => {
document.getElementById("themeInfoModal")!.style.display = "block"; document.getElementById("themeInfoModal")!.style.display = "block";
document.getElementById("themeInfoName")!.textContent = `${manifest.name} by ${manifest.author}`; document.getElementById("themeInfoName")!.textContent = `${manifest.name} by ${manifest.author}`;
document.getElementById("themeInfoDesc")!.textContent = manifest.description + "\n\n" + manifest.version; document.getElementById("themeInfoDesc")!.textContent = `${manifest.description}\n\n${manifest.version}`;
if (manifest.source != undefined) if (manifest.source != undefined)
document.getElementById( document.getElementById(
"themeInfoButtons" "themeInfoButtons"
@ -33,14 +33,14 @@ ipcRenderer.on("themeManifest", (_event, json) => {
"themeInfoButtons" "themeInfoButtons"
)!.innerHTML += `<a href="${manifest.website}" class="button">Website</a>`; )!.innerHTML += `<a href="${manifest.website}" class="button">Website</a>`;
if (manifest.invite != undefined) if (manifest.invite != undefined)
document.getElementById("themeInfoButtons")!.innerHTML += `<a href="${ document.getElementById(
"https://discord.gg/" + manifest.invite "themeInfoButtons"
}" class="button">Support Discord</a>`; )!.innerHTML += `<a href="${`https://discord.gg/${manifest.invite}`}" class="button">Support Discord</a>`;
}); });
if (!ipcRenderer.sendSync("disabled").includes(id)) { if (!ipcRenderer.sendSync("disabled").includes(id)) {
(<HTMLInputElement>document.getElementById(id)).checked = true; (document.getElementById(id) as HTMLInputElement).checked = true;
} }
(<HTMLInputElement>document.getElementById(id))!.addEventListener("input", function (evt) { (document.getElementById(id) as HTMLInputElement)!.addEventListener("input", function (evt) {
ipcRenderer.send("reloadMain"); ipcRenderer.send("reloadMain");
if (this.checked) { if (this.checked) {
ipcRenderer.send("removeFromDisabled", id); ipcRenderer.send("removeFromDisabled", id);
@ -55,6 +55,6 @@ document.addEventListener("DOMContentLoaded", () => {
document.getElementById("themeInfoButtons")!.innerHTML = ""; document.getElementById("themeInfoButtons")!.innerHTML = "";
}); });
document.getElementById("download")!.addEventListener("click", () => { document.getElementById("download")!.addEventListener("click", () => {
ipcRenderer.send("installBDTheme", (<HTMLInputElement>document.getElementById("themeLink"))!.value); ipcRenderer.send("installBDTheme", (document.getElementById("themeLink") as HTMLInputElement)!.value);
}); });
}); });