Skip to content

Commit

Permalink
Fix plugin construction error
Browse files Browse the repository at this point in the history
Changes Keybind classes to be defined on settings page opening.
aarondoet#79
  • Loading branch information
helloworld-1839 authored Mar 28, 2022
1 parent 9fc0783 commit 3cb4abe
Showing 1 changed file with 60 additions and 54 deletions.
114 changes: 60 additions & 54 deletions AccountSwitcher.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,60 +114,64 @@ module.exports = (() => {
}
);
}

const KeyRecorder = class KeyRecorder extends WebpackModules.getByDisplayName("KeyRecorder") {
render() {
const ButtonOptions = WebpackModules.getByProps("ButtonLink");
const Button = ButtonOptions.default;
const ret = super.render();
ret.props.children.props.children.props.children.push(
React.createElement(
DiscordModules.FlexChild,
{
style: { margin: 0 }
},
React.createElement(
Button,
{
className: WebpackModules.getByProps("editIcon", "button").button.split(" ")[1],
size: Button.Sizes.MIN,
color: ButtonOptions.ButtonColors.GREY,
look: ButtonOptions.ButtonLooks.GHOST,
onClick: this.props.onRemove
let KeyRecorder, KeybindModule, Keybind;
function loadKeybind() {
if (!Keybind) {
KeyRecorder = class KeyRecorder extends WebpackModules.getByDisplayName("KeyRecorder") {
render() {
const ButtonOptions = WebpackModules.getByProps("ButtonLink");
const Button = ButtonOptions.default;
const ret = super.render();
ret.props.children.props.children.props.children.push(
React.createElement(
DiscordModules.FlexChild,
{
style: { margin: 0 }
},
React.createElement(
Button,
{
className: WebpackModules.getByProps("editIcon", "button").button.split(" ")[1],
size: Button.Sizes.MIN,
color: ButtonOptions.ButtonColors.GREY,
look: ButtonOptions.ButtonLooks.GHOST,
onClick: this.props.onRemove
},
"Remove"
)
)
);
return ret;
}
};
KeybindModule = class KeybindModule extends DiscordModules.Keybind {
constructor(props) {
super(props);
}
render() {
const ret = super.render();
ret.type = KeyRecorder;
ret.props.account = this.props.account;
ret.props.onRemove = this.props.onRemove;
return ret;
}
};
Keybind = class Keybind extends Settings.SettingField {
constructor(account, onChange, onRemove) {
super(account.name + " (" + account.id + ")", "", onChange, KeybindModule, {
defaultValue: (account.keybind[0] !== -1 && account.keybind.map(a => [0, a])) || [],
onChange: element => value => {
if (!Array.isArray(value)) return;
element.props.value = value;
this.onChange(value.map(a => a[1]));
},
"Remove"
)
)
);
return ret;
}
};
const KeybindModule = class KeybindModule extends DiscordModules.Keybind {
constructor(props) {
super(props);
}
render() {
const ret = super.render();
ret.type = KeyRecorder;
ret.props.account = this.props.account;
ret.props.onRemove = this.props.onRemove;
return ret;
}
};
const Keybind = class Keybind extends Settings.SettingField {
constructor(account, onChange, onRemove) {
super(account.name + " (" + account.id + ")", "", onChange, KeybindModule, {
defaultValue: (account.keybind[0] !== -1 && account.keybind.map(a => [0, a])) || [],
onChange: element => value => {
if (!Array.isArray(value)) return;
element.props.value = value;
this.onChange(value.map(a => a[1]));
},
account,
onRemove
});
account,
onRemove
});
}
};
}
};
}
return class AccountSwitcher extends Plugin {
updateAvatars(){
this.settings.accounts.forEach(acc => {
Expand Down Expand Up @@ -332,8 +336,10 @@ module.exports = (() => {
});
});
}

getSettingsPanel(){

getSettingsPanel() {
loadKeybind();

const panel = document.createElement("div");
panel.className = "form";
panel.style = "width:100%;"
Expand Down

0 comments on commit 3cb4abe

Please sign in to comment.