Added main.js file detecting

This commit is contained in:
Henry Hiles 2022-04-28 12:48:17 -04:00
parent e8a3c7fc41
commit cc53a210ae
2 changed files with 32 additions and 15 deletions

View file

@ -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) {
return "Please reload discord with Ctrl+R"
}
} catch (error) {
console.error(error)
return true
return console.error(error)
}
})