Skip to content

Commit

Permalink
Fixes for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
asportnoy committed Aug 17, 2023
1 parent 825341c commit aea5588
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
29 changes: 29 additions & 0 deletions src/inject/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ const moveToOrig = async (appDir: string): Promise<void> => {
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<string> => await join(await configDir(), "replugged");
Expand Down Expand Up @@ -127,5 +141,20 @@ export const uninject = async (appDir: string): Promise<void> => {
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!");
};
42 changes: 31 additions & 11 deletions src/inject/platforms/linux.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -10,6 +10,27 @@ const ProcessRegex: Record<DiscordPlatform, RegExp> = {
development: /discord-?development$/i,
};

const findAppAsarInDir = async (dir: string): Promise<string | null> => {
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<string | null> => {
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<string | null> => {
const homedir = await homeDir();
const flatpakDir = "/var/lib/flatpak/app/com.discordapp";
Expand Down Expand Up @@ -57,18 +78,17 @@ export const getAppDir = async (platform: DiscordPlatform): Promise<string | nul
.find((p) => 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;
};

0 comments on commit aea5588

Please sign in to comment.