diff --git a/preload.js b/preload.js index 89d8ab8..824c6b8 100644 --- a/preload.js +++ b/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 } } }) diff --git a/renderer.js b/renderer.js index 0a2218f..0ac5ab0 100644 --- a/renderer.js +++ b/renderer.js @@ -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") } } -})() +})()``