Skip to content

Commit 6555e03

Browse files
committed
Handle error while creating app directory
1 parent 3091595 commit 6555e03

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

injectors/main.js

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* https://powercord.dev/porkord-license
55
*/
66

7-
const rmdirRf = require('../src/fake_node_modules/powercord/util/rmdirRf');
8-
const { existsSync } = require('fs');
9-
const { mkdir, writeFile } = require('fs').promises;
10-
const { join, sep } = require('path');
11-
const { AnsiEscapes } = require('./log');
7+
const rmdirRf = require("../src/fake_node_modules/powercord/util/rmdirRf");
8+
const { existsSync } = require("fs");
9+
const { mkdir, writeFile } = require("fs").promises;
10+
const { join, sep } = require("path");
11+
const { AnsiEscapes } = require("./log");
1212

1313
exports.inject = async ({ getAppDir }) => {
1414
const appDir = await getAppDir();
@@ -17,25 +17,47 @@ exports.inject = async ({ getAppDir }) => {
1717
* @todo: verify if there is nothing in discord_desktop_core as well
1818
* @todo: prompt to automatically uninject and continue
1919
*/
20-
console.log('Looks like you already have an injector in place. Try unplugging (`npm run unplug`) and try again.', '\n');
21-
console.log(`${AnsiEscapes.YELLOW}NOTE:${AnsiEscapes.RESET} If you already have BetterDiscord or another client mod injected, Powercord cannot run along with it!`);
22-
console.log('Read our FAQ for more details: https://powercord.dev/faq#bd-and-pc');
20+
console.log(
21+
"Looks like you already have an injector in place. Try unplugging (`npm run unplug`) and try again.",
22+
"\n"
23+
);
24+
console.log(
25+
`${AnsiEscapes.YELLOW}NOTE:${AnsiEscapes.RESET} If you already have BetterDiscord or another client mod injected, Powercord cannot run along with it!`
26+
);
27+
console.log(
28+
"Read our FAQ for more details: https://powercord.dev/faq#bd-and-pc"
29+
);
30+
return false;
31+
}
32+
33+
try {
34+
await mkdir(appDir);
35+
} catch (err) {
36+
console.log(
37+
"It appears that your Discord Canary installation is broken. Try reinstalling and run again.",
38+
"\n"
39+
);
40+
console.log(
41+
`${AnsiEscapes.YELLOW}NOTE:${AnsiEscapes.RESET} This issue has been known to happen using non-official Discord Canary installs. Try using the official package if you're not already.`
42+
);
2343
return false;
2444
}
2545

26-
await mkdir(appDir);
2746
await Promise.all([
2847
writeFile(
29-
join(appDir, 'index.js'),
30-
`require(\`${__dirname.replace(RegExp(sep.repeat(2), 'g'), '/')}/../src/patcher.js\`)`
48+
join(appDir, "index.js"),
49+
`require(\`${__dirname.replace(
50+
RegExp(sep.repeat(2), "g"),
51+
"/"
52+
)}/../src/patcher.js\`)`
3153
),
3254
writeFile(
33-
join(appDir, 'package.json'),
55+
join(appDir, "package.json"),
3456
JSON.stringify({
35-
main: 'index.js',
36-
name: 'discord'
57+
main: "index.js",
58+
name: "discord",
3759
})
38-
)
60+
),
3961
]);
4062

4163
return true;
@@ -45,7 +67,9 @@ exports.uninject = async ({ getAppDir }) => {
4567
const appDir = await getAppDir();
4668

4769
if (!existsSync(appDir)) {
48-
console.log('There is nothing to unplug. You are already running Discord without mods.');
70+
console.log(
71+
"There is nothing to unplug. You are already running Discord without mods."
72+
);
4973
return false;
5074
}
5175

0 commit comments

Comments
 (0)