BetterDiscordApp-v2/client/src/modules/editor.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

/**
* 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 Module from './imodule';
2019-02-25 11:41:22 +01:00
import { DOM } from 'ui';
export default new class extends Module {
2019-02-24 18:57:46 +01:00
get name() { return 'Editor' }
get delay() { return false; }
setInitialState(state) {
return {
editorBounds: undefined
};
}
2019-02-25 16:56:56 +01:00
initialize() {
super.initialize();
(async () => {
try {
// TODO this is temporary
const userScss = await this.send('readDataFile', 'user.scss');
const compiled = await this.send('compileSass', { data: userScss });
this.injectStyle('customcss', compiled.css.toString());
} catch (err) {
console.warn('SCSS Compilation error', err);
}
})();
}
2019-02-24 18:57:46 +01:00
events(ipc) {
ipc.on('editor-runScript', (e, script) => {
try {
new Function(script)();
e.reply('ok');
} catch (err) {
e.reply({ err: err.stack || err });
}
});
2019-02-25 11:41:22 +01:00
ipc.on('editor-injectStyle', (e, { id, style }) => {
2019-02-25 16:56:56 +01:00
this.injectStyle(id, style);
2019-02-25 11:41:22 +01:00
e.reply('ok');
});
}
2019-02-25 16:56:56 +01:00
injectStyle(id, style) {
return DOM.injectStyle(style, `userstyle-${id}`);
}
/**
* Show editor, flashes if already visible.
*/
async show() {
2019-02-24 18:57:46 +01:00
await this.send('editor-open', this.state.editorBounds);
}
}