diff --git a/injector/src/index.js b/injector/src/index.js index 025821ae..c881f953 100644 --- a/injector/src/index.js +++ b/injector/src/index.js @@ -1,3 +1,4 @@ +import fs from "fs"; import path from "path"; import {app} from "electron"; import Module from "module"; @@ -37,7 +38,9 @@ Object.defineProperty(global, "appSettings", { // Use Discord's info to run the app if (process.platform == "win32" || process.platform == "darwin") { - const basePath = path.join(app.getAppPath(), "..", "app.asar"); + const appAsar = path.join(app.getAppPath(), "..", "app.asar"); + const discordAsar = path.join(app.getAppPath(), "..", "discord.asar"); + const basePath = fs.existsSync(discordAsar) ? discordAsar : appAsar; const pkg = __non_webpack_require__(path.join(basePath, "package.json")); app.setAppPath(basePath); app.name = pkg.name; diff --git a/preload/src/api/index.js b/preload/src/api/index.js index c5bc23aa..2d097c76 100644 --- a/preload/src/api/index.js +++ b/preload/src/api/index.js @@ -1,37 +1,3 @@ -import fs from "fs"; -import path from "path"; -import Module from "module"; - -// const Module = require("module"); -Module.globalPaths.push(path.resolve(process.env.DISCORD_APP_PATH, "..", "app.asar", "node_modules")); -// module.paths.push(path.resolve(process.env.DISCORD_APP_PATH, "..", "app.asar", "node_modules")); - -Module._load = (load => (req, parent, isMain) => { - if (req.includes("./") || req.includes("..")) return load(req, parent, isMain); - const found = Module.globalPaths.find(m => fs.existsSync(path.resolve(m, req))); - - return found ? load(path.resolve(found, req), parent, isMain) : load(req, parent, isMain); -})(Module._load); - -// const originalLoad = Module.prototype.load; -// Module.prototype.load = function() { -// const returnValue = Reflect.apply(originalLoad, this, arguments); -// console.log(this, arguments, returnValue); -// return returnValue; -// }; - - -// const nodeModulePaths = Module._nodeModulePaths; -// console.log(nodeModulePaths); -// Module._nodeModulePaths = (from) => { -// return nodeModulePaths(from).concat([path.resolve(process.env.DISCORD_APP_PATH, "..", "app.asar", "node_modules")]); -// }; - -// console.log(Module._nodeModulePaths, Module._nodeModulePaths("request")); -// console.dir(Module); -// console.log(Object.keys(Module)); -// console.log(require("request")); - export * as filesystem from "./filesystem"; export {default as https} from "./https"; export * as electron from "./electron";