This commit is contained in:
Henry Hiles 2022-04-26 08:36:46 -04:00
parent a9b6d3c2a5
commit 2db736aa59

View file

@ -3,7 +3,7 @@
export default new (class PackageDownloader { export default new (class PackageDownloader {
async start() { async start() {
await Webpack.whenReady await Webpack.whenReady
const { React } = Webpack.common const { React } = window.Webpack.common
const MiniPopover = Webpack.findByDisplayName("MiniPopover", { const MiniPopover = Webpack.findByDisplayName("MiniPopover", {
default: true, default: true,
}) })
@ -16,36 +16,27 @@ export default new (class PackageDownloader {
const Tooltip = Webpack.findByDisplayName("Tooltip") const Tooltip = Webpack.findByDisplayName("Tooltip")
const funcCopy = MiniPopover.default const funcCopy = MiniPopover.default
MiniPopover.default = function (...args) { const Button = (componentProps) => {
const props = args[0].children.at const [disabled, setDisabled] = React.useState(false)
? args[0].children.at(-1).props const props = componentProps.props
: null
if (
props?.message &&
props.channel &&
props.channel.id == "899717501120806963"
) {
const gitURL = props.message.content const gitURL = props.message.content
.slice(props.message.content.indexOf("Repository")) .slice(props.message.content.indexOf("Repository"))
.match( .match(
/((git@|http(s)?:\/\/)([\w\.@]+)(\/|:))([\w,\-,\_]+)\/([\w,\-,\_]+)(.git){0,1}((\/){0,1})/ /((git@|http(s)?:\/\/)([\w\.@]+)(\/|:))([\w,\-,\_]+)\/([\w,\-,\_]+)(.git){0,1}((\/){0,1})/
) )
const Button = () => { if (!disabled)
const [disabled, setDisabled] = React.useState(false) Object.values(kernel.packages.getPackages()).forEach((pkg) => {
Object.values(kernel.packages.getPackages()).forEach(
(pkg) => {
if (pkg.path.split("/").at(-1) == gitURL[7]) if (pkg.path.split("/").at(-1) == gitURL[7])
setDisabled(true) setDisabled(true)
} })
)
return React.createElement( return [
React.createElement(
Tooltip, Tooltip,
{ {
position: top, position: "top",
text: disabled text: disabled
? "Already Installed" ? "Already Installed"
: "Install Package", : "Install Package",
@ -58,8 +49,9 @@ export default new (class PackageDownloader {
disabled: disabled, disabled: disabled,
onClick: async () => { onClick: async () => {
setDisabled(true) setDisabled(true)
const failed = const failed = await window.package.install(
await window.package.install(gitURL) gitURL
)
if (failed) { if (failed) {
Toasts.showToast( Toasts.showToast(
@ -68,14 +60,24 @@ export default new (class PackageDownloader {
Toasts.ToastType.ERROR Toasts.ToastType.ERROR
) )
) )
console.error(
`[${this.constructor.name}]`,
"Package installation failed, error above."
)
setDisabled(false) setDisabled(false)
} else } else {
Toasts.showToast( Toasts.showToast(
Toasts.createToast( Toasts.createToast(
"Successfully installed package! Please reload discord with Ctrl+R.", "Successfully installed package! Please reload discord with Ctrl+R.",
Toasts.ToastType.SUCCESS Toasts.ToastType.SUCCESS
) )
) )
console.log(
`%c[${this.constructor.name}]`,
"color:#14bbaa",
"Successfully installed package! Please reload discord with Ctrl+R."
)
}
}, },
}, },
React.createElement( React.createElement(
@ -92,15 +94,31 @@ export default new (class PackageDownloader {
d: "M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v5.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V4.5z", d: "M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v5.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V4.5z",
}) })
) )
),
React.createElement(MiniPopover.Separator, null)
) )
),
React.createElement(MiniPopover.Separator, null),
]
} }
args[0].children.unshift(React.createElement(Button)) 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(Button, { props }))
return funcCopy.apply(this, args) return funcCopy.apply(this, args)
} }
Object.assign(MiniPopover.default, funcCopy) Object.assign(MiniPopover.default, funcCopy)
this.stop = () => {
MiniPopover.default = funcCopy
}
} }
})() })()