armcord/src/preload/titlebar.ts

57 lines
2.3 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 16:34:53 +00:00
document.body.setAttribute("armcord-platform", "win32");
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
}