diff --git a/core/dist/main.js b/core/dist/main.js index f2a60580..5cbbaf54 100644 --- a/core/dist/main.js +++ b/core/dist/main.js @@ -66,6 +66,12 @@ class Comms { })(); } + send(channel, message) { + return _asyncToGenerator(function* () { + BDIpc.send(channel, message); + })(); + } + } class BetterDiscord { @@ -86,31 +92,26 @@ class BetterDiscord { _this.windowUtils = new WindowUtils({ window }); //Log some events for now - _this.windowUtils.webContents.on('did-start-loading', function (e) { - return _this.windowUtils.executeJavascript(`console.info('did-start-loading');`); - }); - _this.windowUtils.webContents.on('did-stop-loading', function (e) { - return _this.windowUtils.executeJavascript(`console.info('did-stop-loading');`); - }); - _this.windowUtils.webContents.on('did-get-response-details', function (e) { + //this.windowUtils.webContents.on('did-start-loading', e => this.windowUtils.executeJavascript(`console.info('did-start-loading');`)); + //this.windowUtils.webContents.on('did-stop-loading', e => this.windowUtils.executeJavascript(`console.info('did-stop-loading');`)); + //this.windowUtils.webContents.on('did-get-response-details', e => this.ignite(this.windowUtils.window)); + //this.windowUtils.webContents.on('page-favicon-updated', e => this.windowUtils.executeJavascript(`console.info('page-favicon-updated');`)); + //this.windowUtils.webContents.on('will-navigate', e => this.windowUtils.executeJavascript(`console.info('will-navigate');`)); + //this.windowUtils.webContents.on('did-navigate', e => this.windowUtils.executeJavascript(`console.info('did-navigate');`)); + //this.windowUtils.webContents.on('did-navigate-in-page', e => this.windowUtils.executeJavascript(`console.info('did-navigate-in-page');`)); + //this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true)); + + _this.windowUtils.events('did-get-response-details', function () { return _this.ignite(_this.windowUtils.window); }); - _this.windowUtils.webContents.on('page-favicon-updated', function (e) { - return _this.windowUtils.executeJavascript(`console.info('page-favicon-updated');`); - }); - _this.windowUtils.webContents.on('will-navigate', function (e) { - return _this.windowUtils.executeJavascript(`console.info('will-navigate');`); - }); - _this.windowUtils.webContents.on('did-navigate', function (e) { - return _this.windowUtils.executeJavascript(`console.info('did-navigate');`); - }); - _this.windowUtils.webContents.on('did-navigate-in-page', function (e) { - return _this.windowUtils.executeJavascript(`console.info('did-navigate-in-page');`); - }); - _this.windowUtils.webContents.on('did-finish-load', function (e) { + _this.windowUtils.events('did-finish-load', function (e) { return _this.injectScripts(true); }); + _this.windowUtils.events('did-navigate-in-page', function (event, url, isMainFrame) { + _this.windowUtils.send('did-navigate-in-page', { event, url, isMainFrame }); + }); + setTimeout(function () { if (__DEV) { _this.injectScripts(); diff --git a/core/dist/modules/utils.js b/core/dist/modules/utils.js index ad3d87a8..5ad5b674 100644 --- a/core/dist/modules/utils.js +++ b/core/dist/modules/utils.js @@ -153,6 +153,15 @@ class WindowUtils extends Module { if (variable) this.executeJavascript(`${variable} = require("${fpath}");`);else this.executeJavascript(`require("${fpath}");`); } + events(event, callback) { + this.webContents.on(event, callback); + } + + send(channel, message) { + channel = channel.startsWith('bd-') ? channel : `bd-${channel}`; + this.webContents.send(channel, message); + } + } module.exports = { diff --git a/core/src/main.js b/core/src/main.js index 3af4481a..4d4024b9 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -65,6 +65,10 @@ class Comms { } } + async send(channel, message) { + BDIpc.send(channel, message); + } + } class BetterDiscord { @@ -82,14 +86,22 @@ class BetterDiscord { this.windowUtils = new WindowUtils({ window }); //Log some events for now - this.windowUtils.webContents.on('did-start-loading', e => this.windowUtils.executeJavascript(`console.info('did-start-loading');`)); - this.windowUtils.webContents.on('did-stop-loading', e => this.windowUtils.executeJavascript(`console.info('did-stop-loading');`)); - this.windowUtils.webContents.on('did-get-response-details', e => this.ignite(this.windowUtils.window)); - this.windowUtils.webContents.on('page-favicon-updated', e => this.windowUtils.executeJavascript(`console.info('page-favicon-updated');`)); - this.windowUtils.webContents.on('will-navigate', e => this.windowUtils.executeJavascript(`console.info('will-navigate');`)); - this.windowUtils.webContents.on('did-navigate', e => this.windowUtils.executeJavascript(`console.info('did-navigate');`)); - this.windowUtils.webContents.on('did-navigate-in-page', e => this.windowUtils.executeJavascript(`console.info('did-navigate-in-page');`)); - this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true)); + //this.windowUtils.webContents.on('did-start-loading', e => this.windowUtils.executeJavascript(`console.info('did-start-loading');`)); + //this.windowUtils.webContents.on('did-stop-loading', e => this.windowUtils.executeJavascript(`console.info('did-stop-loading');`)); + //this.windowUtils.webContents.on('did-get-response-details', e => this.ignite(this.windowUtils.window)); + //this.windowUtils.webContents.on('page-favicon-updated', e => this.windowUtils.executeJavascript(`console.info('page-favicon-updated');`)); + //this.windowUtils.webContents.on('will-navigate', e => this.windowUtils.executeJavascript(`console.info('will-navigate');`)); + //this.windowUtils.webContents.on('did-navigate', e => this.windowUtils.executeJavascript(`console.info('did-navigate');`)); + //this.windowUtils.webContents.on('did-navigate-in-page', e => this.windowUtils.executeJavascript(`console.info('did-navigate-in-page');`)); + //this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true)); + + this.windowUtils.events('did-get-response-details', () => this.ignite(this.windowUtils.window)); + this.windowUtils.events('did-finish-load', e => this.injectScripts(true)); + + this.windowUtils.events('did-navigate-in-page', (event, url, isMainFrame) => { + this.windowUtils.send('did-navigate-in-page', { event, url, isMainFrame }); + }); + setTimeout(() => { if (__DEV) { this.injectScripts(); } diff --git a/core/src/modules/utils.js b/core/src/modules/utils.js index 3d88fdd5..923072f5 100644 --- a/core/src/modules/utils.js +++ b/core/src/modules/utils.js @@ -136,6 +136,15 @@ class WindowUtils extends Module { if (variable) this.executeJavascript(`${variable} = require("${fpath}");`); else this.executeJavascript(`require("${fpath}");`); } + + events(event, callback) { + this.webContents.on(event, callback); + } + + send(channel, message) { + channel = channel.startsWith('bd-') ? channel : `bd-${channel}`; + this.webContents.send(channel, message); + } }