imodule and base for new editor module in client
This commit is contained in:
parent
8c04e7d2d3
commit
d1fd5ae881
client/src
core/src
|
@ -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,
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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; }
|
||||
|
||||
}
|
|
@ -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';
|
||||
|
|
|
@ -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
|
||||
|
||||
<template>
|
||||
<SettingsWrapper headertext="CSS Editor">
|
||||
<div class="bd-cssEditor">
|
||||
|
@ -49,7 +51,7 @@
|
|||
|
||||
<script>
|
||||
// Imports
|
||||
import { Settings, CssEditor } from 'modules';
|
||||
import { Settings, Editor } from 'modules';
|
||||
import { SettingsWrapper } from './';
|
||||
import { FormButton } from '../common';
|
||||
import SettingsPanel from './SettingsPanel.vue';
|
||||
|
@ -64,18 +66,18 @@
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
CssEditor
|
||||
Editor
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
error() {
|
||||
return this.CssEditor.error;
|
||||
return this.Editor.error;
|
||||
},
|
||||
compiling() {
|
||||
return this.CssEditor.compiling;
|
||||
return this.Editor.compiling;
|
||||
},
|
||||
systemEditorPath() {
|
||||
return this.CssEditor.filePath;
|
||||
return this.Editor.filePath;
|
||||
},
|
||||
liveUpdateSetting() {
|
||||
return Settings.getSetting('css', 'default', 'live-update');
|
||||
|
@ -92,13 +94,13 @@
|
|||
},
|
||||
methods: {
|
||||
openInternalEditor() {
|
||||
this.CssEditor.show();
|
||||
this.Editor.show();
|
||||
},
|
||||
openSystemEditor() {
|
||||
this.CssEditor.openSystemEditor();
|
||||
// this.Editor.openSystemEditor();
|
||||
},
|
||||
recompile() {
|
||||
this.CssEditor.recompile();
|
||||
// this.Editor.recompile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ class Comms {
|
|||
|
||||
// BDIpc.on('bd-openCssEditor', (event, options) => this.bd.csseditor.openEditor(options), true);
|
||||
// BDIpc.on('bd-sendToCssEditor', (event, m) => this.sendToCssEditor(m.channel, m.message), true);
|
||||
BDIpc.on('bd-openCssEditor', (event, options) => this.bd.editor.openEditor(options), true);
|
||||
// BDIpc.on('bd-openCssEditor', (event, options) => this.bd.editor.openEditor(options), true);
|
||||
|
||||
BDIpc.on('bd-native-open', (event, options) => {
|
||||
dialog.showOpenDialog(OriginalBrowserWindow.fromWebContents(event.ipcEvent.sender), options, filenames => {
|
||||
|
@ -97,8 +97,11 @@ class Comms {
|
|||
}
|
||||
|
||||
editorListeners() {
|
||||
BDIpc.on('bd-openCssEditor', (event, options) => this.bd.editor.openEditor(options), true);
|
||||
BDIpc.on('bd-editor-open', (event, options) => this.bd.editor.openEditor(options), true);
|
||||
|
||||
BDIpc.on('bd-editor-runScript', async (event, script) => {
|
||||
const result = await this.sendToDiscord('bd-runEditorScript', script);
|
||||
const result = await this.sendToDiscord('bd-editor-runScript', script);
|
||||
event.reply(result);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue