From e72fb0d525b16635288431744264819b1c5f6dc3 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 11 Jan 2018 00:41:57 +0200 Subject: [PATCH] Handle reloading through simple inject --- core/dist/main.js | 16 +++++++++++++--- core/src/main.js | 20 ++++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/core/dist/main.js b/core/dist/main.js index fc5f6d62..202301f9 100644 --- a/core/dist/main.js +++ b/core/dist/main.js @@ -16,7 +16,7 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a * DEVELOPMENT VARIABLES */ const __DEV = { - TESTING: true, + TESTING: false, clietScriptPath: "G:/Github/JsSucks/BetterDiscordApp/client/dist/betterdiscord.client.js" }; @@ -73,6 +73,13 @@ class BetterDiscord { return _asyncToGenerator(function* () { const window = yield _this.waitForWindow(); _this.windowUtils = new WindowUtils({ window }); + + _this.windowUtils.webContents.on('did-finish-load', function (e) { + if (__DEV) { + _this.windowUtils.injectScript(__DEV.clietScriptPath); + } + }); + setTimeout(function () { if (__DEV) { _this.windowUtils.injectScript(__DEV.clietScriptPath); @@ -90,11 +97,14 @@ class BetterDiscord { resolve(windows[0]); clearInterval(defer); return; - } else if (false) { - //TODO Check for Discord loading finished + } + //TODO Check for Discord loading finished + if (windows.length === 1 && windows[0].webContents.getURL().includes("discordapp.com")) { resolve(windows[0]); clearInterval(defer); } + //resolve(windows[0]); + //clearInterval(defer); }, 100); }); })(); diff --git a/core/src/main.js b/core/src/main.js index 58ca9037..60869178 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -13,8 +13,8 @@ * DEVELOPMENT VARIABLES */ const __DEV = { - TESTING: true, - clietScriptPath: "G:/Github/JsSucks/BetterDiscordApp/client/dist/betterdiscord.client.js" + TESTING: false, + clientScriptPath: "G:/Github/JsSucks/BetterDiscordApp/client/dist/betterdiscord.client.js" } const { Utils, FileUtils, BDIpc, Config, WindowUtils } = require('./modules'); @@ -61,6 +61,7 @@ class Comms { class BetterDiscord { constructor(args) { + this.injectScripts = this.injectScripts.bind(this); Common.Config = new Config(args || dummyArgs); this.comms = new Comms(); this.init(); @@ -69,9 +70,12 @@ class BetterDiscord { async init() { const window = await this.waitForWindow(); this.windowUtils = new WindowUtils({ window }); + + this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true)); + setTimeout(() => { if (__DEV) { - this.windowUtils.injectScript(__DEV.clietScriptPath); + this.ínjectScripts(); } }, 500); } @@ -84,7 +88,9 @@ class BetterDiscord { resolve(windows[0]); clearInterval(defer); return; - }else if (false) { //TODO Check for Discord loading finished + } + + if (windows.length === 1 && windows[0].webContents.getURL().includes("discordapp.com")) { resolve(windows[0]); clearInterval(defer); } @@ -92,6 +98,12 @@ class BetterDiscord { }); } + injectScripts(reload) { + if (__DEV) { + this.windowUtils.injectScript(__DEV.clientScriptPath); + } + } + get fileUtils() { return FileUtils; } }