Initial BDEdit addition. No logic yet.

This commit is contained in:
Jiiks 2019-02-24 13:03:15 +02:00
parent 99ef0d9f81
commit f1f23fa220
9 changed files with 216 additions and 8 deletions

View File

@ -21,7 +21,8 @@ const TEST_ARGS = () => {
'paths': {
'client': path.resolve(_basePath, 'client', 'dist'),
'core': path.resolve(_basePath, 'core', 'dist'),
'data': path.resolve(_baseDataPath, 'data')
'data': path.resolve(_baseDataPath, 'data'),
'editor': path.resolve(_basePath, 'editor', 'dist')
}
}
}
@ -33,7 +34,7 @@ import deepmerge from 'deepmerge';
import ContentSecurityPolicy from 'csp-parse';
import keytar from 'keytar';
import { FileUtils, BDIpc, Config, WindowUtils, CSSEditor, Database } from './modules';
import { FileUtils, BDIpc, Config, WindowUtils, CSSEditor, Editor, Database } from './modules';
const packageJson = require(path.resolve(__dirname, 'package.json'));
const sparkplug = path.resolve(__dirname, 'sparkplug.js');
@ -63,7 +64,8 @@ class Comms {
BDIpc.on('bd-sendToDiscord', (event, m) => this.sendToDiscord(m.channel, m.message), true);
// 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-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-native-open', (event, options) => {
dialog.showOpenDialog(OriginalBrowserWindow.fromWebContents(event.ipcEvent.sender), options, filenames => {
@ -148,7 +150,8 @@ export class BetterDiscord {
get comms() { return this._comms ? this._comms : (this._commas = new Comms(this)); }
get database() { return this._db ? this._db : (this._db = new Database(this.config.getPath('data'))); }
get config() { return this._config ? this._config : (this._config = new Config(this._args)); }
get window() { return this.windowUtils ? this.windowUtils.window : undefined; }
get window() { return this.windowUtils ? this.windowUtils.window : undefined; }
get editor() { return this._editor ? this._editor : (this._editor = new Editor(this, this.config.getPath('editor'))); }
constructor(args) {
if (TESTS) args = TEST_ARGS();

View File

@ -0,0 +1,93 @@
/**
* BetterDiscord Editor Module
* 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.
*/
import path from 'path';
import { BrowserWindow } from 'electron';
import Module from './modulebase';
import { WindowUtils } from './utils';
import BDIpc from './bdipc';
export default class Editor extends Module {
constructor(bd, path) {
super();
this.editorPath = path;
this.bd = bd;
}
/**
* Opens an editor.
* @return {Promise}
*/
openEditor(options) {
return new Promise((resolve, reject) => {
if (this.editor) {
if (this.editor.isFocused()) return;
this.editor.focus();
this.editor.flashFrame(true);
return resolve(true);
}
options = Object.assign({}, this.options, options);
this.editor = new BrowserWindow(options);
this.editor.loadURL('about:blank');
this.editor.setSheetOffset(33);
this.editorUtils = new WindowUtils({ window: this.editor });
this.editor.on('close', () => {
this.bd.windowUtils.send('bd-save-csseditor-bounds', this.editor.getBounds());
this.editor = null;
});
this.editor.once('ready-to-show', () => {
this.editor.show();
});
this.editor.webContents.on('did-finish-load', () => {
this.editorUtils.injectScript(path.join(this.editorPath, 'editor.js'));
resolve(true);
});
})
}
/**
* Sends data to the editor.
* @param {String} channel
* @param {Any} data
*/
send(channel, data) {
if (!this.editor) throw { message: 'The CSS editor is not open.' };
return BDIpc.send(this.editor, channel, data);
}
/**
* Sets the CSS editor's always on top flag.
*/
set alwaysOnTop(state) {
if (!this.editor) return;
this.editor.setAlwaysOnTop(state);
}
/**
* Default options to pass to BrowserWindow.
*/
get options() {
return {
width: 800,
height: 600,
show: false,
frame: false
};
}
}

View File

@ -2,4 +2,5 @@ export { default as BDIpc } from './bdipc';
export { Utils, FileUtils, WindowUtils } from './utils';
export { default as Config } from './config';
export { default as CSSEditor } from './csseditor';
export { default as Editor } from './editor';
export { default as Database } from './database';

View File

@ -1,12 +1,30 @@
<template>
<div class="container"></div>
<div class="container">
<div class="titlebar">
<div class="draggable"></div>
<div class="icon">
<div class="inner"></div>
</div>
<div class="title">Content Editor</div>
<div class="flex-spacer"></div>
<div class="controls">
<button :class="{active: alwaysOnTop}" ref="aot" title="Toggle always on top" @click="toggleaot">P</button>
<button title="Close CSS Editor" @click="close">X</button>
</div>
</div>
<BDEdit />
</div>
</template>
<script>
import { BDEdit } from 'bdedit';
ace.acequire = ace.require;
export default {
components: { BDEdit }
components: { BDEdit },
mounted() {
console.log(ace);
}
}
</script>

View File

@ -0,0 +1,20 @@
@import './vars.scss';
@import './titlebar.scss';
html, body {
margin: 0;
padding: 0;
display: flex;
max-height: 100%;
height: 100%;
width: 100%;
background: #2c383e;
min-width: 700px;
min-height: 400px;
}
.container {
display: flex;
flex-grow: 1;
flex-direction: column;
}

View File

@ -0,0 +1,71 @@
.titlebar {
display: flex;
height: 25px;
padding: 4px 5px;
background: #292b2f;
border-bottom: 1px solid hsla(218,5%,47%,.3);
user-select: none;
cursor: default;
.icon {
width: 31px;
height: 25px;
.inner {
width: 25px;
height: 25px;
background-image: $bdicon;
background-size: 22px 22px;
background-repeat: no-repeat;
background-position: center;
}
}
.title {
color: #bac9d2;
font-family: Whitney,Helvetica Neue,Helvetica,Arial,sans-serif;
line-height: 25px;
font-size: 15px;
}
.controls {
margin: 0 0 0 2px;
font-size: 0;
button {
-webkit-app-region: no-drag;
border-radius: 3px;
width: 25px;
font-size: 12px;
font-weight: 600;
background: #36393f;
color: #bac9d2;
font-family: Whitney,Helvetica Neue,Helvetica,Arial,sans-serif;
transition: background-color .2s ease, color .2s ease;
cursor: default;
border: 0;
height: 25px;
z-index: 900062;
padding: 0;
margin: 0 0 0 4px;
&:hover {
background: #44474e;
color: #FFF;
}
&.active {
background: #3a71c1;
}
}
}
.draggable {
top: 0;
left: 0;
right: 63px;
position: absolute;
height: 33px;
-webkit-app-region: drag;
}
}

View File

@ -0,0 +1,2 @@
$logoSmallGw: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNv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xMy43LTI3LjMsMjcuM3Y0Ny4zQzMyOS4zLDc2LjIsMjkzLjksNjYuMywyNTYsNjYuM2MtMjkuOCwwLTU3LjksNi4zLTgzLjYsMTcuM3YxMzQuMmMxOS0yNS42LDQ5LjMtNDIuMiw4My42LTQyLjJjNTcuNiwwLDEwNC4xLDQ2LjUsMTA0LjEsMTA0LjF2MTg2LjJjNjUuMi0zNi40LDEwOS4yLTEwNiwxMDkuMi0xODYuMlY0Ni4xYzAtMTguOC0xMy43LTI3LjMtMjcuMy0yNy4zSDM4Ny40eiIvPjwvZz48L3N2Zz4=);
$bdicon: $logoSmallGw;

2
package-lock.json generated
View File

@ -1588,7 +1588,7 @@
}
},
"bdedit": {
"version": "github:JsSucks/BDEdit#1ddc18aa4ae980cd0d50618ba4ffa73721a6819e",
"version": "github:JsSucks/bdedit#1ddc18aa4ae980cd0d50618ba4ffa73721a6819e",
"dev": true,
"requires": {
"ace-builds": "1.4.3"

View File

@ -18,6 +18,7 @@
"dependencies": {
"asar": "^0.14.6",
"csp-parse": "github:macropodhq/csp-parse",
"bdedit": "github:JsSucks/bdedit",
"deepmerge": "^2.2.1",
"fs-extra": "^7.0.0",
"keytar": "^4.3.0",
@ -33,7 +34,6 @@
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"bdedit": "github:JsSucks/BDEdit",
"codemirror": "^5.39.2",
"combokeys": "^3.0.0",
"css-loader": "^0.28.11",