n is not a function
This commit is contained in:
parent
a238ab299a
commit
a9b6d3c2a5
4 changed files with 137 additions and 14 deletions
10
index.json
10
index.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "PluginTemplate",
|
||||
"id": "plugin-template",
|
||||
"description": "A template for future Kernel plugin development.",
|
||||
"dependencies": []
|
||||
}
|
||||
"name": "Kernel Package Downloader",
|
||||
"id": "kernel-package-downloader",
|
||||
"description": "A package downloader for kernel.",
|
||||
"dependencies": ["strencher.webpack"]
|
||||
}
|
||||
|
|
1
main.js
1
main.js
|
@ -1 +0,0 @@
|
|||
// Do stuff in the main context of discord.
|
29
preload.js
29
preload.js
|
@ -1 +1,28 @@
|
|||
// Do something in the preload of discord.
|
||||
const { contextBridge } = require("electron")
|
||||
const { resolve, join } = require("path")
|
||||
const { exec } = require("child_process")
|
||||
|
||||
const execWithPromise = async (command, options) =>
|
||||
new Promise(async (resolve, reject) =>
|
||||
exec(command, options, (err, stout, sterr) =>
|
||||
err ? reject(err, sterr) : resolve(stout)
|
||||
)
|
||||
)
|
||||
|
||||
contextBridge.exposeInMainWorld("package", {
|
||||
install: async (link) => {
|
||||
const packagesPath = resolve(__dirname, "..")
|
||||
try {
|
||||
await execWithPromise(`git clone ${link[0]}`, {
|
||||
cwd: packagesPath,
|
||||
})
|
||||
|
||||
await execWithPromise("pnpm i --production", {
|
||||
cwd: join(packagesPath, link[7]),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return true
|
||||
}
|
||||
},
|
||||
})
|
||||
|
|
111
renderer.js
111
renderer.js
|
@ -1,9 +1,106 @@
|
|||
export default new class PluginTemplate {
|
||||
start() {
|
||||
console.log("Hello World!");
|
||||
}
|
||||
/// <reference path="../webpack/types.d.ts" />
|
||||
|
||||
stop() {
|
||||
console.log("Bye World!");
|
||||
export default new (class PackageDownloader {
|
||||
async start() {
|
||||
await Webpack.whenReady
|
||||
const { React } = Webpack.common
|
||||
const MiniPopover = Webpack.findByDisplayName("MiniPopover", {
|
||||
default: true,
|
||||
})
|
||||
const Toasts = Object.assign(
|
||||
{},
|
||||
...Webpack.getByProps("showToast", "createToast", {
|
||||
bulk: true,
|
||||
})
|
||||
)
|
||||
const Tooltip = Webpack.findByDisplayName("Tooltip")
|
||||
const funcCopy = MiniPopover.default
|
||||
|
||||
MiniPopover.default = function (...args) {
|
||||
const props = args[0].children.at
|
||||
? args[0].children.at(-1).props
|
||||
: null
|
||||
|
||||
if (
|
||||
props?.message &&
|
||||
props.channel &&
|
||||
props.channel.id == "899717501120806963"
|
||||
) {
|
||||
const gitURL = props.message.content
|
||||
.slice(props.message.content.indexOf("Repository"))
|
||||
.match(
|
||||
/((git@|http(s)?:\/\/)([\w\.@]+)(\/|:))([\w,\-,\_]+)\/([\w,\-,\_]+)(.git){0,1}((\/){0,1})/
|
||||
)
|
||||
|
||||
const Button = () => {
|
||||
const [disabled, setDisabled] = React.useState(false)
|
||||
|
||||
Object.values(kernel.packages.getPackages()).forEach(
|
||||
(pkg) => {
|
||||
if (pkg.path.split("/").at(-1) == gitURL[7])
|
||||
setDisabled(true)
|
||||
}
|
||||
)
|
||||
|
||||
return React.createElement(
|
||||
Tooltip,
|
||||
{
|
||||
position: top,
|
||||
text: disabled
|
||||
? "Already Installed"
|
||||
: "Install Package",
|
||||
},
|
||||
(args) =>
|
||||
React.createElement(
|
||||
MiniPopover.Button,
|
||||
{
|
||||
...args,
|
||||
disabled: disabled,
|
||||
onClick: async () => {
|
||||
setDisabled(true)
|
||||
const failed =
|
||||
await window.package.install(gitURL)
|
||||
|
||||
if (failed) {
|
||||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
"Failed to install package",
|
||||
Toasts.ToastType.ERROR
|
||||
)
|
||||
)
|
||||
setDisabled(false)
|
||||
} else
|
||||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
"Successfully installed package! Please reload discord with Ctrl+R.",
|
||||
Toasts.ToastType.SUCCESS
|
||||
)
|
||||
)
|
||||
},
|
||||
},
|
||||
React.createElement(
|
||||
"svg",
|
||||
{
|
||||
xmlns: "http://www.w3.org/2000/svg",
|
||||
width: "16",
|
||||
height: "16",
|
||||
fill: "currentColor",
|
||||
class: "bi bi-arrow-down-circle-fill",
|
||||
viewBox: "0 0 16 16",
|
||||
},
|
||||
React.createElement("path", {
|
||||
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)
|
||||
)
|
||||
}
|
||||
|
||||
args[0].children.unshift(React.createElement(Button))
|
||||
}
|
||||
return funcCopy.apply(this, args)
|
||||
}
|
||||
Object.assign(MiniPopover.default, funcCopy)
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
|
Reference in a new issue