armcord/src/preload/titlebar.ts

105 lines
4.2 KiB
TypeScript
Raw Normal View History

2022-03-04 17:53:18 +00:00
import {ipcRenderer} from "electron";
import {addStyle} from "../utils";
import * as fs from "fs";
import * as path from "path";
import os from "os";
2021-12-24 21:56:49 +00:00
export function injectTitlebar() {
2022-03-04 17:53:18 +00:00
document.addEventListener("DOMContentLoaded", function (event) {
var elem = document.createElement("div");
elem.innerHTML = `<nav class="titlebar">
2021-12-24 21:56:49 +00:00
<div class="window-title" id="window-title"></div>
<div id="window-controls-container">
<div id="spacer"></div>
<div id="minimize"><div id="minimize-icon"></div></div>
<div id="maximize"><div id="maximize-icon"></div></div>
<div id="quit"><div id="quit-icon"></div></div>
2021-12-24 21:56:49 +00:00
</div>
</nav>`;
2022-03-04 17:53:18 +00:00
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", "");
2022-07-05 17:02:49 +00:00
document.body.setAttribute("armcord-platform", os.platform());
2022-03-04 17:53:18 +00:00
var minimize = document.getElementById("minimize");
var maximize = document.getElementById("maximize");
var quit = document.getElementById("quit");
2022-03-04 17:53:18 +00:00
minimize!.addEventListener("click", () => {
ipcRenderer.send("win-minimize");
});
2022-03-04 17:53:18 +00:00
maximize!.addEventListener("click", () => {
if (ipcRenderer.sendSync("win-isMaximized") == true) {
ipcRenderer.send("win-unmaximize");
document.body.removeAttribute("isMaximized");
} else if (ipcRenderer.sendSync("win-isNormal") == true) {
2022-03-04 17:53:18 +00:00
ipcRenderer.send("win-maximize");
}
});
2022-03-04 17:53:18 +00:00
quit!.addEventListener("click", () => {
if (ipcRenderer.sendSync("minimizeToTray") === true) {
ipcRenderer.send("win-hide");
} else if (ipcRenderer.sendSync("minimizeToTray") === false) {
ipcRenderer.send("win-quit");
}
});
});
2021-12-24 21:56:49 +00:00
}
export function injectHummusTitlebar() {
document.addEventListener("DOMContentLoaded", function (event) {
var elem = document.createElement("div");
elem.innerHTML = `
<button class="win-minimize" id="minimize"></button><button class="win-maximize" id="maximize"></button><button class="win-close" id="quit"></button>
`;
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");
}
});
});
}