From 9653cec2c9994580cb14d1a9459450157b3194b6 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Thu, 17 Jan 2019 13:46:11 +0100 Subject: [PATCH] fixed maxmin issue in OTB --- Plugins/OldTitleBar/OldTitleBar.plugin.js | 168 +++++++++------------- 1 file changed, 69 insertions(+), 99 deletions(-) diff --git a/Plugins/OldTitleBar/OldTitleBar.plugin.js b/Plugins/OldTitleBar/OldTitleBar.plugin.js index 8a4de34f4d..0a6b14c347 100644 --- a/Plugins/OldTitleBar/OldTitleBar.plugin.js +++ b/Plugins/OldTitleBar/OldTitleBar.plugin.js @@ -1,6 +1,14 @@ //META{"name":"OldTitleBar"}*// class OldTitleBar { + getName () {return "OldTitleBar";} + + getVersion () {return "1.5.2";} + + getAuthor () {return "DevilBro";} + + getDescription () {return "Reverts the title bar back to its former self.";} + initConstructor () { this.patchModules = { "HeaderBar":["componentDidMount","componentDidUpdate"], @@ -16,7 +24,7 @@ class OldTitleBar { display: none !important; } - ${BDFDB.dotCN.channelheaderheaderbardrag} { + body:not(.settingsTitlebarOTB-added) ${BDFDB.dotCN.channelheaderheaderbardrag} { -webkit-app-region: drag !important; } @@ -53,23 +61,14 @@ class OldTitleBar { `; - this.maxButtonIsMaxMarkup = + this.maxButtonMarkup = ` - - - - - `; - - this.maxButtonIsMinMarkup = - ` - - - - + `; + this.maxButtonInnerMin = ``; + this.maxButtonInnerMax = ``; this.closeButtonMarkup = ` @@ -90,29 +89,20 @@ class OldTitleBar { }; } - getName () {return "OldTitleBar";} - - getDescription () {return "Reverts the title bar back to its former self.";} - - getVersion () {return "1.5.1";} - - getAuthor () {return "DevilBro";} - getSettingsPanel () { if (!this.started || typeof BDFDB !== "object") return; var settings = BDFDB.getAllData(this, "settings"); var settingshtml = `
${this.getName()}
`; for (let key in settings) { - settingshtml += `

${this.defaults.settings[key].description}

`; + settingshtml += `

${this.defaults.settings[key].description}

