Some fixes, still doesn't work if pnpm is installed via npm.

This commit is contained in:
Henry Hiles 2022-05-13 14:22:51 -04:00
parent cc53a210ae
commit 2b7b383a4e
2 changed files with 14 additions and 17 deletions

View file

@ -1,34 +1,31 @@
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) =>
exec(command, options, (err, stout, sterr) =>
err ? reject(err, sterr) : resolve(stout)
)
)
const exec = require("util").promisify(require("child_process").exec)
contextBridge.exposeInMainWorld("installPackage", async (link) => {
const packagesPath = resolve(__dirname, "..")
const packagePath = join(packagesPath, link[7])
try {
await execWithPromise(`git clone ${link[0]}`, {
await exec(`git clone ${link[0]}`, {
cwd: packagesPath,
})
await execWithPromise("pnpm i --production", {
await exec("pnpm i --production", {
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"
return {
reloadMessage:
"Main.js file detected: Please quit Discord from the system tray",
}
} catch (error) {
return "Please reload discord with Ctrl+R"
return { reloadMessage: "Please reload discord with Ctrl+R" }
}
} catch (error) {
return console.error(error)
return { errorMessage: error }
}
})

View file

@ -22,7 +22,7 @@ export default new (class PackageDownloader {
const funcCopy = MiniPopover.default
MiniPopover.default = (...args) => {
const props = args[0].children.at
const props = args[0].children.at?.(-1)
? args[0].children.at(-1).props
: null
@ -61,7 +61,7 @@ export default new (class PackageDownloader {
onClick: async () => {
setDisabled(true)
const reloadMessage =
const { reloadMessage, errorMessage } =
await window.installPackage(gitURL)
if (reloadMessage) {
@ -85,12 +85,12 @@ export default new (class PackageDownloader {
} else {
Toasts.showToast(
Toasts.createToast(
"Failed to install package",
"Failed to install package, check console for error.",
Toasts.ToastType.ERROR
)
)
pluginLog(
"Package installation failed, error above.",
`Package installation failed: ${errorMessage}`,
console.error
)
setDisabled(false)
@ -136,4 +136,4 @@ export default new (class PackageDownloader {
pluginLog("Stopped successfully")
}
}
})()
})()``