diff --git a/preload.js b/preload.js index 192aaa7..89d8ab8 100644 --- a/preload.js +++ b/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) { + return "Please reload discord with Ctrl+R" + } } catch (error) { - console.error(error) - return true + return console.error(error) } }) diff --git a/renderer.js b/renderer.js index 541689e..0a2218f 100644 --- a/renderer.js +++ b/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." - ) } }, },