Update GameActivityToggle.plugin.js
This commit is contained in:
parent
5e534c91ae
commit
1b9f44fda5
|
@ -2,7 +2,7 @@
|
|||
* @name GameActivityToggle
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 1.2.6
|
||||
* @version 1.2.7
|
||||
* @description Adds a Quick-Toggle Game Activity Button
|
||||
* @invite Jx3TjNS
|
||||
* @donate https://www.paypal.me/MircoWittrien
|
||||
|
@ -62,7 +62,7 @@ module.exports = (_ => {
|
|||
}
|
||||
} : (([Plugin, BDFDB]) => {
|
||||
var _this;
|
||||
var toggleButton;
|
||||
var toggleButton, toggleItem;
|
||||
|
||||
const ActivityToggleComponent = class ActivityToggle extends BdApi.React.Component {
|
||||
componentDidMount() {
|
||||
|
@ -89,11 +89,55 @@ module.exports = (_ => {
|
|||
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;
|
||||
|
||||
return class GameActivityToggle extends Plugin {
|
||||
|
@ -114,11 +158,9 @@ module.exports = (_ => {
|
|||
};
|
||||
|
||||
this.modulePatches = {
|
||||
before: [
|
||||
"Menu"
|
||||
],
|
||||
after: [
|
||||
"Account"
|
||||
"Account",
|
||||
"AccountPopout"
|
||||
]
|
||||
};
|
||||
|
||||
|
@ -150,6 +192,8 @@ module.exports = (_ => {
|
|||
if (newSettings.showCurrentGame != undefined) {
|
||||
if (toggleButton) toggleButton.props.forceState = newSettings.showCurrentGame.value;
|
||||
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");
|
||||
}
|
||||
}});
|
||||
|
@ -222,24 +266,20 @@ module.exports = (_ => {
|
|||
});
|
||||
}
|
||||
|
||||
processMenu (e) {
|
||||
if (!this.settings.general.showItem || (e.instance.props.navId != "account" && e.instance.props.navId != "status")) return;
|
||||
let [_, oldIndex] = BDFDB.ContextMenuUtils.findItem(e.instance, {id: BDFDB.ContextMenuUtils.createItemId(this.name, "activity-toggle")});
|
||||
if (oldIndex > -1) return;
|
||||
let [children, index] = BDFDB.ContextMenuUtils.findItem(e.instance, {id: ["custom-status", "set-custom-status", "edit-custom-status", "add-custom-status"]});
|
||||
if (index > -1) {
|
||||
let isChecked = BDFDB.DiscordUtils.getSetting("status", "showCurrentGame");
|
||||
children.push(BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuCheckboxItem, {
|
||||
label: BDFDB.LanguageUtils.LanguageStrings.ACTIVITY_STATUS,
|
||||
id: BDFDB.ContextMenuUtils.createItemId(this.name, "activity-toggle"),
|
||||
icon: _ => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuIcon, {
|
||||
icon: BDFDB.LibraryComponents.SvgIcon.Names.GAMEPAD
|
||||
}),
|
||||
showIconFirst: true,
|
||||
checked: isChecked,
|
||||
action: _ => this.toggle()
|
||||
}));
|
||||
}
|
||||
processAccountPopout (e) {
|
||||
if (!this.settings.general.showItem) return;
|
||||
let userpopoutMenus = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.userpopoutmenus]]});
|
||||
if (!userpopoutMenus) return;
|
||||
let [children, index] = BDFDB.ReactUtils.findParent(userpopoutMenus, {props: [["id", "set-status"]]});
|
||||
if (index == -1) return;
|
||||
children.splice(index, 0, BDFDB.ReactUtils.createElement(BDFDB.LibraryModules.React.Fragment, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(ActivityToggleItemComponent, {}),
|
||||
BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCN.userpopoutmenudivider
|
||||
})
|
||||
]
|
||||
}));
|
||||
}
|
||||
|
||||
processAccount (e) {
|
||||
|
|
Loading…
Reference in New Issue