Move editor events to editor

This commit is contained in:
Jiiks 2019-02-24 21:24:37 +02:00
parent da1fc0a2f0
commit 1a26e77dd9
3 changed files with 39 additions and 35 deletions

View File

@ -18,7 +18,7 @@ import path from 'path';
import { setTimeout } from 'timers';
const tests = typeof PRODUCTION === 'undefined';
const ignoreExternal = false;
const ignoreExternal = true;
class BetterDiscord {

View File

@ -58,8 +58,6 @@ class Comms {
}
initListeners() {
this.editorListeners();
BDIpc.on('ping', () => 'pong', true);
BDIpc.on('bd-getConfig', () => this.bd.config.config, true);
@ -96,38 +94,6 @@ class Comms {
BDIpc.on('bd-keytar-find-credentials', (event, { service }) => keytar.findCredentials(service), true);
}
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-editor-runScript', script);
event.reply(result);
});
BDIpc.on('bd-editor-getFiles', async (event) => {
event.reply([
{ type: 'file', name: 'custom.scss', content: '', savedContent: '', mode: 'scss', saved: true }
]);
});
BDIpc.on('bd-editor-getSnippets', async (event) => {
event.reply([
{ type: 'snippet', name: 'test.js', content: '', savedContent: '', mode: 'javascript', saved: true }
]);
});
BDIpc.on('bd-editor-saveFile', async (event, file) => {
console.log(file);
event.reply('ok');
});
BDIpc.on('bd-editor-saveSnippet', async (event, snippet) => {
console.log(snippet);
event.reply('ok');
});
}
async send(channel, message) {
BDIpc.send(channel, message);
}
@ -207,6 +173,7 @@ export class BetterDiscord {
configProxy = () => this.config;
const autoInitComms = this.comms;
const autoInitEditor = this.editor;
this.init();
}

View File

@ -21,6 +21,39 @@ export default class Editor extends Module {
super();
this.editorPath = path;
this.bd = bd;
this.initListeners();
}
initListeners() {
BDIpc.on('bd-openCssEditor', (event, options) => this.openEditor(options), true);
BDIpc.on('bd-editor-open', (event, options) => this.openEditor(options), true);
BDIpc.on('bd-editor-runScript', async (event, script) => {
const result = await this.sendToDiscord('bd-editor-runScript', script);
event.reply(result);
});
BDIpc.on('bd-editor-getFiles', async (event) => {
event.reply([
{ type: 'file', name: 'custom.scss', content: '', savedContent: '', mode: 'scss', saved: true }
]);
});
BDIpc.on('bd-editor-getSnippets', async (event) => {
event.reply([
{ type: 'snippet', name: 'test.js', content: '', savedContent: '', mode: 'javascript', saved: true }
]);
});
BDIpc.on('bd-editor-saveFile', async (event, file) => {
console.log(file);
event.reply('ok');
});
BDIpc.on('bd-editor-saveSnippet', async (event, snippet) => {
console.log(snippet);
event.reply('ok');
});
}
/**
@ -70,6 +103,10 @@ export default class Editor extends Module {
return BDIpc.send(this.editor, channel, data);
}
async sendToDiscord(channel, message) {
return this.bd.windowUtils.send(channel, message);
}
/**
* Sets the CSS editor's always on top flag.
*/