import {ipcRenderer} from "electron";
import {addStyle} from "../utils";
import * as fs from "fs";
import * as path from "path";
import os from "os";
export function injectTitlebar() {
document.addEventListener("DOMContentLoaded", function (event) {
var elem = document.createElement("div");
elem.innerHTML = ``;
elem.classList.add("withFrame-haYltI");
if (document.getElementById("app-mount") == null) {
document.body.appendChild(elem);
} else {
document.getElementById("app-mount")!.prepend(elem);
}
const titlebarcssPath = path.join(__dirname, "../", "/content/css/titlebar.css");
const wordmarkcssPath = path.join(__dirname, "../", "/content/css/logos.css");
addStyle(fs.readFileSync(titlebarcssPath, "utf8"));
addStyle(fs.readFileSync(wordmarkcssPath, "utf8"));
document.body.setAttribute("customTitlebar", "");
document.body.setAttribute("armcord-platform", os.platform());
var minimize = document.getElementById("minimize");
var maximize = document.getElementById("maximize");
var quit = document.getElementById("quit");
minimize!.addEventListener("click", () => {
ipcRenderer.send("win-minimize");
});
maximize!.addEventListener("click", () => {
if (ipcRenderer.sendSync("win-isMaximized") == true) {
ipcRenderer.send("win-unmaximize");
document.body.removeAttribute("isMaximized");
} else if (ipcRenderer.sendSync("win-isNormal") == true) {
ipcRenderer.send("win-maximize");
}
});
quit!.addEventListener("click", () => {
if (ipcRenderer.sendSync("minimizeToTray") === true) {
ipcRenderer.send("win-hide");
} else if (ipcRenderer.sendSync("minimizeToTray") === false) {
ipcRenderer.send("win-quit");
}
});
});
}
export function injectHummusTitlebar() {
document.addEventListener("DOMContentLoaded", function (event) {
var elem = document.createElement("div");
elem.innerHTML = `
`;
elem.classList.add("win-buttons");
elem.classList.add("win-buttons-light");
document.getElementsByClassName("titlebar")[0].appendChild(elem);
document.body.setAttribute("customTitlebar", "");
document.body.setAttribute("hummus", "");
document.body.setAttribute("armcord-platform", os.platform());
addStyle(`
html, body {
background-color: #1e2124;
}
.friends-header,
.chat > .title-wrap {
float: right !important;
padding-right: 140px !important;
}`);
var minimize = document.getElementById("minimize");
var maximize = document.getElementById("maximize");
var quit = document.getElementById("quit");
minimize!.addEventListener("click", () => {
ipcRenderer.send("win-minimize");
});
maximize!.addEventListener("click", () => {
if (ipcRenderer.sendSync("win-isMaximized") == true) {
ipcRenderer.send("win-unmaximize");
document.body.removeAttribute("isMaximized");
} else if (ipcRenderer.sendSync("win-isNormal") == true) {
ipcRenderer.send("win-maximize");
}
});
quit!.addEventListener("click", () => {
if (ipcRenderer.sendSync("minimizeToTray") === true) {
ipcRenderer.send("win-hide");
} else if (ipcRenderer.sendSync("minimizeToTray") === false) {
ipcRenderer.send("win-quit");
}
});
});
}