-
-
Notifications
You must be signed in to change notification settings - Fork 147
/
index.js
60 lines (55 loc) · 2.41 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Copyright (c) 2018-2020 aetheryx & Bowser65
* All Rights Reserved. Licensed under the Porkord License
* https://powercord.dev/porkord-license
*/
require('./elevate');
require('./env_check')(); // Perform checks
require('../polyfills'); // And then do stuff
const { join } = require('path');
const { readFile, writeFile } = require('fs').promises;
const { BasicMessages } = require('./log');
const main = require('./main.js');
let platformModule;
try {
platformModule = require(`./${process.platform}.js`);
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
console.log(BasicMessages.PLUG_FAILED, '\n');
console.log('It seems like your platform is not supported yet.', '\n');
console.log('Feel free to open an issue about it, so we can add support for it!');
console.log(`Make sure to mention the platform you are on is "${process.platform}" in your issue ticket.`);
console.log('https://github.com/powercord-org/powercord/issues/new/choose');
process.exit(process.argv.includes('--no-exit-codes') ? 0 : 1);
}
}
(async () => {
if (process.argv[2] === 'inject') {
if (await main.inject(platformModule)) {
if (!process.argv.includes('--no-welcome-message')) {
await writeFile(join(__dirname, '../src/__injected.txt'), 'hey cutie');
}
// @todo: prompt to (re)start automatically
console.log(BasicMessages.PLUG_SUCCESS, '\n');
console.log('You now have to completely close the Discord client, from the system tray or through the task manager.');
}
} else if (process.argv[2] === 'uninject') {
if (await main.uninject(platformModule)) {
// @todo: prompt to (re)start automatically
console.log(BasicMessages.UNPLUG_SUCCESS, '\n');
console.log('You now have to completely close the Discord client, from the system tray or through the task manager.');
}
} else {
console.log(`Unsupported argument "${process.argv[2]}", exiting.`);
process.exit(process.argv.includes('--no-exit-codes') ? 0 : 1);
}
})().catch(e => {
if (e.code === 'EACCES') {
// todo: this was linux only (?) so I assume this is now safe to delete
console.log(process.argv[2] === 'inject' ? BasicMessages.PLUG_FAILED : BasicMessages.UNPLUG_FAILED, '\n');
console.log('Powercord wasn\'t able to inject itself due to missing permissions.', '\n');
console.log('Try again with elevated permissions.');
} else {
console.error('fucky wucky', e);
}
});