diff --git a/src/inject/injector.ts b/src/inject/injector.ts index f4d1389..ac0baf3 100644 --- a/src/inject/injector.ts +++ b/src/inject/injector.ts @@ -22,6 +22,20 @@ const moveToOrig = async (appDir: string): Promise => { console.log(`RM ${appDir}`); await remove(appDir); } + + // For discord_arch_electron + const unpackedPath = await join(appDir, "..", "app.asar.unpacked"); + const unpackedOrigPath = await join(appDir, "..", "app.orig.asar.unpacked"); + const unpackedExists = await exists(unpackedPath); + const unpackedOrigExists = await exists(unpackedOrigPath); + if (unpackedExists && !unpackedOrigExists) { + console.log(`MV ${unpackedPath} ${unpackedOrigPath}`); + await rename(unpackedPath, unpackedOrigPath); + } + if (unpackedExists) { + console.log(`RM ${unpackedPath}`); + await removeDir(unpackedPath); + } }; const getConfigDir = async (): Promise => await join(await configDir(), "replugged"); @@ -127,5 +141,20 @@ export const uninject = async (appDir: string): Promise => { const origPath = await join(appDir, "..", "app.orig.asar"); console.log(`MV ${origPath} ${appDir}`); await rename(origPath, appDir); + + // For discord_arch_electron + const unpackedPath = await join(appDir, "..", "app.asar.unpacked"); + const unpackedOrigPath = await join(appDir, "..", "app.orig.asar.unpacked"); + const unpackedExists = await exists(unpackedPath); + const unpackedOrigExists = await exists(unpackedOrigPath); + if (unpackedOrigExists && !unpackedExists) { + console.log(`MV ${unpackedOrigPath} ${unpackedPath}`); + await rename(unpackedOrigPath, unpackedPath); + } + if (unpackedOrigExists) { + console.log(`RM ${unpackedOrigPath}`); + await removeDir(unpackedOrigPath); + } + console.log("DONE UNINJECTING!"); }; diff --git a/src/inject/platforms/linux.ts b/src/inject/platforms/linux.ts index e6ba147..89e8e36 100644 --- a/src/inject/platforms/linux.ts +++ b/src/inject/platforms/linux.ts @@ -1,5 +1,5 @@ import { DiscordPlatform } from "../../types"; -import { homeDir, join } from "@tauri-apps/api/path"; +import { basename, homeDir, join } from "@tauri-apps/api/path"; import { Command } from "@tauri-apps/api/shell"; import { exists, promiseFind } from "../../util"; @@ -10,6 +10,27 @@ const ProcessRegex: Record = { development: /discord-?development$/i, }; +const findAppAsarInDir = async (dir: string): Promise => { + const name = await basename(dir); + if (name === "app.asar") return dir; + const topLevelAsar = await join(dir, "app.asar"); + if (await exists(topLevelAsar)) return topLevelAsar; + const resourcesAsar = await join(dir, "resources", "app.asar"); + if (await exists(resourcesAsar)) return resourcesAsar; + + return null; +}; + +const findPathFromPaths = async (paths: string[]): Promise => { + const discordPath = await promiseFind(paths, async (path) => await exists(path)); + + // TODO: Ask user for path + if (!discordPath) return null; + + const path = await findAppAsarInDir(discordPath); + return path; +}; + export const getAppDir = async (platform: DiscordPlatform): Promise => { const homedir = await homeDir(); const flatpakDir = "/var/lib/flatpak/app/com.discordapp"; @@ -57,18 +78,17 @@ export const getAppDir = async (platform: DiscordPlatform): Promise p[4] && ProcessRegex[platform].test(p[4]) && p.includes("--type=renderer")); if (!discordProcess) { - const discordPath = await promiseFind( - KnownLinuxPaths[platform], - async (path) => await exists(path), - ); - - // TODO: Ask user for path - if (!discordPath) return null; - - return await join(discordPath, "resources", "app.asar"); + const paths = KnownLinuxPaths[platform]; + return await findPathFromPaths(paths); } const discordPath = discordProcess[4].split("/"); discordPath.splice(discordPath.length - 1, 1); - return await join("/", ...discordPath, "resources", "app.asar"); + const path = await findAppAsarInDir(await join(...discordPath)); + if (!path) { + const paths = KnownLinuxPaths[platform]; + return await findPathFromPaths(paths); + } + + return path; };