From bba1165c770e552b57a4028b2f3efe400c56ffd4 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Mon, 28 May 2018 01:42:59 +0100 Subject: [PATCH] =?UTF-8?q?Wrap=20Discord=E2=80=99s=20preload=20script=20i?= =?UTF-8?q?nstead=20of=20enabling=20Node=20integration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/index.js | 8 +++++++- client/src/modules/contentmanager.js | 2 +- client/src/modules/extmodule.js | 3 ++- client/src/modules/globals.js | 2 ++ client/src/modules/pluginmanager.js | 3 ++- client/src/structs/settings/types/custom.js | 5 +++-- .../src/ui/components/BdSettingsWrapper.vue | 3 ++- .../ui/components/bd/modals/ErrorModal.vue | 3 +-- .../src/ui/components/bd/setting/Custom.vue | 4 ++-- client/webpack.config.js | 9 +++++---- client/webpack.production.config.js | 9 +++++---- core/src/main.js | 12 +++++------ core/src/modules/utils.js | 6 +++++- core/src/sparkplug.js | 20 +++++++++++++++++++ 14 files changed, 62 insertions(+), 27 deletions(-) diff --git a/client/src/index.js b/client/src/index.js index 079a7e4a..be21a426 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -39,7 +39,13 @@ class BetterDiscord { plugins: PluginManager.localContent, themes: ThemeManager.localContent, - extmodules: ExtModuleManager.localContent + extmodules: ExtModuleManager.localContent, + + __filename, __dirname, + module: Globals.require.cache[__filename], + require: Globals.require, + webpack_require: __webpack_require__, + get discord_require() { return WebpackModules.require } }; const developermode = Settings.getSetting('core', 'advanced', 'developer-mode'); diff --git a/client/src/modules/contentmanager.js b/client/src/modules/contentmanager.js index 2cbdd863..8d98fc87 100644 --- a/client/src/modules/contentmanager.js +++ b/client/src/modules/contentmanager.js @@ -269,7 +269,7 @@ export default class { const index = this.getContentIndex(content); - delete window.require.cache[window.require.resolve(content.paths.mainPath)]; + delete Globals.require.cache[Globals.require.resolve(content.paths.mainPath)]; if (reload) { const newcontent = await this.preloadContent(content.dirName, true, index); diff --git a/client/src/modules/extmodule.js b/client/src/modules/extmodule.js index 4b8fb0db..262fbd84 100644 --- a/client/src/modules/extmodule.js +++ b/client/src/modules/extmodule.js @@ -8,13 +8,14 @@ * LICENSE file in the root directory of this source tree. */ +import Globals from './globals'; import Content from './content'; export default class ExtModule extends Content { constructor(internals) { super(internals); - this.__require = window.require(this.paths.mainPath); + this.__require = Globals.require(this.paths.mainPath); } get type() { return 'module' } diff --git a/client/src/modules/globals.js b/client/src/modules/globals.js index 6b0312f4..bb9147dc 100644 --- a/client/src/modules/globals.js +++ b/client/src/modules/globals.js @@ -17,6 +17,8 @@ export default new class extends Module { constructor(args) { super(args); + + this.require = __non_webpack_require__; } initg() { diff --git a/client/src/modules/pluginmanager.js b/client/src/modules/pluginmanager.js index 4f227840..0dc3cbd2 100644 --- a/client/src/modules/pluginmanager.js +++ b/client/src/modules/pluginmanager.js @@ -12,6 +12,7 @@ import { Events, Permissions } from 'modules'; import { Modals } from 'ui'; import { ErrorEvent } from 'structs'; import { ClientLogger as Logger } from 'common'; +import Globals from './globals'; import ContentManager from './contentmanager'; import ExtModuleManager from './extmodulemanager'; import Plugin from './plugin'; @@ -96,7 +97,7 @@ export default class extends ContentManager { } } - const plugin = window.require(paths.mainPath)(Plugin, new PluginApi(info, paths.contentPath), Vendor, deps); + const plugin = Globals.require(paths.mainPath)(Plugin, new PluginApi(info, paths.contentPath), Vendor, deps); if (!(plugin.prototype instanceof Plugin)) throw {message: `Plugin ${info.name} did not return a class that extends Plugin.`}; diff --git a/client/src/structs/settings/types/custom.js b/client/src/structs/settings/types/custom.js index a44bdb54..31c3effd 100644 --- a/client/src/structs/settings/types/custom.js +++ b/client/src/structs/settings/types/custom.js @@ -8,10 +8,11 @@ * LICENSE file in the root directory of this source tree. */ +import { Globals } from 'modules'; +import path from 'path'; import Setting from './basesetting'; import SettingsCategory from '../settingscategory'; import SettingsScheme from '../settingsscheme'; -import path from 'path'; export default class CustomSetting extends Setting { @@ -68,7 +69,7 @@ export default class CustomSetting extends Setting { * @param {String} classExport The name of a property of the file's exports that will be used (optional) */ setClass(class_file, class_export) { - const component = window.require(path.join(this.path, class_file)); + const component = Globals.require(path.join(this.path, class_file)); const setting_class = class_export ? component[class_export](CustomSetting) : component.default ? component.default(CustomSetting) : component(CustomSetting); if (!(setting_class.prototype instanceof CustomSetting)) diff --git a/client/src/ui/components/BdSettingsWrapper.vue b/client/src/ui/components/BdSettingsWrapper.vue index 1b636769..98b94c10 100644 --- a/client/src/ui/components/BdSettingsWrapper.vue +++ b/client/src/ui/components/BdSettingsWrapper.vue @@ -23,6 +23,7 @@ // Imports import { Events, Settings } from 'modules'; import { Modals } from 'ui'; + import process from 'process'; import BdSettings from './BdSettings.vue'; export default { @@ -33,7 +34,7 @@ active: false, animating: false, timeout: null, - platform: global.process.platform + platform: process.platform }; }, components: { diff --git a/client/src/ui/components/bd/modals/ErrorModal.vue b/client/src/ui/components/bd/modals/ErrorModal.vue index d43a5139..38f59456 100644 --- a/client/src/ui/components/bd/modals/ErrorModal.vue +++ b/client/src/ui/components/bd/modals/ErrorModal.vue @@ -28,11 +28,10 @@