diff --git a/.gitignore b/.gitignore index 8fa902c78..fc61f2e58 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ config.json # macOS .DS_Store + +.installdir-* diff --git a/injectors/linux.js b/injectors/linux.js index 353531f56..1077db5e5 100644 --- a/injectors/linux.js +++ b/injectors/linux.js @@ -1,5 +1,5 @@ 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'); @@ -7,8 +7,9 @@ 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({ @@ -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') @@ -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; + } +}