This commit is contained in:
Mirco Wittrien 2021-04-21 20:20:36 +02:00
parent 071520ce2c
commit 6064e1fbb5
2 changed files with 72 additions and 90 deletions

View File

@ -2,7 +2,7 @@
* @name OldTitleBar
* @author DevilBro
* @authorId 278543574059057154
* @version 1.6.8
* @version 1.6.9
* @description Allows you to switch to Discord's old Titlebar or add the native OS Titlebar
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -17,7 +17,7 @@ module.exports = (_ => {
"info": {
"name": "OldTitleBar",
"author": "DevilBro",
"version": "1.6.8",
"version": "1.6.9",
"description": "Allows you to switch to Discord's old Titlebar or add the native OS Titlebar"
}
};
@ -61,18 +61,15 @@ module.exports = (_ => {
}
} : (([Plugin, BDFDB]) => {
var patched, lastWindowRects;
var settings = {};
return class OldTitleBar extends Plugin {
onLoad () {
patched = false;
this.defaults = {
settings: {
displayNative: {value: !!document.querySelector(".platform-linux"), description: "Display the native Titlebar"},
addOldBar: {value: true, description: "Display the Titlebar in the old Fashion"},
addToSettings: {value: true, description: "Add a Titlebar to Settings Windows"},
reloadButton: {value: false, description: "Add a Reload Button to the Titlebar"}
general: {
addToSettings: {value: true, description: "Adds a Titlebar to Settings Windows"},
reloadButton: {value: false, description: "Adds a Reload Button to the Titlebar"}
}
};
@ -142,68 +139,42 @@ module.exports = (_ => {
BDFDB.DOMUtils.addClass(document.body, BDFDB.disCN._oldtitlebarenabled);
this.forceUpdateAll();
this.patchMainScreen(settings.displayNative);
BDFDB.PatchUtils.forceAllUpdates(this);
}
onStop () {
this.forceUpdateAll();
BDFDB.PatchUtils.forceAllUpdates(this);
BDFDB.DOMUtils.removeClassFromDOM(BDFDB.disCN._oldtitlebarenabled);
}
getSettingsPanel (collapseStates = {}) {
let settingsPanel, settingsItems = [];
let settingsPanel;
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
collapseStates: collapseStates,
children: _ => {
let settingsItems = [];
let isLinux = !!document.querySelector(".platform-linux");
for (let key in settings) {
let isNativeTitlebarSetting = key == "displayNative";
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
for (let key in this.defaults.general) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: isLinux && isNativeTitlebarSetting || settings[key],
disabled: isLinux && isNativeTitlebarSetting,
note: isLinux && isNativeTitlebarSetting && "This is disabled on Linux, because Discord/BD forces the Titlebar on Linux Systems!",
onChange: isNativeTitlebarSetting ? value => {
if (this.patchMainScreen(value)) {
patched = !patched;
let notifybar = document.querySelector("#OldTitleBarNotifyBar");
if (notifybar) notifybar.querySelector(BDFDB.dotCN.noticedismiss).click();
if (patched) {
notifybar = BDFDB.NotificationUtils.notice("Changed native Titlebar Settings. Please relaunch now:", {
type: "danger",
id: "OldTitleBarNotifyBar",
buttons: [{
contents: "Relaunch",
onClick: _ => {BDFDB.LibraryModules.WindowUtils.relaunch();}
}]
});
}
}
} : null
keys: ["general", key],
label: this.defaults.general[key].description,
value: this.settings.general[key],
}));
}
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
return settingsItems;
}
});
}
onSettingsClosed () {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
BDFDB.PatchUtils.forceAllUpdates(this);
}
}
processApp (e) {
let [children, index] = BDFDB.ReactUtils.findParent(e.instance, {props: [["type", ["WINDOWS", "MACOS"]]]});
@ -215,7 +186,6 @@ module.exports = (_ => {
}
processHeaderBarContainer (e) {
if (!settings.addOldBar) return;
let children = BDFDB.ObjectUtils.get(e.returnvalue, "props.toolbar.props.children");
if (!children) {
let [oldToolbarParent, oldToolbarIndex] = BDFDB.ReactUtils.findParent(e.returnvalue, {key: "OldTitleBar-toolbar"});
@ -242,7 +212,7 @@ module.exports = (_ => {
}
injectSettingsToolbar (children, fixed) {
if (!settings.addToSettings) return;
if (!this.settings.general.addToSettings) return;
let toolbar = BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCNS.channelheadertoolbar + BDFDB.disCN._oldtitlebarsettingstoolbar,
children: [],
@ -254,7 +224,7 @@ module.exports = (_ => {
injectButtons (children, addFirstDivider) {
if (addFirstDivider) children.push(BDFDB.ReactUtils.createElement("div", {className: BDFDB.disCN.channelheaderdivider}))
if (settings.reloadButton) {
if (this.settings.general.reloadButton) {
children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
text: BDFDB.LanguageUtils.LanguageStrings.ERRORS_RELOAD,
tooltipConfig: {type: "bottom"},
@ -325,19 +295,6 @@ module.exports = (_ => {
getWindowRects () {
return {x: window.screenX, y: window.screenY, width: window.outerWidth, height: window.outerHeight};
}
patchMainScreen (enable) {
try {
if (BdApi.getWindowPreference("frame") != enable) {
BdApi.setWindowPreference("frame", enable);
return true;
}
return false;
}
catch (err) {
return false;
}
}
};
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
})();

View File

@ -2,7 +2,7 @@
* @name ServerHider
* @author DevilBro
* @authorId 278543574059057154
* @version 6.1.9
* @version 6.2.0
* @description Allows you to hide certain Servers in your Server List
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -17,12 +17,12 @@ module.exports = (_ => {
"info": {
"name": "ServerHider",
"author": "DevilBro",
"version": "6.1.9",
"version": "6.2.0",
"description": "Allows you to hide certain Servers in your Server List"
},
"changeLog": {
"fixed": {
"Works again": "Can discord stop messing with the server list, jeez"
"added": {
"Streamer Mode": "Added Option to only hide Servers while in Streamer Mode"
}
}
};
@ -67,6 +67,12 @@ module.exports = (_ => {
} : (([Plugin, BDFDB]) => {
return class ServerHider extends Plugin {
onLoad () {
this.defaults = {
general: {
onlyHideInStream: {value: false, description: "Only hide selected Servers while in Streamer Mode"}
}
};
this.patchedModules = {
after: {
Guilds: "render"
@ -75,6 +81,10 @@ module.exports = (_ => {
}
onStart () {
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.DispatchApiUtils, "dispatch", {after: e => {
if (e.methodArguments[0].type == BDFDB.DiscordConstants.ActionTypes.STREAMER_MODE_UPDATE) BDFDB.PatchUtils.forceAllUpdates(this);
}});
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.FolderStore, "getGuildFolderById", {after: e => {
let hiddenGuildIds = BDFDB.DataUtils.load(this, "hidden", "servers") || [];
if (e.returnValue && hiddenGuildIds.length) {
@ -93,14 +103,26 @@ module.exports = (_ => {
}
getSettingsPanel (collapseStates = {}) {
let settingsPanel, settingsItems = [];
let settingsPanel;
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
collapseStates: collapseStates,
children: _ => {
let settingsItems = [];
for (let key in this.defaults.general) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["general", key],
label: this.defaults.general[key].description,
value: this.settings.general[key],
}));
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Unhide all Servers/Folders",
onClick: _ => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to unhide all servers and folders?", _ => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to unhide all Servers and Folders?", _ => {
BDFDB.DataUtils.save([], this, "hidden");
BDFDB.PatchUtils.forceAllUpdates(this);
});
@ -108,7 +130,9 @@ module.exports = (_ => {
children: BDFDB.LanguageUtils.LanguageStrings.RESET
}));
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
return settingsItems;
}
});
}
onGuildContextMenu (e) {
@ -185,6 +209,7 @@ module.exports = (_ => {
}
handleGuilds (returnvalue) {
if (this.settings.general.onlyHideInStream && !BDFDB.LibraryModules.StreamerModeStore.enabled) return;
let hiddenEles = BDFDB.DataUtils.load(this, "hidden");
let hiddenGuildIds = hiddenEles.servers || [];
let hiddenFolderIds = hiddenEles.folders || [];