Some fixes, still doesn't work if pnpm is installed via npm.
This commit is contained in:
parent
cc53a210ae
commit
2b7b383a4e
2 changed files with 14 additions and 17 deletions
21
preload.js
21
preload.js
|
@ -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 }
|
||||
}
|
||||
})
|
||||
|
|
Reference in a new issue