From 725c95d6d3e65dd4b576a2a806e19a9182bb94a9 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Mon, 22 Jan 2018 12:16:23 +0200 Subject: [PATCH] Start converting csseditor to another module --- core/src/modules/csseditor.js | 2 + csseditor/package.json | 25 ++ csseditor/src/BDIpc.js | 26 ++ csseditor/src/Editor.vue | 476 ++++++++++++++++++++++++++++++++++ csseditor/src/index.js | 13 + csseditor/webpack.config.js | 29 +++ package.json | 3 +- 7 files changed, 573 insertions(+), 1 deletion(-) create mode 100644 csseditor/package.json create mode 100644 csseditor/src/BDIpc.js create mode 100644 csseditor/src/Editor.vue create mode 100644 csseditor/src/index.js create mode 100644 csseditor/webpack.config.js diff --git a/core/src/modules/csseditor.js b/core/src/modules/csseditor.js index c55fd822..96648ab9 100644 --- a/core/src/modules/csseditor.js +++ b/core/src/modules/csseditor.js @@ -27,6 +27,7 @@ class CSSEditor extends Module { this.editor = new BrowserWindow(this.options); this.editor.loadURL(`file://${this.editorPath}/index.html`); + this.editor.webContents.toggleDevTools(); this.editor.open = true; this.editor.setSheetOffset(33); @@ -58,6 +59,7 @@ class CSSEditor extends Module { //TODO Currently uses a development path get editorPath() { + return path.resolve(__dirname, '..', '..', '..', 'csseditor', 'dist'); return path.resolve(__dirname, '..', '..', '..', 'tests', 'csseditor'); } diff --git a/csseditor/package.json b/csseditor/package.json new file mode 100644 index 00000000..43608e53 --- /dev/null +++ b/csseditor/package.json @@ -0,0 +1,25 @@ +{ + "name": "bdcsseditor", + "description": "BetterDiscord css editor package", + "author": "Jiiks", + "version": "0.4.0", + "homepage": "https://betterdiscord.net", + "license": "MIT", + "main": "index.js", + "contributors": [ + "Jiiks", + "Pohky" + ], + "repository": { + "type": "git", + "url": "https://github.com/Jiiks/BetterDiscordApp.git" + }, + "private": false, + "devDependencies": { + + }, + "scripts": { + "build": "webpack --progress --colors", + "watch": "webpack --progress --colors --watch" + } +} diff --git a/csseditor/src/BDIpc.js b/csseditor/src/BDIpc.js new file mode 100644 index 00000000..36d9a7e5 --- /dev/null +++ b/csseditor/src/BDIpc.js @@ -0,0 +1,26 @@ +const { ipcRenderer } = window.require('electron'); + +class BDIpc { + + static on(channel, cb) { + ipcRenderer.on(channel, (event, args) => cb(event, args)); + } + + static async send(channel, message) { + const __eid = Date.now().toString(); + ipcRenderer.send( + channel.startsWith('bd-') ? channel: `bd-${channel}`, + message === undefined ? { __eid } : Object.assign(message, { __eid }) + ); + + return new Promise((resolve, reject) => { + ipcRenderer.once(__eid, (event, arg) => { + if (arg.err) return reject(arg); + resolve(arg); + }); + }); + } + +} + +module.exports = { BDIpc }; \ No newline at end of file diff --git a/csseditor/src/Editor.vue b/csseditor/src/Editor.vue new file mode 100644 index 00000000..9c120493 --- /dev/null +++ b/csseditor/src/Editor.vue @@ -0,0 +1,476 @@ + + + + + \ No newline at end of file diff --git a/csseditor/src/index.js b/csseditor/src/index.js new file mode 100644 index 00000000..9f5eeee2 --- /dev/null +++ b/csseditor/src/index.js @@ -0,0 +1,13 @@ +import Vue from 'vue'; +import Editor from './Editor.vue'; +import VueCodemirror from 'vue-codemirror' + +Vue.use(VueCodemirror, {}); + +window.cmCommands = VueCodemirror.CodeMirror.commands; + +new Vue({ + el: '#root', + template: '', + components: { Editor } +}); \ No newline at end of file diff --git a/csseditor/webpack.config.js b/csseditor/webpack.config.js new file mode 100644 index 00000000..affb1609 --- /dev/null +++ b/csseditor/webpack.config.js @@ -0,0 +1,29 @@ +const + path = require('path'), + webpack = require('webpack'); +const vueLoader = { + test: /\.(vue)$/, + exclude: /node_modules/, + loader: 'vue-loader' +} + +const scssLoader = { + test: /\.(css|scss)$/, + loader: ['css-loader', 'sass-loader'] +} + +module.exports = { + entry: './src/index.js', + output: { + path: path.resolve(__dirname, 'dist'), + filename: 'csseditor.js' + }, + module: { + loaders: [vueLoader, scssLoader] + }, + resolve: { + alias: { + vue$: path.resolve('..', 'node_modules', 'vue', 'dist', 'vue.esm.js') + } + } +}; \ No newline at end of file diff --git a/package.json b/package.json index 97ac790d..1f7d6875 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "pump": "^2.0.0", "gulp-plumber": "^1.2.0", "gulp-watch": "^5.0.0", - "codemirror": "^5.23.0" + "codemirror": "^5.23.0", + "vue-codemirror": "^4.0.3" }, "scripts": { "build": "cd ./client && npm run build && cd ../core && npm run build",