Skip to content
This repository has been archived by the owner on Jun 27, 2021. It is now read-only.

Commit

Permalink
Partial fix for BD Plugins compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
MasicoreLord authored and MasicoreLord committed Feb 9, 2021
1 parent af67eb2 commit f14309e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
11 changes: 7 additions & 4 deletions bd_shit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const fs = require('fs');
const Module = require('module').Module;
const originalRequire = Module._extensions['.js'];
const EDPlugin = require('./plugin');
const electron = require('electron');

const splitRegex = /[^\S\r\n]*?(?:\r\n|\n)[^\S\r\n]*?\*[^\S\r\n]?/;
const escapedAtRegex = /^\\@/;
module.exports = class BDManager {

static async setup(currentWindow) {
this.currentWindow = currentWindow;
static async setup() {
this.defineGlobals();
this.jqueryElement = document.createElement('script');
this.jqueryElement.src = `//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js`;
Expand All @@ -23,7 +23,9 @@ module.exports = class BDManager {
});
this.observer.observe(document, {childList: true, subtree: true});

this.currentWindow.webContents.on('did-navigate-in-page', BDManager.onSwitch);
//this.currentWindow.webContents.on('did-navigate-in-page', BDManager.onSwitch);
electron.ipcRenderer.invoke('bd-navigate-page-listener', BDManager.onSwitch);


fs.readFile(path.join(process.env.injDir, 'bd.css'), (err, text) => {
if (err) return console.error(err);
Expand All @@ -36,7 +38,8 @@ module.exports = class BDManager {
static destroy() {
EDApi.clearCSS('BDManager');
this.observer.disconnect();
this.currentWindow.webContents.removeEventListener('did-navigate-in-page', BDManager.onSwitch);
//this.currentWindow.webContents.removeEventListener('did-navigate-in-page', BDManager.onSwitch);
electron.ipcRenderer.invoke('remove-bd-navigate-page-listener', BDManager.onSwitch);
this.jqueryElement.remove();
Module._extensions['.js'] = originalRequire;
}
Expand Down
5 changes: 4 additions & 1 deletion dom_shit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const fs = require('fs');
const electron = require('electron');

const mainProcessInfo = JSON.parse(electron.ipcRenderer.sendSync('main-process-info'));
const Module = require('module');
Module.globalPaths.push(mainProcessInfo.originalNodeModulesPath);
Expand All @@ -11,6 +12,8 @@ if (mainProcessInfo.originalPreloadScript) {
require(mainProcessInfo.originalPreloadScript);
}

//electron.ipcRenderer.sendSync('current-web-contents');

//Get inject directory
if (!process.env.injDir) process.env.injDir = __dirname;

Expand Down Expand Up @@ -169,7 +172,7 @@ process.once('loaded', async () => {

if (ED.config.bdPlugins) {
try {
await require('./bd_shit').setup(currentWindow);
await require('./bd_shit').setup();
c.log(`Preparing BD plugins...`);
for (const i in pluginFiles) {
if (!pluginFiles[i].endsWith('.js') || !pluginFiles[i].endsWith('.plugin.js')) continue;
Expand Down
14 changes: 9 additions & 5 deletions main_process_shit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ ipcMain.on('main-process-info', (event, arg) => {
}`
});

ipcMain.on('current-web-contents', (event, arg) => {
event.returnValue = event.sender.__currentWebContents
});

ipcMain.on('main-process-utils', (event, arg) => {
event.returnValue = `{
"dialog": "${electron.dialog}"
}`
});
});

ipcMain.handle('bd-navigate-page-listener', (event, arg) => {
event.sender.getOwnerBrowserWindow().webContents.on('did-navigate-in-page', arg);
})

ipcMain.handle('remove-bd-navigate-page-listener', (event, arg) => {
event.sender.getOwnerBrowserWindow().webContents.removeEventListener('did-navigate-in-page', arg);
})

0 comments on commit f14309e

Please sign in to comment.