Added main.js file detecting
This commit is contained in:
parent
e8a3c7fc41
commit
cc53a210ae
2 changed files with 32 additions and 15 deletions
14
preload.js
14
preload.js
|
@ -1,6 +1,7 @@
|
|||
const { contextBridge } = require("electron")
|
||||
const { resolve, join } = require("path")
|
||||
const { exec } = require("child_process")
|
||||
const { promises, constants } = require("fs")
|
||||
|
||||
const execWithPromise = async (command, options) =>
|
||||
new Promise(async (resolve, reject) =>
|
||||
|
@ -11,16 +12,23 @@ const execWithPromise = async (command, options) =>
|
|||
|
||||
contextBridge.exposeInMainWorld("installPackage", async (link) => {
|
||||
const packagesPath = resolve(__dirname, "..")
|
||||
const packagePath = join(packagesPath, link[7])
|
||||
try {
|
||||
await execWithPromise(`git clone ${link[0]}`, {
|
||||
cwd: packagesPath,
|
||||
})
|
||||
|
||||
await execWithPromise("pnpm i --production", {
|
||||
cwd: join(packagesPath, link[7]),
|
||||
cwd: packagePath,
|
||||
})
|
||||
|
||||
try {
|
||||
await promises.access(join(packagePath, "main.js"), constants.F_OK)
|
||||
return "Main.js file detected: Please quit Discord from the system tray"
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return true
|
||||
return "Please reload discord with Ctrl+R"
|
||||
}
|
||||
} catch (error) {
|
||||
return console.error(error)
|
||||
}
|
||||
})
|
||||
|
|
33
renderer.js
33
renderer.js
|
@ -60,10 +60,29 @@ export default new (class PackageDownloader {
|
|||
disabled: disabled,
|
||||
onClick: async () => {
|
||||
setDisabled(true)
|
||||
const failed =
|
||||
|
||||
const reloadMessage =
|
||||
await window.installPackage(gitURL)
|
||||
|
||||
if (failed) {
|
||||
if (reloadMessage) {
|
||||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
`Successfully installed package! ${
|
||||
reloadMessage
|
||||
? `${reloadMessage}.`
|
||||
: ""
|
||||
}`,
|
||||
Toasts.ToastType.SUCCESS
|
||||
)
|
||||
)
|
||||
pluginLog(
|
||||
`Successfully installed package! ${
|
||||
reloadMessage
|
||||
? `${reloadMessage}.`
|
||||
: ""
|
||||
}`
|
||||
)
|
||||
} else {
|
||||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
"Failed to install package",
|
||||
|
@ -75,16 +94,6 @@ export default new (class PackageDownloader {
|
|||
console.error
|
||||
)
|
||||
setDisabled(false)
|
||||
} else {
|
||||
Toasts.showToast(
|
||||
Toasts.createToast(
|
||||
"Successfully installed package! Please reload discord with Ctrl+R.",
|
||||
Toasts.ToastType.SUCCESS
|
||||
)
|
||||
)
|
||||
pluginLog(
|
||||
"Successfully installed package! Please reload discord with Ctrl+R."
|
||||
)
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
Reference in a new issue