Update index.js

pull/98/head
Delta-official 2 years ago committed by GitHub
parent 4df26a181c
commit e72ede1af2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,7 @@ const { join, posix, sep } = require('path');
const { prompt } = require('inquirer');
const { promisify } = require('util');
const chalk = require('chalk');
const { platform } = require('os');
const exec = promisify(_exec);
@ -127,7 +128,11 @@ async function promptManualPathCompletion (action) {
} else if (process.platform === 'darwin') {
discordAppPath = join(discordPath, 'Contents', 'Resources', 'app');
} else {
discordAppPath = join(discordPath, 'resources', 'app');
discordAppPath = join(discordPath, 'resources');
if (confirmExistAndHasPermissions(discordAppPath)) {
mkdir(discordAppPath);
}
}
if (!discordAppPath || !(await confirmExistAndHasPermissions(discordAppPath))) {
@ -166,7 +171,7 @@ async function getDiscordAppPath () {
if (process.platform === 'win32') {
const discordPath = join(process.env.LOCALAPPDATA, release?.replace(' ', ''));
if (!discordPath || !(await confirmExistAndHasPermissions(discordPath))) {
info(`Unfortunately, the ${release} directory couldn't be located.`);
error(`Unfortunately, the ${release} directory couldn't be located or you don't have enough permissions to access it.`);
return promptManualPathCompletion('inject');
}
@ -187,51 +192,27 @@ async function getDiscordAppPath () {
const discordPath = join('/Applications', `${release}.app`);
if (!discordPath || !(await confirmExistAndHasPermissions(discordPath))) {
error(`Unfortunately, the ${release} directory couldn't be located.`);
error(`Unfortunately, the ${release} directory couldn't be located or you don't have enough permissions to access it.`);
return promptManualPathCompletion('inject');
}
return join(discordPath, 'Contents', 'Resources', 'app');
}
/**
* If all else fails, assume the user is on Linux and try to find the Discord process.
*/
const discordProcess = (await exec('ps x')).toString().split('\n').map(s => s.split(' ').filter(Boolean)).find(process => process[4] && (/discord$/i).test(process[4]) && process.includes('--type=renderer'));
/**
* If the process can't be found, try to determine the directory path by checking if any
* predefined path directories exist.
*/
if (!discordProcess) {
warn('Cannot find Discord process, falling back to legacy path detection...');
/**
* Instead of using ~, use this to determine the user's home directory instead of the root's home directory.
* Unix-like systems
*/
const homeDirectory = (await exec('grep $(logname) /etc/passwd | cut -d ":" -f6').toString()).trim();
const paths = [
`/usr/share/${release.toLowerCase().replace(' ', '-')}`,
`/usr/lib64/${release.toLowerCase().replace(' ', '-')}`,
`/opt/${release.toLowerCase().replace(' ', '-')}`,
`/opt/${release.replace(' ', '')}`,
`${homeDirectory}/.local/bin/${release.replace(' ', '')}/`
];
const discordPath = paths.find(async path => !(await confirmExistAndHasPermissions(path)));
// eslint-disable-next-line no-else-return
} else {
const discordPath = join('/opt', `${release}`, 'resources');
if (!discordPath || !(await confirmExistAndHasPermissions(discordPath))) {
error(`Unfortunately, the ${release} directory couldn't be located.`);
error(`Unfortunately, the ${release} directory couldn't be located or you don't have enough permissions to access it.`);
return promptManualPathCompletion('inject');
}
return join(discordPath, 'resources', 'app');
}
mkdir(join(discordPath, 'app'));
const discordPath = discordProcess[4].split('/');
discordPath.splice(discordPath.length - 1, 1);
return join('/', ...discordPath, 'resources', 'app');
return join(discordPath, 'app');
}
}
/**
@ -368,7 +349,9 @@ async function inject (discordAppPath) {
}
await ensureDependencies();
await mkdir(discordAppPath);
if (confirmExistAndHasPermissions(discordAppPath)) {
await mkdir(discordAppPath);
}
Promise.all([
/**
* Relative to dist/setup.bundle.js
@ -423,6 +406,13 @@ async function startInjectionProcess () {
'*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n'
);
if (process.platform !== 'win32' || process.platform !== 'darwin') {
if (process.getuid() !== 0) {
error(`Vizality installer must be run as root on unix-like systems\nPlease rerun the installer with this command: ${chalk.reset()}node setup:sudo`);
process.exit(77);
}
}
/**
* Not sure why someone would clone into System32... but let's not let them proceed to avoid any issues.
*/
@ -504,13 +494,25 @@ async function startInjectionProcess () {
*/
switch (true) {
case release.includes('Stable'):
release = 'Discord';
if (process.platform === 'win32' || process.platform === "darwin") {
release = 'Discord';
} else {
release = 'discord'
}
break;
case release.includes('PTB'):
release = 'Discord PTB';
if (process.platform === 'win32' || process.platform === "darwin") {
release = 'Discord PTB';
} else {
release = 'discord-ptb'
}
break;
case release.includes('Canary'):
release = 'Discord Canary';
if (process.platform === 'win32' || process.platform === "darwin") {
release = 'Discord Canary';
} else {
release = 'discord-canary'
}
break;
}
switch (true) {

Loading…
Cancel
Save