`; } settingshtml += `
`; - var settingspanel = $(settingshtml)[0]; + let settingspanel = BDFDB.htmlToElement(settingshtml); - BDFDB.initElements(settingspanel); + BDFDB.initElements(settingspanel, this); - $(settingspanel) - .on("click", BDFDB.dotCN.switchinner, (e) => {this.updateSettings(settingspanel, e.currentTarget.value);}); + BDFDB.addChildEventListener(settingspanel, "click", BDFDB.dotCN.switchinner, e => {this.updateSettings(settingspanel, e.currentTarget.value);}); return settingspanel; } @@ -122,7 +112,7 @@ class OldTitleBar { start () { var libraryScript = null; - if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) { + if (!global.BDFDB || typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) { libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); @@ -131,22 +121,24 @@ class OldTitleBar { document.head.appendChild(libraryScript); } this.startTimeout = setTimeout(() => {this.initialize();}, 30000); - if (typeof BDFDB === "object" && typeof BDFDB.isLibraryOutdated === "function") this.initialize(); - else libraryScript.addEventListener("load", () => {this.initialize();}); + if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize(); + else if (libraryScript) libraryScript.addEventListener("load", () => { + BDFDB.loaded = true; + this.initialize(); + }); } initialize () { - if (typeof BDFDB === "object") { + if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { BDFDB.loadMessage(this); + BDFDB.addEventListener(this, window, "resize", e => {this.changeMaximizeButtons();}); + this.window = require("electron").remote.getCurrentWindow(); - $(window).on("resize." + this.getName(), (e) => {this.changeMaximizeButton();}); - this.patchMainScreen(BDFDB.getData("displayNative", this, "settings")); - document.body.classList.add("hidden-by-OTB"); - document.querySelector(BDFDB.dotCN.titlebar).classList.add("hidden-by-OTB"); + BDFDB.addClass([document.body,document.querySelector(BDFDB.dotCN.titlebar)], "hidden-by-OTB"); BDFDB.WebModules.forceAllUpdates(this); } @@ -157,10 +149,10 @@ class OldTitleBar { stop () { - if (typeof BDFDB === "object") { - BDFDB.removeEles(".headerbarOTB",".settingsTitlebarOTB"); + if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { + BDFDB.removeEles(".headerbarOTB", ".settingsTitlebarOTB"); - BDFDB.removeClasses("hidden-by-OTB"); + BDFDB.removeClasses("hidden-by-OTB", "settingsTitlebarOTB-added"); BDFDB.unloadMessage(this); } @@ -182,7 +174,11 @@ class OldTitleBar { if (notifybar) notifybar.querySelector(BDFDB.dotCN.noticedismiss).click(); if (this.patched) { notifybar = BDFDB.createNotificationsBar("Changed nativebar settings, relaunch to see changes:", {type:"danger",btn:"Relaunch",id:"OldTitleBarNotifyBar"}); - $(notifybar).on("click." + this.getName(), BDFDB.dotCN.noticebutton, (e) => {this.doRelaunch();}); + notifybar.querySelector(BDFDB.dotCN.noticebutton).addEventListener("click", e => { + let app = require("electron").remote.app; + app.relaunch(); + app.quit(); + }); } } } @@ -202,91 +198,65 @@ class OldTitleBar { } else if (methodnames.includes("componentWillUnmount")) { BDFDB.removeEles(".settingsTitlebarOTB"); + BDFDB.removeClass(document.body, "settingsTitlebarOTB-added"); this.addTitleBar(); } } addTitleBar () { - $("*").off("." + this.getName()); BDFDB.removeEles(".headerbarOTB"); var settings = BDFDB.getAllData(this, "settings"); if (BDFDB.getData("addOldBar", this, "settings")) { - var headerbar = $(``)[0]; + var headerbar = BDFDB.htmlToElement(``); this.createButtons(headerbar); - $(BDFDB.dotCNS.channelheaderheaderbardrag + BDFDB.dotCN.flex + " > " + BDFDB.dotCN.channelheadericonmargin).parent().append(headerbar); + let headerbaricon = document.querySelector(BDFDB.dotCNS.channelheaderheaderbardrag + BDFDB.dotCN.flex + " > " + BDFDB.dotCN.channelheadericonmargin); + if (headerbaricon) headerbaricon.parentElement.appendChild(headerbar); + this.changeMaximizeButtons(); } } addSettingsTitleBar (settingspane) { BDFDB.removeEles(".settingsTitlebarOTB"); if (BDFDB.getData("addToSettings", this, "settings")) { - var settingsbar = $(`
`)[0]; + BDFDB.addClass(document.body, "settingsTitlebarOTB-added"); + var settingsbar = BDFDB.htmlToElement(`
`); this.createButtons(settingsbar); settingspane.parentElement.appendChild(settingsbar); + this.changeMaximizeButtons(); } } createButtons (bar) { + var settings = BDFDB.containsClass(bar, "settingsTitlebarOTB"); if (BDFDB.getData("reloadButton", this, "settings")) { - $(bar) - .append(bar.classList.contains("settingsTitlebarOTB") ? "" : this.dividerMarkup) - .append(this.reloadButtonMarkup) - .on("click." + this.getName(), ".reloadButtonOTB " + BDFDB.dotCN.channelheadericon, () => { - this.doReload(); - }) - .on("mouseenter." + this.getName(), ".reloadButtonOTB " + BDFDB.dotCN.channelheadericon, (e) => { - BDFDB.createTooltip("Reload", e.currentTarget, {type:"bottom",selector:"reload-button-tooltip"}); - }); - } - $(bar) - .append(bar.classList.contains("settingsTitlebarOTB") ? "" : this.dividerMarkup) - .append(this.minButtonMarkup) - .append(this.isMaximized() ? this.maxButtonIsMaxMarkup : this.maxButtonIsMinMarkup) - .append(this.closeButtonMarkup) - .on("click." + this.getName(), ".minButtonOTB " + BDFDB.dotCN.channelheadericon, () => { - this.doMinimize(); - }) - .on("click." + this.getName(), ".maxButtonOTB " + BDFDB.dotCN.channelheadericon, () => { - this.doMaximize(); - }) - .on("click." + this.getName(), ".closeButtonOTB " + BDFDB.dotCN.channelheadericon, () => { - this.doClose(); + if (!settings) bar.appendChild(BDFDB.htmlToElement(this.dividerMarkup)); + var reloadbutton = BDFDB.htmlToElement(this.reloadButtonMarkup); + bar.appendChild(reloadbutton); + var reloadbuttonicon = reloadbutton.querySelector(BDFDB.dotCN.channelheadericon); + reloadbuttonicon.addEventListener("click", () => {this.window.reload();}); + reloadbuttonicon.addEventListener("mouseenter", e => { + BDFDB.createTooltip("Reload", reloadbuttonicon, {type:"bottom",selector:"reload-button-tooltip"}); }); + } + if (!settings) bar.appendChild(BDFDB.htmlToElement(this.dividerMarkup)); + var minbutton = BDFDB.htmlToElement(this.minButtonMarkup); + bar.appendChild(minbutton); + minbutton.querySelector(BDFDB.dotCN.channelheadericon).addEventListener("click", () => {this.window.minimize();}); + var maxbutton = BDFDB.htmlToElement(this.maxButtonMarkup); + bar.appendChild(maxbutton); + maxbutton.querySelector(BDFDB.dotCN.channelheadericon).addEventListener("click", () => { + if (this.window.isMaximized()) this.window.unmaximize(); + else this.window.maximize(); + this.changeMaximizeButtons(); + }); + var closebutton = BDFDB.htmlToElement(this.closeButtonMarkup); + bar.appendChild(closebutton); + closebutton.querySelector(BDFDB.dotCN.channelheadericon).addEventListener("click", () => {this.window.close();}); } - doReload () { - this.window.reload(); - } - - doMinimize () { - this.window.minimize(); - } - - doMaximize () { - if (this.isMaximized()) this.window.unmaximize(); - else this.window.maximize(); - this.changeMaximizeButton(); - } - - isMaximized () { - var pos = this.window.getPosition(); - var size = this.window.getSize(); - return (pos[0] == 0 && pos[1] == 0 && size[0] == global.window.screen.availWidth && size[1] == global.window.screen.availHeight); - } - - doClose () { - this.window.close(); - } - - doRelaunch () { - var app = require("electron").remote.app; - app.relaunch(); - app.quit(); - } - - changeMaximizeButton () { - var maxButtonHTML = this.isMaximized() ? this.maxButtonIsMaxMarkup : this.maxButtonIsMinMarkup; - document.querySelectorAll(".maxButtonOTB").forEach(maxButton => {maxButton.outerHTML = maxButtonHTML;}); + changeMaximizeButtons () { + var innerHTML = this.window.isMaximized() ? this.maxButtonInnerMax : this.maxButtonInnerMin; + document.querySelectorAll(".maxButtonOTB g").forEach(g => {g.innerHTML = innerHTML;}); } patchMainScreen (enable) {