diff --git a/client/src/index.js b/client/src/index.js index c64134a0..5d2e315d 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -10,7 +10,7 @@ import { DOM, BdUI, BdMenu, Modals, Toasts, Notifications, BdContextMenu, DiscordContextMenu } from 'ui'; import BdCss from './styles/index.scss'; -import { Events, CssEditor, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, BdWebApi, Connectivity, Cache, Reflection, PackageInstaller } from 'modules'; +import { Events, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, BdWebApi, Connectivity, Cache, Reflection, PackageInstaller } from 'modules'; import { ClientLogger as Logger, ClientIPC, Utils } from 'common'; import { BuiltinManager, EmoteModule, ReactDevtoolsModule, VueDevtoolsModule, TrackingProtection, E2EE } from 'builtin'; import electron from 'electron'; @@ -30,7 +30,7 @@ class BetterDiscord { this._bd = { DOM, BdUI, BdMenu, Modals, Reflection, Toasts, Notifications, BdContextMenu, DiscordContextMenu, - Events, CssEditor, Globals, Settings, Database, Updater, + Events, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, PackageInstaller, Vendor, diff --git a/client/src/modules/csseditor.js b/client/src/modules/csseditor.js index 487c1516..873a4943 100644 --- a/client/src/modules/csseditor.js +++ b/client/src/modules/csseditor.js @@ -38,7 +38,7 @@ export default new class { ClientIPC.on('bd-get-scss', () => this.scss, true); ClientIPC.on('bd-update-scss', (e, scss) => this.updateScss(scss)); ClientIPC.on('bd-save-csseditor-bounds', (e, bounds) => this.saveEditorBounds(bounds)); - ClientIPC.on('bd-runEditorScript', (e, script) => { + ClientIPC.on('bd-editor-runScript', (e, script) => { try { new Function(script)(); e.reply('ok'); diff --git a/client/src/modules/editor.js b/client/src/modules/editor.js new file mode 100644 index 00000000..b4cea53e --- /dev/null +++ b/client/src/modules/editor.js @@ -0,0 +1,40 @@ +/** + * BetterDiscord Editor Module + * Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks + * All rights reserved. + * https://betterdiscord.net + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. +*/ + +import { FileUtils, ClientLogger as Logger, ClientIPC } from 'common'; +import Module from './imodule'; + +export default new class extends Module { + + setInitialState(state) { + return { + editorBounds: undefined + }; + } + + events() { + ClientIPC.on('editor-runScript', (e, script) => { + try { + new Function(script)(); + e.reply('ok'); + } catch (err) { + e.reply({ err: err.stack || err }); + } + }); + } + + /** + * Show editor, flashes if already visible. + */ + async show() { + await ClientIPC.send('editor-open', this.state.editorBounds); + } + +} diff --git a/client/src/modules/imodule.js b/client/src/modules/imodule.js new file mode 100644 index 00000000..0afbad3c --- /dev/null +++ b/client/src/modules/imodule.js @@ -0,0 +1,44 @@ +/** + * BetterDiscord Module Base + * Copyright (c) 2015-present JsSucks - https://github.com/JsSucks + * All rights reserved. + * https://github.com/JsSucks - https://betterdiscord.net + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. +*/ + +/** + * Base Module that every non-static module should extend + */ +export default class Module { + + constructor(args) { + this.__ = { + state: args || {}, + args + }; + this.setState = this.setState.bind(this); + this.initialize(); + } + + initialize() { + if (this.bindings) this.bindings(); + if (this.setInitialState) this.setState(this.setInitialState(this.state)); + if (this.events) this.events(); + if (this.init) this.init(); + } + + setState(newState) { + const oldState = this.state; + Object.assign(this.state, newState); + if (this.stateChanged) this.stateChanged(oldState, newState); + } + + set args(t) { } + get args() { return this.__.args; } + + set state(state) { return this.__.state = state; } + get state() { return this.__.state; } + +} diff --git a/client/src/modules/modules.js b/client/src/modules/modules.js index 239e89f8..437f54fc 100644 --- a/client/src/modules/modules.js +++ b/client/src/modules/modules.js @@ -1,5 +1,6 @@ export { default as Events } from './events'; export { default as CssEditor } from './csseditor'; +export { default as Editor } from './editor'; export { default as Globals } from './globals'; export { default as Settings } from './settings'; export { default as Database } from './database'; diff --git a/client/src/ui/components/bd/CssEditor.vue b/client/src/ui/components/bd/CssEditor.vue index 18a39f57..a5639641 100644 --- a/client/src/ui/components/bd/CssEditor.vue +++ b/client/src/ui/components/bd/CssEditor.vue @@ -8,6 +8,8 @@ * LICENSE file in the root directory of this source tree. */ +// TODO this should be remade as editor instead of css editor +