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
23
preload.js
23
preload.js
|
@ -1,34 +1,31 @@
|
||||||
const { contextBridge } = require("electron")
|
const { contextBridge } = require("electron")
|
||||||
const { resolve, join } = require("path")
|
const { resolve, join } = require("path")
|
||||||
const { exec } = require("child_process")
|
|
||||||
const { promises, constants } = require("fs")
|
const { promises, constants } = require("fs")
|
||||||
|
|
||||||
const execWithPromise = async (command, options) =>
|
const exec = require("util").promisify(require("child_process").exec)
|
||||||
new Promise(async (resolve, reject) =>
|
|
||||||
exec(command, options, (err, stout, sterr) =>
|
|
||||||
err ? reject(err, sterr) : resolve(stout)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld("installPackage", async (link) => {
|
contextBridge.exposeInMainWorld("installPackage", async (link) => {
|
||||||
const packagesPath = resolve(__dirname, "..")
|
const packagesPath = resolve(__dirname, "..")
|
||||||
const packagePath = join(packagesPath, link[7])
|
const packagePath = join(packagesPath, link[7])
|
||||||
try {
|
try {
|
||||||
await execWithPromise(`git clone ${link[0]}`, {
|
await exec(`git clone ${link[0]}`, {
|
||||||
cwd: packagesPath,
|
cwd: packagesPath,
|
||||||
})
|
})
|
||||||
|
|
||||||
await execWithPromise("pnpm i --production", {
|
await exec("pnpm i --production", {
|
||||||
cwd: packagePath,
|
cwd: packagePath,
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await promises.access(join(packagePath, "main.js"), constants.F_OK)
|
await promises.access(join(packagePath, "main.js"), constants.F_OK)
|
||||||
return "Main.js file detected: Please quit Discord from the system tray"
|
return {
|
||||||
} catch (error) {
|
reloadMessage:
|
||||||
return "Please reload discord with Ctrl+R"
|
"Main.js file detected: Please quit Discord from the system tray",
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return console.error(error)
|
return { reloadMessage: "Please reload discord with Ctrl+R" }
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return { errorMessage: error }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
10
renderer.js
10
renderer.js
|
@ -22,7 +22,7 @@ export default new (class PackageDownloader {
|
||||||
const funcCopy = MiniPopover.default
|
const funcCopy = MiniPopover.default
|
||||||
|
|
||||||
MiniPopover.default = (...args) => {
|
MiniPopover.default = (...args) => {
|
||||||
const props = args[0].children.at
|
const props = args[0].children.at?.(-1)
|
||||||
? args[0].children.at(-1).props
|
? args[0].children.at(-1).props
|
||||||
: null
|
: null
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ export default new (class PackageDownloader {
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
setDisabled(true)
|
setDisabled(true)
|
||||||
|
|
||||||
const reloadMessage =
|
const { reloadMessage, errorMessage } =
|
||||||
await window.installPackage(gitURL)
|
await window.installPackage(gitURL)
|
||||||
|
|
||||||
if (reloadMessage) {
|
if (reloadMessage) {
|
||||||
|
@ -85,12 +85,12 @@ export default new (class PackageDownloader {
|
||||||
} else {
|
} else {
|
||||||
Toasts.showToast(
|
Toasts.showToast(
|
||||||
Toasts.createToast(
|
Toasts.createToast(
|
||||||
"Failed to install package",
|
"Failed to install package, check console for error.",
|
||||||
Toasts.ToastType.ERROR
|
Toasts.ToastType.ERROR
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
pluginLog(
|
pluginLog(
|
||||||
"Package installation failed, error above.",
|
`Package installation failed: ${errorMessage}`,
|
||||||
console.error
|
console.error
|
||||||
)
|
)
|
||||||
setDisabled(false)
|
setDisabled(false)
|
||||||
|
@ -136,4 +136,4 @@ export default new (class PackageDownloader {
|
||||||
pluginLog("Stopped successfully")
|
pluginLog("Stopped successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})()
|
})()``
|
||||||
|
|
Reference in a new issue