From 1a26e77dd9de056582cee5c95a876d6fd06c9638 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Sun, 24 Feb 2019 21:24:37 +0200 Subject: [PATCH] Move editor events to editor --- client/src/index.js | 2 +- core/src/main.js | 35 +---------------------------------- core/src/modules/editor.js | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/client/src/index.js b/client/src/index.js index 5d2e315d..de27de87 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -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 { diff --git a/core/src/main.js b/core/src/main.js index 1b07067f..a9f2c642 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -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(); } diff --git a/core/src/modules/editor.js b/core/src/modules/editor.js index 0f4b46e7..5f4737b8 100644 --- a/core/src/modules/editor.js +++ b/core/src/modules/editor.js @@ -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. */