forked from brunos3d/discord-enable-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.mjs
More file actions
executable file
·92 lines (83 loc) · 2.93 KB
/
index.mjs
File metadata and controls
executable file
·92 lines (83 loc) · 2.93 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env zx
const osPaths = {
// tested os.platform() values
darwin: `${os.homedir()}/Library/Application Support/discord/settings.json`,
win32: `${os.homedir()}/AppData/Roaming/discord/settings.json`,
linux: {
standard: `${os.homedir()}/.config/discord/settings.json`,
flatpak: `${os.homedir()}/.var/app/com.discordapp.Discord/config/discord/settings.json`,
snap: `${os.homedir()}/snap/discord/current/.config/discord/settings.json`,
},
// https://nodejs.org/api/process.html#process_process_platform
// not fully tested os.platform() values
// if one of these is your platform and the script doesn't work, please open an issue
aix: `${os.homedir()}/.config/discord/settings.json`,
freebsd: `${os.homedir()}/.config/discord/settings.json`,
openbsd: `${os.homedir()}/.config/discord/settings.json`,
sunos: `${os.homedir()}/.config/discord/settings.json`,
android: `/data/data/com.discord/files/discord/settings.json`, // typical Android path
};
// Helper function to resolve the config file path
async function resolveConfigPath(pathOrPaths) {
// If it's a string, return it directly
if (typeof pathOrPaths === "string") {
return pathOrPaths;
}
// If it's an object, check which path exists
if (typeof pathOrPaths === "object" && pathOrPaths !== null) {
for (const [key, path] of Object.entries(pathOrPaths)) {
try {
await fs.access(path);
console.log(chalk.blue("Found Discord installation:"), key);
return path;
} catch {
// Path doesn't exist, continue to next
}
}
// If no path exists, return the first one (standard) as fallback
return Object.values(pathOrPaths)[0];
}
return null;
}
const platformPaths = osPaths[os.platform()];
if (!platformPaths) {
console.error(chalk.red("Error: Unsupported platform"), os.platform());
console.log(
chalk.yellow(
"Please open an issue on GitHub with your platform information.",
),
);
console.log(
chalk.yellow(
"https://github.com/brunos3d/discord-enable-devtools/issues/new",
),
);
process.exit(1);
}
const configFile = await resolveConfigPath(platformPaths);
if (!configFile) {
console.error(chalk.red("Error: Could not resolve config file path"));
process.exit(1);
}
try {
const config = await fs.readJson(configFile);
config.DANGEROUS_ENABLE_DEVTOOLS_ONLY_ENABLE_IF_YOU_KNOW_WHAT_YOURE_DOING = true;
await fs.writeJson(configFile, config, { spaces: 2 });
console.log(chalk.black.bgGreen(" DEVTOOLS ENABLED "), configFile);
} catch (error) {
console.error(chalk.red("Error:"), error);
console.log(chalk.yellow("Debug Info:"), {
platform: os.platform(),
configFile,
});
console.log(
chalk.red(
"Could not enable devtools. Make sure Discord is installed or open an issue on GitHub with the error message above.",
),
);
console.log(
chalk.yellow(
"https://github.com/brunos3d/discord-enable-devtools/issues/new",
),
);
}