diff --git a/client/dist/betterdiscord.client.js b/client/dist/betterdiscord.client.js index 0370a585..501902d8 100644 --- a/client/dist/betterdiscord.client.js +++ b/client/dist/betterdiscord.client.js @@ -88,7 +88,7 @@ var _require = __webpack_require__(1), var BetterDiscord = function BetterDiscord() { _classCallCheck(this, BetterDiscord); - Logger.log("Hi!"); + Logger.log("Test Log"); }; var bdInstance = new BetterDiscord(); diff --git a/client/src/index.js b/client/src/index.js index 178ea739..adbbe341 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -15,7 +15,7 @@ const { Logger } = require('./modules'); class BetterDiscord { constructor() { - Logger.log("Hi!"); + Logger.log("Test Log"); } } diff --git a/core/dist/main.js b/core/dist/main.js index d650dd52..fc5f6d62 100644 --- a/core/dist/main.js +++ b/core/dist/main.js @@ -12,7 +12,16 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a * LICENSE file in the root directory of this source tree. */ -const { Utils, FileUtils, BDIpc, Config } = require('./modules'); +/** + * DEVELOPMENT VARIABLES + */ +const __DEV = { + TESTING: true, + clietScriptPath: "G:/Github/JsSucks/BetterDiscordApp/client/dist/betterdiscord.client.js" +}; + +const { Utils, FileUtils, BDIpc, Config, WindowUtils } = require('./modules'); +const { BrowserWindow } = require('electron'); const Common = {}; @@ -55,6 +64,40 @@ class BetterDiscord { constructor(args) { Common.Config = new Config(args || dummyArgs); this.comms = new Comms(); + this.init(); + } + + init() { + var _this = this; + + return _asyncToGenerator(function* () { + const window = yield _this.waitForWindow(); + _this.windowUtils = new WindowUtils({ window }); + setTimeout(function () { + if (__DEV) { + _this.windowUtils.injectScript(__DEV.clietScriptPath); + } + }, 500); + })(); + } + + waitForWindow() { + return _asyncToGenerator(function* () { + return new Promise(function (resolve, reject) { + const defer = setInterval(function () { + const windows = BrowserWindow.getAllWindows(); + if (__DEV && __DEV.TESTING && windows.length > 0) { + resolve(windows[0]); + clearInterval(defer); + return; + } else if (false) { + //TODO Check for Discord loading finished + resolve(windows[0]); + clearInterval(defer); + } + }, 100); + }); + })(); } get fileUtils() { diff --git a/core/dist/modules/index.js b/core/dist/modules/index.js index e9f233bc..a8ae78c3 100644 --- a/core/dist/modules/index.js +++ b/core/dist/modules/index.js @@ -27,6 +27,12 @@ Object.defineProperty(exports, 'FileUtils', { return _utils.FileUtils; } }); +Object.defineProperty(exports, 'WindowUtils', { + enumerable: true, + get: function () { + return _utils.WindowUtils; + } +}); var _config = require('./config'); diff --git a/core/dist/modules/utils.js b/core/dist/modules/utils.js index 700b723d..ad3d87a8 100644 --- a/core/dist/modules/utils.js +++ b/core/dist/modules/utils.js @@ -15,6 +15,8 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a const path = require('path'), fs = require('fs'); +const { Module } = require('./modulebase'); + class Utils { static tryParseJson(jsonString) { @@ -122,7 +124,39 @@ class FileUtils { } } +class WindowUtils extends Module { + + bindings() { + this.openDevTools = this.openDevTools.bind(this); + this.executeJavascript = this.executeJavascript.bind(this); + this.injectScript = this.injectScript.bind(this); + } + + get window() { + return this.state.window; + } + + get webContents() { + return this.window.webContents; + } + + openDevTools() { + this.webContents.openDevTools(); + } + + executeJavascript(script) { + this.webContents.executeJavaScript(script); + } + + injectScript(fpath, variable) { + console.log(`Injecting: ${fpath}`); + if (variable) this.executeJavascript(`${variable} = require("${fpath}");`);else this.executeJavascript(`require("${fpath}");`); + } + +} + module.exports = { Utils, - FileUtils + FileUtils, + WindowUtils }; \ No newline at end of file diff --git a/core/src/main.js b/core/src/main.js index 9e00bb36..58ca9037 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -8,7 +8,17 @@ * LICENSE file in the root directory of this source tree. */ -const { Utils, FileUtils, BDIpc, Config } = require('./modules'); + +/** + * DEVELOPMENT VARIABLES + */ +const __DEV = { + TESTING: true, + clietScriptPath: "G:/Github/JsSucks/BetterDiscordApp/client/dist/betterdiscord.client.js" +} + +const { Utils, FileUtils, BDIpc, Config, WindowUtils } = require('./modules'); +const { BrowserWindow } = require('electron'); const Common = {}; @@ -53,6 +63,33 @@ class BetterDiscord { constructor(args) { Common.Config = new Config(args || dummyArgs); this.comms = new Comms(); + this.init(); + } + + async init() { + const window = await this.waitForWindow(); + this.windowUtils = new WindowUtils({ window }); + setTimeout(() => { + if (__DEV) { + this.windowUtils.injectScript(__DEV.clietScriptPath); + } + }, 500); + } + + async waitForWindow() { + return new Promise((resolve, reject) => { + const defer = setInterval(() => { + const windows = BrowserWindow.getAllWindows(); + if (__DEV && __DEV.TESTING && windows.length > 0) { + resolve(windows[0]); + clearInterval(defer); + return; + }else if (false) { //TODO Check for Discord loading finished + resolve(windows[0]); + clearInterval(defer); + } + }, 100); + }); } get fileUtils() { return FileUtils; } diff --git a/core/src/modules/index.js b/core/src/modules/index.js index b5f7415a..983b5553 100644 --- a/core/src/modules/index.js +++ b/core/src/modules/index.js @@ -1,3 +1,3 @@ export { BDIpc } from './bdipc'; -export { Utils, FileUtils } from './utils'; +export { Utils, FileUtils, WindowUtils } from './utils'; export { Config } from './config'; \ No newline at end of file diff --git a/core/src/modules/utils.js b/core/src/modules/utils.js index 9c7301f2..3d88fdd5 100644 --- a/core/src/modules/utils.js +++ b/core/src/modules/utils.js @@ -12,6 +12,8 @@ const path = require('path'), fs = require('fs'); +const { Module } = require('./modulebase'); + class Utils { static async tryParseJson(jsonString) { @@ -105,7 +107,40 @@ class FileUtils { } } +class WindowUtils extends Module { + + bindings() { + this.openDevTools = this.openDevTools.bind(this); + this.executeJavascript = this.executeJavascript.bind(this); + this.injectScript = this.injectScript.bind(this); + } + + get window() { + return this.state.window; + } + + get webContents() { + return this.window.webContents; + } + + openDevTools() { + this.webContents.openDevTools(); + } + + executeJavascript(script) { + this.webContents.executeJavaScript(script); + } + + injectScript(fpath, variable) { + console.log(`Injecting: ${fpath}`); + if (variable) this.executeJavascript(`${variable} = require("${fpath}");`); + else this.executeJavascript(`require("${fpath}");`); + } + +} + module.exports = { Utils, - FileUtils + FileUtils, + WindowUtils } \ No newline at end of file diff --git a/tests/index.js b/tests/index.js index f7b9f893..0c1a74a0 100644 --- a/tests/index.js +++ b/tests/index.js @@ -6,10 +6,9 @@ const url = require('url'); const config = require('./config.json'); let bw; - -const bd = new BetterDiscord(config); - +const bd = new BetterDiscord(Object.assign(config)); app.on('ready', () => { + bw = new BrowserWindow({ width: 1920, height: 1080 }); bw.webContents.openDevTools(); bw.loadURL(url.format({ @@ -18,4 +17,5 @@ app.on('ready', () => { slashes: true })); bw.on('closed', () => app.quit()); + }); \ No newline at end of file