Smol things

This commit is contained in:
Jiiks 2019-02-24 19:57:46 +02:00
parent d1fd5ae881
commit da1fc0a2f0
3 changed files with 39 additions and 9 deletions

View File

@ -8,19 +8,21 @@
* 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 {
get name() { return 'Editor' }
get delay() { return false; }
setInitialState(state) {
return {
editorBounds: undefined
};
}
events() {
ClientIPC.on('editor-runScript', (e, script) => {
events(ipc) {
ipc.on('editor-runScript', (e, script) => {
try {
new Function(script)();
e.reply('ok');
@ -34,7 +36,7 @@ export default new class extends Module {
* Show editor, flashes if already visible.
*/
async show() {
await ClientIPC.send('editor-open', this.state.editorBounds);
await this.send('editor-open', this.state.editorBounds);
}
}

View File

@ -11,6 +11,9 @@
/**
* Base Module that every non-static module should extend
*/
import { ClientLogger as Logger, ClientIPC } from 'common';
export default class Module {
constructor(args) {
@ -19,14 +22,20 @@ export default class Module {
args
};
this.setState = this.setState.bind(this);
this.initialize();
if (this.delay) { // If delay is set then module is set to load delayed from modulemanager
this.initialize = this.initialize.bind(this);
this.init = this.initialize;
} else {
this.initialize();
this.init = () => { };
}
}
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();
if (this.events) this.events(ClientIPC);
}
setState(newState) {
@ -41,4 +50,24 @@ export default class Module {
set state(state) { return this.__.state = state; }
get state() { return this.__.state; }
async send(channel, message) {
return ClientIPC.send(channel, message);
}
log(msg) {
Logger.log(this.name, msg);
}
warn(msg) {
Logger.log(this.name, msg);
}
err(msg) {
Logger.log(this.name, msg);
}
info(msg) {
Logger.log(this.name, msg);
}
}

View File

@ -9,7 +9,7 @@
*/
import { ClientLogger as Logger } from 'common';
import { SocketProxy, EventHook, CssEditor } from 'modules';
import { SocketProxy, EventHook } from 'modules';
import { ProfileBadges, ClassNormaliser } from 'ui';
import Updater from './updater';
@ -27,7 +27,6 @@ export default class {
new ClassNormaliser(),
new SocketProxy(),
new EventHook(),
CssEditor,
Updater
]);
}