Ready for release
This commit is contained in:
parent
31d29253ab
commit
d0124cef8a
3 changed files with 121 additions and 105 deletions
22
README.md
Normal file
22
README.md
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Kernel Package Downloader
|
||||||
|
|
||||||
|
A package for the [kernel client mod](https://github.com/kernel-mod/) to download other packages from the #packages-link channel with a single click. (Compatable with openasar)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
### [Webpack Package](https://github.com/strencher-kernel/webpack)
|
||||||
|
|
||||||
|
To install the webpack package:
|
||||||
|
|
||||||
|
1. `cd <your kernel packages folder>`
|
||||||
|
2. `git clone https://github.com/strencher-kernel/webpack`
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
**Before you follow this make sure you have the prerequisites.**
|
||||||
|
|
||||||
|
1. `cd <your kernel packages folder>`
|
||||||
|
2. `git clone https://github.com/Henry-Hiles/kernel-package-downloader`
|
||||||
|
3. Restart discord with `Ctrl+R`
|
28
preload.js
28
preload.js
|
@ -9,20 +9,18 @@ const execWithPromise = async (command, options) =>
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld("package", {
|
contextBridge.exposeInMainWorld("installPackage", async (link) => {
|
||||||
install: async (link) => {
|
const packagesPath = resolve(__dirname, "..")
|
||||||
const packagesPath = resolve(__dirname, "..")
|
try {
|
||||||
try {
|
await execWithPromise(`git clone ${link[0]}`, {
|
||||||
await execWithPromise(`git clone ${link[0]}`, {
|
cwd: packagesPath,
|
||||||
cwd: packagesPath,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
await execWithPromise("pnpm i --production", {
|
await execWithPromise("pnpm i --production", {
|
||||||
cwd: join(packagesPath, link[7]),
|
cwd: join(packagesPath, link[7]),
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
176
renderer.js
176
renderer.js
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
export default new (class PackageDownloader {
|
export default new (class PackageDownloader {
|
||||||
async start() {
|
async start() {
|
||||||
|
const pluginLog = (msg, logFunc = console.info) =>
|
||||||
|
logFunc(`%c[${this.constructor.name}] `, "color:#14bbaa", msg)
|
||||||
|
|
||||||
|
pluginLog("Started successfully")
|
||||||
|
|
||||||
await Webpack.whenReady
|
await Webpack.whenReady
|
||||||
const { React } = window.Webpack.common
|
const { React } = Webpack.common
|
||||||
const MiniPopover = Webpack.findByDisplayName("MiniPopover", {
|
const MiniPopover = Webpack.findByDisplayName("MiniPopover", {
|
||||||
default: true,
|
default: true,
|
||||||
})
|
})
|
||||||
|
@ -27,103 +32,91 @@ export default new (class PackageDownloader {
|
||||||
props.channel.id == "899717501120806963"
|
props.channel.id == "899717501120806963"
|
||||||
)
|
)
|
||||||
args[0].children.unshift(
|
args[0].children.unshift(
|
||||||
React.createElement(
|
React.createElement(() => {
|
||||||
(componentProps) => {
|
const [disabled, setDisabled] = React.useState(false)
|
||||||
const [disabled, setDisabled] =
|
|
||||||
React.useState(false)
|
|
||||||
const props = componentProps.props
|
|
||||||
|
|
||||||
const gitURL = props.message.content
|
const gitURL = props.message.content
|
||||||
.slice(
|
.slice(props.message.content.indexOf("Repository"))
|
||||||
props.message.content.indexOf("Repository")
|
.match(
|
||||||
)
|
/((git@|http(s)?:\/\/)([\w\.@]+)(\/|:))([\w,\-,\_]+)\/([\w,\-,\_]+)(.git){0,1}((\/){0,1})/
|
||||||
.match(
|
)
|
||||||
/((git@|http(s)?:\/\/)([\w\.@]+)(\/|:))([\w,\-,\_]+)\/([\w,\-,\_]+)(.git){0,1}((\/){0,1})/
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!disabled)
|
if (!disabled)
|
||||||
Object.values(
|
Object.values(
|
||||||
kernel.packages.getPackages()
|
kernel.packages.getPackages()
|
||||||
).forEach((pkg) => {
|
).forEach((pkg) => {
|
||||||
if (pkg.path.split("/").at(-1) == gitURL[7])
|
if (pkg.path.split("/").at(-1) == gitURL[7])
|
||||||
setDisabled(true)
|
setDisabled(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
return [
|
return [
|
||||||
React.createElement(
|
React.createElement(
|
||||||
Tooltip,
|
Tooltip,
|
||||||
{
|
{
|
||||||
position: "top",
|
position: "top",
|
||||||
text: disabled
|
text: disabled
|
||||||
? "Already Installed"
|
? "Already Installed"
|
||||||
: "Install Package",
|
: "Install Package",
|
||||||
},
|
},
|
||||||
(args) =>
|
(args) =>
|
||||||
React.createElement(
|
React.createElement(
|
||||||
MiniPopover.Button,
|
MiniPopover.Button,
|
||||||
{
|
{
|
||||||
...args,
|
...args,
|
||||||
disabled: disabled,
|
disabled: disabled,
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
setDisabled(true)
|
setDisabled(true)
|
||||||
const failed =
|
const failed =
|
||||||
await window.package.install(
|
await window.installPackage(
|
||||||
gitURL
|
gitURL
|
||||||
)
|
)
|
||||||
|
|
||||||
if (failed) {
|
if (failed) {
|
||||||
Toasts.showToast(
|
Toasts.showToast(
|
||||||
Toasts.createToast(
|
Toasts.createToast(
|
||||||
"Failed to install package",
|
"Failed to install package",
|
||||||
Toasts.ToastType
|
Toasts.ToastType
|
||||||
.ERROR
|
.ERROR
|
||||||
)
|
|
||||||
)
|
)
|
||||||
console.error(
|
)
|
||||||
`[${this.constructor.name}]`,
|
pluginLog(
|
||||||
"Package installation failed, error above."
|
"Package installation failed, error above.",
|
||||||
|
console.error
|
||||||
|
)
|
||||||
|
setDisabled(false)
|
||||||
|
} else {
|
||||||
|
Toasts.showToast(
|
||||||
|
Toasts.createToast(
|
||||||
|
"Successfully installed package! Please reload discord with Ctrl+R.",
|
||||||
|
Toasts.ToastType
|
||||||
|
.SUCCESS
|
||||||
)
|
)
|
||||||
setDisabled(false)
|
)
|
||||||
} else {
|
pluginLog(
|
||||||
Toasts.showToast(
|
"Successfully installed package! Please reload discord with Ctrl+R."
|
||||||
Toasts.createToast(
|
)
|
||||||
"Successfully installed package! Please reload discord with Ctrl+R.",
|
}
|
||||||
Toasts.ToastType
|
|
||||||
.SUCCESS
|
|
||||||
)
|
|
||||||
)
|
|
||||||
console.log(
|
|
||||||
`%c[${this.constructor.name}]`,
|
|
||||||
"color:#14bbaa",
|
|
||||||
"Successfully installed package! Please reload discord with Ctrl+R."
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
React.createElement(
|
},
|
||||||
"svg",
|
React.createElement(
|
||||||
{
|
"svg",
|
||||||
xmlns: "http://www.w3.org/2000/svg",
|
{
|
||||||
width: "16",
|
xmlns: "http://www.w3.org/2000/svg",
|
||||||
height: "16",
|
width: "16",
|
||||||
fill: "currentColor",
|
height: "16",
|
||||||
class: "bi bi-arrow-down-circle-fill",
|
fill: "currentColor",
|
||||||
viewBox: "0 0 16 16",
|
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("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,
|
React.createElement(MiniPopover.Separator),
|
||||||
null
|
]
|
||||||
),
|
})
|
||||||
]
|
|
||||||
},
|
|
||||||
{ props }
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return funcCopy.apply(this, args)
|
return funcCopy.apply(this, args)
|
||||||
|
@ -131,8 +124,11 @@ export default new (class PackageDownloader {
|
||||||
|
|
||||||
Object.assign(MiniPopover.default, funcCopy)
|
Object.assign(MiniPopover.default, funcCopy)
|
||||||
|
|
||||||
|
pluginLog("Patched, ready to download packages!")
|
||||||
|
|
||||||
this.stop = () => {
|
this.stop = () => {
|
||||||
MiniPopover.default = funcCopy
|
MiniPopover.default = funcCopy
|
||||||
|
pluginLog("Stopped successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
Reference in a new issue