Skip to content

Commit

Permalink
Memorize install directory on Linux (#154)
Browse files Browse the repository at this point in the history
* Memorize install directory on Linux

* Prefer path.join for .installdir file

Co-authored-by: lleyton <[email protected]>
  • Loading branch information
oatmealine and lleyton authored Aug 26, 2022
1 parent be8916e commit 609c7c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ config.json

# macOS
.DS_Store

.installdir-*
20 changes: 16 additions & 4 deletions injectors/linux.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const { join } = require('path');
const { existsSync } = require('fs');
const { existsSync, readFileSync, writeFileSync } = require('fs');
const { execSync } = require('child_process');
const readline = require('readline');
const { BasicMessages, AnsiEscapes, PlatformNames } = require('./log');

// This is to ensure the homedir we get is the actual user's homedir instead of root's homedir
const homedir = execSync('grep $(logname) /etc/passwd | cut -d ":" -f6').toString().trim();

const flatpakDir = '/var/lib/flatpak/app/com.discordapp';
const installDirFile = join(__dirname, '../.installdir-');

const flatpakDir = '/var/lib/flatpak/app/com.discordapp';
const homeFlatpakDir = `${homedir}/.local/share/flatpak/app/com.discordapp`;

const KnownLinuxPaths = Object.freeze({
Expand Down Expand Up @@ -53,7 +54,7 @@ const ProcessRegex = {
dev: /discord-?development$/i
};

exports.getAppDir = async (platform) => {
async function findAppDir(platform) {
const discordProcess = execSync('ps x')
.toString()
.split('\n')
Expand Down Expand Up @@ -88,4 +89,15 @@ exports.getAppDir = async (platform) => {
const discordPath = discordProcess[4].split('/');
discordPath.splice(discordPath.length - 1, 1);
return join('/', ...discordPath, 'resources', 'app');
};
}

exports.getAppDir = async (platform) => {
const installDirPath = installDirFile + platform;
if (existsSync(installDirPath)) {
return readFileSync(installDirPath, 'utf8');
} else {
const appDir = await findAppDir(platform);
writeFileSync(installDirPath, appDir);
return appDir;
}
}

0 comments on commit 609c7c3

Please sign in to comment.