parent
0eea6d8d17
commit
f35b82c69e
|
@ -10,11 +10,12 @@ const releaseInput = useBdRelease ? args[3] && args[3].toLowerCase() : args[2] &
|
||||||
const release = releaseInput === "canary" ? "Discord Canary" : releaseInput === "ptb" ? "Discord PTB" : "Discord";
|
const release = releaseInput === "canary" ? "Discord Canary" : releaseInput === "ptb" ? "Discord PTB" : "Discord";
|
||||||
const bdPath = useBdRelease ? path.resolve(__dirname, "..", "dist", "betterdiscord.asar") : path.resolve(__dirname, "..", "dist");
|
const bdPath = useBdRelease ? path.resolve(__dirname, "..", "dist", "betterdiscord.asar") : path.resolve(__dirname, "..", "dist");
|
||||||
const discordPath = (function() {
|
const discordPath = (function() {
|
||||||
|
let resourcePath = "";
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
const basedir = path.join(process.env.LOCALAPPDATA, release.replace(/ /g, ""));
|
const basedir = path.join(process.env.LOCALAPPDATA, release.replace(/ /g, ""));
|
||||||
if (!fs.existsSync(basedir)) throw new Error(`Cannot find directory for ${release}`);
|
if (!fs.existsSync(basedir)) throw new Error(`Cannot find directory for ${release}`);
|
||||||
const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0];
|
const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0];
|
||||||
return path.join(basedir, version, "resources");
|
resourcePath = path.join(basedir, version, "resources");
|
||||||
}
|
}
|
||||||
else if (process.platform === "darwin") {
|
else if (process.platform === "darwin") {
|
||||||
const appPath = releaseInput === "canary" ? path.join("/Applications", "Discord Canary.app")
|
const appPath = releaseInput === "canary" ? path.join("/Applications", "Discord Canary.app")
|
||||||
|
@ -22,11 +23,19 @@ const discordPath = (function() {
|
||||||
: useBdRelease && args[3] ? args[3] ? args[2] : args[2]
|
: useBdRelease && args[3] ? args[3] ? args[2] : args[2]
|
||||||
: path.join("/Applications", "Discord.app");
|
: path.join("/Applications", "Discord.app");
|
||||||
|
|
||||||
return path.join(appPath, "Contents", "Resources");
|
resourcePath = path.join(appPath, "Contents", "Resources");
|
||||||
}
|
}
|
||||||
else if (process.platform === "linux") {
|
else {
|
||||||
return path.join("/usr", "share", release.toLowerCase().replace(/ /g, "-"), "resources");
|
const userData = process.env.XDG_CONFIG_HOME ? process.env.XDG_CONFIG_HOME : path.join(process.env.HOME, ".config");
|
||||||
|
const basedir = path.join(userData, release.toLowerCase().replace(" ", ""));
|
||||||
|
if (!fs.existsSync(basedir)) return "";
|
||||||
|
const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0];
|
||||||
|
if (!version) return "";
|
||||||
|
resourcePath = path.join(basedir, version, "modules", "discord_desktop_core");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fs.existsSync(resourcePath)) return resourcePath;
|
||||||
|
return "";
|
||||||
})();
|
})();
|
||||||
|
|
||||||
doSanityChecks(bdPath);
|
doSanityChecks(bdPath);
|
||||||
|
@ -45,13 +54,19 @@ if (!fs.existsSync(appPath)) fs.mkdirSync(appPath);
|
||||||
if (fs.existsSync(packageJson)) fs.unlinkSync(packageJson);
|
if (fs.existsSync(packageJson)) fs.unlinkSync(packageJson);
|
||||||
if (fs.existsSync(indexJs)) fs.unlinkSync(indexJs);
|
if (fs.existsSync(indexJs)) fs.unlinkSync(indexJs);
|
||||||
|
|
||||||
fs.writeFileSync(packageJson, JSON.stringify({
|
if (process.platform === "win32" || process.platform === "darwin") {
|
||||||
|
fs.writeFileSync(packageJson, JSON.stringify({
|
||||||
name: "betterdiscord",
|
name: "betterdiscord",
|
||||||
main: "index.js",
|
main: "index.js",
|
||||||
}, null, 4));
|
}, null, 4));
|
||||||
console.log(" ✅ Wrote package.json");
|
console.log(" ✅ Wrote package.json");
|
||||||
|
|
||||||
|
fs.writeFileSync(indexJs, `require("${bdPath.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}");`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fs.writeFileSync(indexJs, `require("${bdPath.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}");\nmodule.exports = require("./core.asar");`);
|
||||||
|
}
|
||||||
|
|
||||||
fs.writeFileSync(indexJs, `require("${bdPath.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}");`);
|
|
||||||
console.log(" ✅ Wrote index.js");
|
console.log(" ✅ Wrote index.js");
|
||||||
console.log("");
|
console.log("");
|
||||||
console.log(`Injection successful, please restart ${release}.`);
|
console.log(`Injection successful, please restart ${release}.`);
|
Loading…
Reference in New Issue