From 03505fcdb6e7fda445b273928d77edc7155b831e Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 11 Jan 2018 16:12:24 +0200 Subject: [PATCH] Client ipc --- client/dist/betterdiscord.client.js | 52 +++++++++++++++++++++++++++-- client/src/index.js | 3 +- client/src/modules/bdipc.js | 26 +++++++++++++++ client/src/modules/index.js | 3 +- client/webpack.config.js | 3 ++ 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 client/src/modules/bdipc.js diff --git a/client/dist/betterdiscord.client.js b/client/dist/betterdiscord.client.js index 1f46e50d..bbf09f7d 100644 --- a/client/dist/betterdiscord.client.js +++ b/client/dist/betterdiscord.client.js @@ -26595,7 +26595,9 @@ return jQuery; -const { Logger, PluginManager } = __webpack_require__(123); +const { Logger, PluginManager, BDIpc } = __webpack_require__(123); + +window.bdipc = BDIpc; class BetterDiscord { @@ -26634,6 +26636,10 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__plugin__ = __webpack_require__(128); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__plugin___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2__plugin__); /* harmony reexport (binding) */ if(__webpack_require__.o(__WEBPACK_IMPORTED_MODULE_2__plugin__, "Pluging")) __webpack_require__.d(__webpack_exports__, "Pluging", function() { return __WEBPACK_IMPORTED_MODULE_2__plugin__["Pluging"]; }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__bdipc__ = __webpack_require__(129); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__bdipc___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3__bdipc__); +/* harmony reexport (binding) */ if(__webpack_require__.o(__WEBPACK_IMPORTED_MODULE_3__bdipc__, "BDIpc")) __webpack_require__.d(__webpack_exports__, "BDIpc", function() { return __WEBPACK_IMPORTED_MODULE_3__bdipc__["BDIpc"]; }); + @@ -27011,8 +27017,11 @@ class PluginManager extends Module { } getPluginByName(name) { - const { plugins } = this; - return plugins.find(plugin => plugin.name === name); + return this.plugins.find(plugin => plugin.name === name); + } + + getPluginById(id) { + return this.plugins.find(plugin => plugin.id === id); } } @@ -27043,5 +27052,42 @@ class Plugin { module.exports = { Plugin }; +/***/ }), +/* 129 */ +/***/ (function(module, exports, __webpack_require__) { + +/** + * BetterDiscord Client IPC 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. +*/ + +const { ipcRenderer } = __webpack_require__(130); + +class BDIpc { + + static async send(channel, message) { + channel = channel.startsWith('bd-') ? channel : `bd-${channel}`; + const __eid = Date.now().toString(); + ipcRenderer.send(channel, Object.assign(message ? message : {}, { __eid })); + return new Promise((resolve, reject) => { + ipcRenderer.once(__eid, (event, arg) => resolve(arg)); + }); + } + +} + +module.exports = { BDIpc }; + +/***/ }), +/* 130 */ +/***/ (function(module, exports) { + +module.exports = window.require("electron"); + /***/ }) /******/ ]); \ No newline at end of file diff --git a/client/src/index.js b/client/src/index.js index 6bda7dcf..dd298f21 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -10,8 +10,7 @@ 'use strict'; -const { Logger, PluginManager } = require('./modules'); - +const { Logger, PluginManager, BDIpc } = require('./modules'); class BetterDiscord { diff --git a/client/src/modules/bdipc.js b/client/src/modules/bdipc.js new file mode 100644 index 00000000..8029b721 --- /dev/null +++ b/client/src/modules/bdipc.js @@ -0,0 +1,26 @@ +/** + * BetterDiscord Client IPC 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. +*/ + +const { ipcRenderer } = require('electron'); + +class BDIpc { + + static async send(channel, message) { + channel = channel.startsWith('bd-') ? channel : `bd-${channel}`; + const __eid = Date.now().toString(); + ipcRenderer.send(channel, Object.assign(message ? message : {}, { __eid })); + return new Promise((resolve, reject) => { + ipcRenderer.once(__eid, (event, arg) => resolve(arg)); + }); + } + +} + +module.exports = { BDIpc }; \ No newline at end of file diff --git a/client/src/modules/index.js b/client/src/modules/index.js index e59ded72..08575f04 100644 --- a/client/src/modules/index.js +++ b/client/src/modules/index.js @@ -1,3 +1,4 @@ export { Logger } from './utils'; export { PluginManager } from './pluginmanager'; -export { Pluging } from './plugin'; \ No newline at end of file +export { Pluging } from './plugin'; +export { BDIpc } from './bdipc'; \ No newline at end of file diff --git a/client/webpack.config.js b/client/webpack.config.js index 213a66b5..e45d2162 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -20,6 +20,9 @@ module.exports = { module: { loaders: [jsLoader] }, + externals: { + 'electron': 'window.require("electron")' + } /* resolve: { alias: { 'momentjs': 'vendor/moment.min.js'