Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for React Developer Tools replacement #1508

Merged
merged 2 commits into from Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion injector/src/modules/betterdiscord.js
Expand Up @@ -121,6 +121,6 @@ export default class BetterDiscord {

if (BetterDiscord.getSetting("developer", "reactDevTools")) {
electron.app.whenReady().then(async ()=>{
await ReactDevTools.install();
await ReactDevTools.install(dataPath);
});
}
27 changes: 20 additions & 7 deletions injector/src/modules/reactdevtools.js
Expand Up @@ -4,7 +4,21 @@ import {session} from "electron";

export const REACT_DEVTOOLS_ID = "fmkadmapgofadopljbjfkapdkoienihi";

const findExtension = function() {
const findLatestVersion = (extensionPath) => {
const versions = fs.readdirSync(extensionPath);
return path.resolve(extensionPath, versions[versions.length - 1]);
};

const findExtension = (dataPath) => {
// Default to extensions folder in BetterDiscord folder
const replacementPath = path.resolve(dataPath, "extensions", REACT_DEVTOOLS_ID);
if (fs.existsSync(replacementPath)) {
if (fs.existsSync(path.resolve(replacementPath, "manifest.json"))) {
return replacementPath;
}
return findLatestVersion(replacementPath);
}

let extensionPath = "";
// Get path to user data folder
if (process.platform === "win32") extensionPath = path.resolve(process.env.LOCALAPPDATA, "Google/Chrome/User Data");
Expand Down Expand Up @@ -39,8 +53,7 @@ const findExtension = function() {

// Get latest version
if (fs.existsSync(extensionPath)) {
const versions = fs.readdirSync(extensionPath);
extensionPath = path.resolve(extensionPath, versions[versions.length - 1]);
extensionPath = findLatestVersion(extensionPath);
}

const isExtensionInstalled = fs.existsSync(extensionPath);
Expand All @@ -49,8 +62,8 @@ const findExtension = function() {
};

export default class ReactDevTools {
static async install() {
const extPath = findExtension();
static async install(dataPath) {
const extPath = findExtension(dataPath);
if (!extPath) return; // TODO: cut a log

try {
Expand All @@ -62,8 +75,8 @@ export default class ReactDevTools {
}
}

static async remove() {
const extPath = findExtension();
static async remove(dataPath) {
const extPath = findExtension(dataPath);
if (!extPath) return; // TODO: cut a log

try {
Expand Down