2018-01-17 14:46:27 +01:00
|
|
|
const { remote, ipcRenderer } = require('electron');
|
2018-01-21 04:48:48 +01:00
|
|
|
const { BDIpc } = require('../frontend/main.js');
|
2018-01-17 14:46:27 +01:00
|
|
|
|
|
|
|
//Options
|
|
|
|
const options = {
|
2018-01-21 04:48:48 +01:00
|
|
|
alwaysOnTop: false,
|
|
|
|
liveUpdate: false
|
2018-01-17 14:46:27 +01:00
|
|
|
};
|
|
|
|
|
2018-01-21 04:48:48 +01:00
|
|
|
function sendToDiscord(channel, message) {
|
|
|
|
BDIpc.send('bd-sendToDiscord', {channel, message});
|
|
|
|
}
|
|
|
|
|
2018-01-17 14:46:27 +01:00
|
|
|
//Elements
|
|
|
|
const
|
|
|
|
$spinner = $('#spinner'),
|
|
|
|
$toggleaot = $('#toggleaot'),
|
|
|
|
$closeeditor = $('#closeeditor'),
|
|
|
|
$editor = $('#editor'),
|
|
|
|
$btnSave = $('#btnSave'),
|
2018-01-21 04:48:48 +01:00
|
|
|
$btnUpdate = $('#btnUpdate'),
|
|
|
|
$chkboxLiveUpdate = $("#chkboxLiveUpdate input");
|
2018-01-17 14:46:27 +01:00
|
|
|
|
2018-01-21 04:48:48 +01:00
|
|
|
$toggleaot.on('click', e => {
|
|
|
|
$toggleaot.toggleClass("active");
|
|
|
|
remote.getCurrentWindow().setAlwaysOnTop(options.alwaysOnTop = !options.alwaysOnTop);
|
|
|
|
});
|
2018-01-17 15:39:39 +01:00
|
|
|
$closeeditor.on('click', e => window.close());
|
|
|
|
|
2018-01-21 04:48:48 +01:00
|
|
|
$btnSave.on('click', () => sendToDiscord("save-css", codeMirror.getValue()));
|
|
|
|
$btnUpdate.on('click', () => sendToDiscord("update-css", codeMirror.getValue()));
|
2018-01-22 01:02:19 +01:00
|
|
|
$chkboxLiveUpdate.on('change', () => options.liveUpdate = $chkboxLiveUpdate[0].checked);
|
2018-01-21 04:48:48 +01:00
|
|
|
|
|
|
|
BDIpc.on("set-css", (_, data) => {
|
2018-01-17 14:46:27 +01:00
|
|
|
if (data.error) {
|
|
|
|
alert(data.error);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-22 01:02:19 +01:00
|
|
|
|
2018-01-21 04:48:48 +01:00
|
|
|
setCss(data.css);
|
2018-01-17 14:46:27 +01:00
|
|
|
$spinner.hide();
|
|
|
|
});
|
|
|
|
|
2018-01-21 04:48:48 +01:00
|
|
|
function setCss(css) {
|
|
|
|
codeMirror.setValue(css);
|
|
|
|
}
|
2018-01-17 14:46:27 +01:00
|
|
|
|
|
|
|
function alert(message) {}
|
|
|
|
|
|
|
|
const codeMirror = CodeMirror($editor[0], {
|
|
|
|
lineNumbers: true,
|
|
|
|
mode: 'css',
|
|
|
|
indentUnit: 4,
|
|
|
|
theme: 'material',
|
|
|
|
scrollbarStyle: 'overlay',
|
|
|
|
extraKeys: { 'Ctrl-Space': 'autocomplete' },
|
|
|
|
dialog: { 'position': 'bottom' }
|
|
|
|
});
|
|
|
|
|
2018-01-21 04:48:48 +01:00
|
|
|
codeMirror.on('change', () => {
|
2018-01-22 01:02:19 +01:00
|
|
|
if (options.liveUpdate)
|
2018-01-21 04:48:48 +01:00
|
|
|
sendToDiscord("update-css", codeMirror.getValue());
|
|
|
|
});
|
|
|
|
|
2018-01-17 14:46:27 +01:00
|
|
|
codeMirror.on('keyup', function (editor, event) {
|
|
|
|
if (window.controlDown) return;
|
|
|
|
if (ExcludedIntelliSenseTriggerKeys[event.keyCode]) return;
|
|
|
|
CodeMirror.commands.autocomplete(editor, null, { completeSingle: false });
|
|
|
|
});
|
|
|
|
|
|
|
|
const ExcludedIntelliSenseTriggerKeys = {
|
|
|
|
'8': 'backspace',
|
|
|
|
'9': 'tab',
|
|
|
|
'13': 'enter',
|
|
|
|
'16': 'shift',
|
|
|
|
'17': 'ctrl',
|
|
|
|
'18': 'alt',
|
|
|
|
'19': 'pause',
|
|
|
|
'20': 'capslock',
|
|
|
|
'27': 'escape',
|
|
|
|
'33': 'pageup',
|
|
|
|
'34': 'pagedown',
|
|
|
|
'35': 'end',
|
|
|
|
'36': 'home',
|
|
|
|
'37': 'left',
|
|
|
|
'38': 'up',
|
|
|
|
'39': 'right',
|
|
|
|
'40': 'down',
|
|
|
|
'45': 'insert',
|
|
|
|
'46': 'delete',
|
|
|
|
'91': 'left window key',
|
|
|
|
'92': 'right window key',
|
|
|
|
'93': 'select',
|
|
|
|
'107': 'add',
|
|
|
|
'109': 'subtract',
|
|
|
|
'110': 'decimal point',
|
|
|
|
'111': 'divide',
|
|
|
|
'112': 'f1',
|
|
|
|
'113': 'f2',
|
|
|
|
'114': 'f3',
|
|
|
|
'115': 'f4',
|
|
|
|
'116': 'f5',
|
|
|
|
'117': 'f6',
|
|
|
|
'118': 'f7',
|
|
|
|
'119': 'f8',
|
|
|
|
'120': 'f9',
|
|
|
|
'121': 'f10',
|
|
|
|
'122': 'f11',
|
|
|
|
'123': 'f12',
|
|
|
|
'144': 'numlock',
|
|
|
|
'145': 'scrolllock',
|
|
|
|
'186': 'semicolon',
|
|
|
|
'187': 'equalsign',
|
|
|
|
'188': 'comma',
|
|
|
|
'189': 'dash',
|
|
|
|
'190': 'period',
|
|
|
|
'191': 'slash',
|
|
|
|
'192': 'graveaccent',
|
|
|
|
'220': 'backslash',
|
|
|
|
'222': 'quote'
|
2018-01-22 01:02:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
BDIpc.send('bd-get-css');
|