Changed button into anonymous arrow function
This commit is contained in:
parent
2db736aa59
commit
31d29253ab
1 changed files with 99 additions and 85 deletions
54
renderer.js
54
renderer.js
|
@ -16,18 +16,35 @@ export default new (class PackageDownloader {
|
|||
const Tooltip = Webpack.findByDisplayName("Tooltip")
|
||||
const funcCopy = MiniPopover.default
|
||||
|
||||
const Button = (componentProps) => {
|
||||
const [disabled, setDisabled] = React.useState(false)
|
||||
MiniPopover.default = (...args) => {
|
||||
const props = args[0].children.at
|
||||
? args[0].children.at(-1).props
|
||||
: null
|
||||
|
||||
if (
|
||||
props?.message &&
|
||||
props.channel &&
|
||||
props.channel.id == "899717501120806963"
|
||||
)
|
||||
args[0].children.unshift(
|
||||
React.createElement(
|
||||
(componentProps) => {
|
||||
const [disabled, setDisabled] =
|
||||
React.useState(false)
|
||||
const props = componentProps.props
|
||||
|
||||
const gitURL = props.message.content
|
||||
.slice(props.message.content.indexOf("Repository"))
|
||||
.slice(
|
||||
props.message.content.indexOf("Repository")
|
||||
)
|
||||
.match(
|
||||
/((git@|http(s)?:\/\/)([\w\.@]+)(\/|:))([\w,\-,\_]+)\/([\w,\-,\_]+)(.git){0,1}((\/){0,1})/
|
||||
)
|
||||
|
||||
if (!disabled)
|
||||
Object.values(kernel.packages.getPackages()).forEach((pkg) => {
|
||||
Object.values(
|
||||
kernel.packages.getPackages()
|
||||
).forEach((pkg) => {
|
||||
if (pkg.path.split("/").at(-1) == gitURL[7])
|
||||
setDisabled(true)
|
||||
})
|
||||
|
@ -49,7 +66,8 @@ export default new (class PackageDownloader {
|
|||
disabled: disabled,
|
||||
onClick: async () => {
|
||||
setDisabled(true)
|
||||
const failed = await window.package.install(
|
||||
const failed =
|
||||
await window.package.install(
|
||||
gitURL
|
||||
)
|
||||
|
||||
|
@ -57,7 +75,8 @@ export default new (class PackageDownloader {
|
|||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
"Failed to install package",
|
||||
Toasts.ToastType.ERROR
|
||||
Toasts.ToastType
|
||||
.ERROR
|
||||
)
|
||||
)
|
||||
console.error(
|
||||
|
@ -69,7 +88,8 @@ export default new (class PackageDownloader {
|
|||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
"Successfully installed package! Please reload discord with Ctrl+R.",
|
||||
Toasts.ToastType.SUCCESS
|
||||
Toasts.ToastType
|
||||
.SUCCESS
|
||||
)
|
||||
)
|
||||
console.log(
|
||||
|
@ -96,21 +116,15 @@ export default new (class PackageDownloader {
|
|||
)
|
||||
)
|
||||
),
|
||||
React.createElement(MiniPopover.Separator, null),
|
||||
React.createElement(
|
||||
MiniPopover.Separator,
|
||||
null
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
MiniPopover.default = (...args) => {
|
||||
const props = args[0].children.at
|
||||
? args[0].children.at(-1).props
|
||||
: null
|
||||
|
||||
if (
|
||||
props?.message &&
|
||||
props.channel &&
|
||||
props.channel.id == "899717501120806963"
|
||||
},
|
||||
{ props }
|
||||
)
|
||||
)
|
||||
args[0].children.unshift(React.createElement(Button, { props }))
|
||||
|
||||
return funcCopy.apply(this, args)
|
||||
}
|
||||
|
|
Reference in a new issue