Add support for react devtools replacement (#1508)
This commit is contained in:
parent
6e93538465
commit
b59e78e0cc
|
@ -121,6 +121,6 @@ export default class BetterDiscord {
|
||||||
|
|
||||||
if (BetterDiscord.getSetting("developer", "reactDevTools")) {
|
if (BetterDiscord.getSetting("developer", "reactDevTools")) {
|
||||||
electron.app.whenReady().then(async ()=>{
|
electron.app.whenReady().then(async ()=>{
|
||||||
await ReactDevTools.install();
|
await ReactDevTools.install(dataPath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,21 @@ import {session} from "electron";
|
||||||
|
|
||||||
export const REACT_DEVTOOLS_ID = "fmkadmapgofadopljbjfkapdkoienihi";
|
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 = "";
|
let extensionPath = "";
|
||||||
// Get path to user data folder
|
// Get path to user data folder
|
||||||
if (process.platform === "win32") extensionPath = path.resolve(process.env.LOCALAPPDATA, "Google/Chrome/User Data");
|
if (process.platform === "win32") extensionPath = path.resolve(process.env.LOCALAPPDATA, "Google/Chrome/User Data");
|
||||||
|
@ -39,8 +53,7 @@ const findExtension = function() {
|
||||||
|
|
||||||
// Get latest version
|
// Get latest version
|
||||||
if (fs.existsSync(extensionPath)) {
|
if (fs.existsSync(extensionPath)) {
|
||||||
const versions = fs.readdirSync(extensionPath);
|
extensionPath = findLatestVersion(extensionPath);
|
||||||
extensionPath = path.resolve(extensionPath, versions[versions.length - 1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isExtensionInstalled = fs.existsSync(extensionPath);
|
const isExtensionInstalled = fs.existsSync(extensionPath);
|
||||||
|
@ -49,8 +62,8 @@ const findExtension = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class ReactDevTools {
|
export default class ReactDevTools {
|
||||||
static async install() {
|
static async install(dataPath) {
|
||||||
const extPath = findExtension();
|
const extPath = findExtension(dataPath);
|
||||||
if (!extPath) return; // TODO: cut a log
|
if (!extPath) return; // TODO: cut a log
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -62,8 +75,8 @@ export default class ReactDevTools {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async remove() {
|
static async remove(dataPath) {
|
||||||
const extPath = findExtension();
|
const extPath = findExtension(dataPath);
|
||||||
if (!extPath) return; // TODO: cut a log
|
if (!extPath) return; // TODO: cut a log
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue