Clean up and comment

This commit is contained in:
Samuel Elliott 2018-03-31 22:49:00 +01:00
parent 3eb1782a64
commit 858fdcec59
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 6 additions and 58 deletions

View File

@ -57,9 +57,9 @@ class PatchedBrowserWindow extends BrowserWindow {
const options = Object.assign({}, originalOptions);
options.webPreferences = Object.assign({}, options.webPreferences);
// Make sure Node integration is enabled
options.webPreferences.nodeIntegration = true;
console.log('Creating new BrowserWindow with options', options, originalOptions);
return new BrowserWindow(options);
}
}
@ -211,6 +211,11 @@ class BetterDiscord {
return this.windowUtils.injectScript(this.config.getPath('cs'));
}
/**
* Patches Electron's BrowserWindow so all windows have Node integration enabled.
* This needs to be called only once before the main window is created (or BrowserWindow is put in a variable).
* Basically BetterDiscord needs to load before discord_desktop_core.
*/
static patchBrowserWindow() {
const electron_path = require.resolve('electron');
const browser_window_path = require.resolve(path.resolve(electron_path, '..', '..', 'browser-window.js'));

View File

@ -1,57 +0,0 @@
const electron = require('electron');
const path = require('path');
const _BrowserWindow = electron.BrowserWindow;
console.log('Open windows:', _BrowserWindow.getAllWindows());
console.log('Open window URLs:', _BrowserWindow.getAllWindows().map(w => w.getURL()));
console.log('Patching BrowserWindow');
class PatchedBrowserWindow extends _BrowserWindow {
constructor(originalOptions) {
const options = Object.assign({}, originalOptions);
options.webPreferences = Object.assign({}, options.webPreferences);
options.webPreferences.nodeIntegration = true;
console.log('Creating new BrowserWindow with options', options, originalOptions);
return new _BrowserWindow(options);
}
};
// Can't just do this because electron.BrowserWindow is a getter
// electron.BrowserWindow = PatchedBrowserWindow;
// Can't do this either because it's not configurable because ^^
// Object.defineProperty(electron, 'BrowserWindow', {
// get: () => PatchedBrowserWindow
// });
console.log('Electron:', electron);
console.log('Electron BrowserWindow getter:', electron.__lookupGetter__('BrowserWindow'));
console.log('Electron BrowserWindow setter:', electron.__lookupSetter__('BrowserWindow'));
const electron_path = require.resolve('electron');
const electron_module = require.cache[electron_path];
console.log('Electron module path:', electron_path);
console.log('Electron module:', electron_module);
const browser_window_path = require.resolve(path.resolve(electron_path, '..', '..', 'browser-window.js'));
const browser_window_module = require.cache[browser_window_path];
console.log('BrowserWindow module path:', browser_window_path);
console.log('BrowserWindow module:', browser_window_module);
browser_window_module.exports = PatchedBrowserWindow;
try {
new (require("../../../../BetterDiscord")).BetterDiscord();
} catch (err) {
console.err('Error loading BetterDiscord:', err);
}
// Main window is created here
module.exports = require('./core');