Skip to content

Commit

Permalink
Specify path for install/uninstall (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKodeToad committed Sep 21, 2023
1 parent 469b4df commit a7c9cf5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ $ pnpm i
$ pnpm build
```

Inject into discord
Inject into Discord
```bash
$ pnpm inject <channel>
$ pnpm inject <channel or path>
```

Tada! 🎉
Expand Down
4 changes: 3 additions & 1 deletion scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import path from "node:path";
import fs from "node:fs";
import os from "node:os";

export const channels = ["stable", "canary", "ptb"];

export const known = {
darwin: {
stable: ["/Applications/Discord.app/Contents/Resources/"],
Expand Down Expand Up @@ -65,7 +67,7 @@ export const getAppPath = async (channel) => {
const appPaths = known[process.platform]?.[channel] ?? [];

for (const appPath of appPaths) {
if (fs.existsSync(appPath)) {
if (fs.statSync(appPath).isDirectory()) {
let p = appPath;

if (process.platform === "win32") {
Expand Down
12 changes: 9 additions & 3 deletions scripts/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ import process from "node:process";
import path from "node:path";
import fs from "node:fs";

import { banner, getAppPath } from "./common.js";
import { banner, channels, getAppPath } from "./common.js";
import { uninject } from "./uninject.js";

const safify = (str) => str.replace(/\\/g, "\\\\").replace("\\C:", "C:");

const channel = process.argv[2] ?? "stable";
let channel = "<unknown>";
let customPath = null;
if (channels.includes(process.argv[2])) {
channel = process.argv[2];
} else {
customPath = process.argv[2];
}

const inject = async () => {
const appPath = await getAppPath(channel);
const appPath = customPath ?? await getAppPath(channel);

console.log("");

Expand Down
12 changes: 9 additions & 3 deletions scripts/uninject.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ import process from "node:process";
import path from "node:path";
import fs from "node:fs";

import { banner, getAppPath } from "./common.js";
import { banner, channels, getAppPath } from "./common.js";

const channel = process.argv[2] ?? "stable";
let channel = "<unknown>";
let customPath = null;
if (channels.includes(process.argv[2])) {
channel = process.argv[2];
} else {
customPath = process.argv[2];
}

export const uninject = async () => {
const appPath = await getAppPath(channel);
const appPath = customPath ?? await getAppPath(channel);

console.log("");

Expand Down

0 comments on commit a7c9cf5

Please sign in to comment.