Update GameActivityToggle.plugin.js

This commit is contained in:
Mirco Wittrien 2024-11-11 21:46:17 +01:00
parent 5e534c91ae
commit 1b9f44fda5
1 changed files with 65 additions and 25 deletions

View File

@ -2,7 +2,7 @@
* @name GameActivityToggle * @name GameActivityToggle
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.2.6 * @version 1.2.7
* @description Adds a Quick-Toggle Game Activity Button * @description Adds a Quick-Toggle Game Activity Button
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -62,7 +62,7 @@ module.exports = (_ => {
} }
} : (([Plugin, BDFDB]) => { } : (([Plugin, BDFDB]) => {
var _this; var _this;
var toggleButton; var toggleButton, toggleItem;
const ActivityToggleComponent = class ActivityToggle extends BdApi.React.Component { const ActivityToggleComponent = class ActivityToggle extends BdApi.React.Component {
componentDidMount() { componentDidMount() {
@ -89,11 +89,55 @@ module.exports = (_ => {
name: enabled ? BDFDB.LibraryComponents.SvgIcon.Names.GAMEPAD : BDFDB.LibraryComponents.SvgIcon.Names.GAMEPAD_DISABLED name: enabled ? BDFDB.LibraryComponents.SvgIcon.Names.GAMEPAD : BDFDB.LibraryComponents.SvgIcon.Names.GAMEPAD_DISABLED
})) }))
}), }),
onClick: _ => _this.toggle() onClick: _ => {
_this.toggle();
if (toggleItem) BDFDB.ReactUtils.forceUpdate(toggleItem);
}
})); }));
} }
}; };
const ActivityToggleItemComponent = class ActivityToggleItem extends BdApi.React.Component {
componentDidMount() {
toggleItem = this;
}
componentWillUnmount() {
toggleItem = null;
}
render() {
const enabled = this.props.forceState != undefined ? this.props.forceState : BDFDB.DiscordUtils.getSetting("status", "showCurrentGame");
delete this.props.forceState;
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.UserPopoutItem, {
label: BDFDB.LanguageUtils.LanguageStrings.ACTIVITY_STATUS,
id: BDFDB.ContextMenuUtils.createItemId(_this.name, "activity-toggle"),
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
name: BDFDB.LibraryComponents.SvgIcon.Names.GAMEPAD,
width: 16,
height: 16
}),
hint: enabled ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.menucolordefault,
background: BDFDB.disCN.menucheckbox,
foreground: BDFDB.disCN.menucheck,
name: BDFDB.LibraryComponents.SvgIcon.Names.CHECKBOX,
style: {background: "unset"},
onClick: _ => {
_this.toggle();
if (toggleButton) BDFDB.ReactUtils.forceUpdate(toggleButton);
}
}) : BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, {
className: BDFDB.disCN.menucolordefault,
name: BDFDB.LibraryComponents.SvgIcon.Names.CHECKBOX_EMPTY,
style: {background: "unset"},
onClick: _ => {
_this.toggle();
if (toggleButton) BDFDB.ReactUtils.forceUpdate(toggleButton);
}
})
});
}
};
var sounds = [], keybind; var sounds = [], keybind;
return class GameActivityToggle extends Plugin { return class GameActivityToggle extends Plugin {
@ -114,11 +158,9 @@ module.exports = (_ => {
}; };
this.modulePatches = { this.modulePatches = {
before: [
"Menu"
],
after: [ after: [
"Account" "Account",
"AccountPopout"
] ]
}; };
@ -150,6 +192,8 @@ module.exports = (_ => {
if (newSettings.showCurrentGame != undefined) { if (newSettings.showCurrentGame != undefined) {
if (toggleButton) toggleButton.props.forceState = newSettings.showCurrentGame.value; if (toggleButton) toggleButton.props.forceState = newSettings.showCurrentGame.value;
BDFDB.ReactUtils.forceUpdate(toggleButton); BDFDB.ReactUtils.forceUpdate(toggleButton);
if (toggleItem) toggleItem.props.forceState = newSettings.showCurrentGame.value;
BDFDB.ReactUtils.forceUpdate(toggleItem);
BDFDB.DataUtils.save({date: new Date(), value: newSettings.showCurrentGame.value}, this, "cachedState"); BDFDB.DataUtils.save({date: new Date(), value: newSettings.showCurrentGame.value}, this, "cachedState");
} }
}}); }});
@ -222,24 +266,20 @@ module.exports = (_ => {
}); });
} }
processMenu (e) { processAccountPopout (e) {
if (!this.settings.general.showItem || (e.instance.props.navId != "account" && e.instance.props.navId != "status")) return; if (!this.settings.general.showItem) return;
let [_, oldIndex] = BDFDB.ContextMenuUtils.findItem(e.instance, {id: BDFDB.ContextMenuUtils.createItemId(this.name, "activity-toggle")}); let userpopoutMenus = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.userpopoutmenus]]});
if (oldIndex > -1) return; if (!userpopoutMenus) return;
let [children, index] = BDFDB.ContextMenuUtils.findItem(e.instance, {id: ["custom-status", "set-custom-status", "edit-custom-status", "add-custom-status"]}); let [children, index] = BDFDB.ReactUtils.findParent(userpopoutMenus, {props: [["id", "set-status"]]});
if (index > -1) { if (index == -1) return;
let isChecked = BDFDB.DiscordUtils.getSetting("status", "showCurrentGame"); children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryModules.React.Fragment, {
children.push(BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuCheckboxItem, { children: [
label: BDFDB.LanguageUtils.LanguageStrings.ACTIVITY_STATUS, BDFDB.ReactUtils.createElement(ActivityToggleItemComponent, {}),
id: BDFDB.ContextMenuUtils.createItemId(this.name, "activity-toggle"), BDFDB.ReactUtils.createElement("div", {
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuIcon, { className: BDFDB.disCN.userpopoutmenudivider
icon: BDFDB.LibraryComponents.SvgIcon.Names.GAMEPAD })
}), ]
showIconFirst: true, }));
checked: isChecked,
action: _ => this.toggle()
}));
}
} }
processAccount (e) { processAccount (e) {