This repository has been archived by the owner on Dec 17, 2022. It is now read-only.
generated from kernel-addons/PluginTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
45 lines (40 loc) · 1.35 KB
/
preload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { contextBridge } = require("electron")
const { resolve, join } = require("path")
const { promises, constants } = require("fs")
const { access } = promises
const exec = require("util").promisify(require("child_process").exec)
contextBridge.exposeInMainWorld("installPackage", async (link) => {
if (process.platform === "darwin") {
process.env.PATH += `:/usr/local/bin:${process.env.HOME}/Library/pnpm`
}
const packagesPath = resolve(__dirname, "..")
const packagePath = join(packagesPath, link[7])
try {
await exec(`git clone ${link[0]}`, {
cwd: packagesPath,
})
try {
await access(join(packagePath, "package.json"), constants.F_OK)
try {
await exec(`pnpm i --production`, {
cwd: packagePath,
})
} catch (error) {
console.error(error)
}
} catch {}
try {
await access(join(packagePath, "main.js"), constants.F_OK)
return {
reloadMessage:
"Main.js file detected: Please quit Discord from the system tray",
}
} catch (error) {
return {
reloadMessage: "Please reload discord with Ctrl+R",
}
}
} catch (error) {
return { error }
}
})