This commit is contained in:
Jiiks 2018-01-12 03:06:43 +02:00
parent 662329c5e9
commit 8e308f2a65
6 changed files with 152 additions and 19 deletions

View File

@ -27094,7 +27094,7 @@ module.exports = window.require("electron");
/***/ }),
/* 131 */
/***/ (function(module, exports, __webpack_require__) {
/***/ (function(module, exports) {
/**
* BetterDiscord Client WebpackModules Module
@ -27111,6 +27111,7 @@ class WebpackModules {
static async getModuleByProps(props) {
const modules = await this.getAllModules();
return new Promise((resolve, reject) => {
const rm = [];
for (let index in modules) {
if (!modules.hasOwnProperty(index)) continue;
const module = modules[index];
@ -27118,11 +27119,11 @@ class WebpackModules {
if (!exports || typeof exports !== 'object') continue;
if (!(props in exports)) continue;
resolve(module.exports);
break;
rm.push(module);
// resolve(module);
// break;
}
resolve(rm);
reject(null);
});
}
@ -27133,10 +27134,14 @@ class WebpackModules {
return new Promise((resolve, reject) => {
for (let index in modules) {
if (!modules.hasOwnProperty(index)) continue;
if (typeof exports === 'object' && name in exports) {
const module = modules[index];
const { exports } = module;
if (!exports) continue;
if (typeof exports === 'object' && (name in exports || exports.name === name)) {
resolve(module.exports);
break;
} else if (false) {
} else if (typeof exports === 'function' && exports.name === name) {
resolve(module.exports);
break;
}

View File

@ -13,6 +13,7 @@ class WebpackModules {
static async getModuleByProps(props) {
const modules = await this.getAllModules();
return new Promise((resolve, reject) => {
const rm = [];
for (let index in modules) {
if (!modules.hasOwnProperty(index)) continue;
const module = modules[index];
@ -20,11 +21,11 @@ class WebpackModules {
if (!exports || typeof exports !== 'object') continue;
if (!(props in exports)) continue;
resolve(module.exports);
break;
rm.push(module);
// resolve(module);
// break;
}
resolve(rm);
reject(null);
});
}
@ -35,7 +36,11 @@ class WebpackModules {
return new Promise((resolve, reject) => {
for (let index in modules) {
if (!modules.hasOwnProperty(index)) continue;
if (typeof exports === 'object' && name in exports) {
const module = modules[index];
const { exports } = module;
if (!exports) continue;
if (typeof exports === 'object' && (name in exports || exports.name === name)) {
resolve(module.exports);
break;
} else if (typeof exports === 'function' && exports.name === name) {

44
core/dist/main.js vendored
View File

@ -24,8 +24,6 @@ const __DEV = {
clientScriptPath: `${clientScriptPath}/betterdiscord.client.js`
};
console.log(__DEV);
const __pluginPath = path.resolve(__dirname, '..', '..', 'tests', 'plugins');
const __themePath = path.resolve(__dirname, '..', '..', 'tests', 'themes');
@ -74,6 +72,7 @@ class BetterDiscord {
constructor(args) {
this.injectScripts = this.injectScripts.bind(this);
this.ignite = this.ignite.bind(this);
Common.Config = new Config(args || dummyArgs);
this.comms = new Comms();
this.init();
@ -86,6 +85,28 @@ class BetterDiscord {
const window = yield _this.waitForWindow();
_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) {
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) {
return _this.injectScripts(true);
});
@ -99,10 +120,20 @@ class BetterDiscord {
}
waitForWindow() {
var _this2 = this;
return _asyncToGenerator(function* () {
const self = _this2;
return new Promise(function (resolve, reject) {
const defer = setInterval(function () {
const windows = BrowserWindow.getAllWindows();
if (windows.length > 0) {
windows.forEach(function (window) {
self.ignite(window);
});
}
if (__DEV && __DEV.TESTING && windows.length > 0) {
resolve(windows[0]);
clearInterval(defer);
@ -113,12 +144,19 @@ class BetterDiscord {
resolve(windows[0]);
clearInterval(defer);
}
}, 100);
}, 10);
});
})();
}
ignite(window) {
//Hook things that Discord removes from global. These will be removed again in the client script
const sp = path.resolve(__dirname, 'sparkplug.js').replace(/\\/g, '/');
window.webContents.executeJavaScript(`require("${sp}");`);
}
injectScripts(reload = false) {
console.log(`RELOAD? ${reload}`);
if (__DEV) {
this.windowUtils.injectScript(__DEV.clientScriptPath);
}

32
core/dist/sparkplug.js vendored Normal file
View File

@ -0,0 +1,32 @@
'use strict';
(() => {
if (window.__bd && window.__bd.ignited) return;
console.log('[BetterDiscord|Sparkplug]');
const ls = window.localStorage;
if (!ls) console.warn('[BetterDiscord|Sparkplug] Failed to hook localStorage :(');
const wsOrig = window.WebSocket;
window.__bd = {
localStorage: ls,
wsHook: null,
wsOrig,
ignited: true
};
window.WebSocket = function (endpoint, protocols) {
console.info(`[BetterDiscord|WebSocket Proxy] new WebSocket detected, endpoint: ${endpoint}`);
const wsHook = new wsOrig(endpoint, protocols);
if (window.__bd.setWS) {
window.__bd.setWS(wsHook);
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket sent to instance`);
} else {
window.__bd['wsHook'] = wsHook;
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket stored to __bd['wsHook']`);
}
return wsHook;
};
})();

View File

@ -71,6 +71,7 @@ class BetterDiscord {
constructor(args) {
this.injectScripts = this.injectScripts.bind(this);
this.ignite = this.ignite.bind(this);
Common.Config = new Config(args || dummyArgs);
this.comms = new Comms();
this.init();
@ -80,19 +81,33 @@ class BetterDiscord {
const window = await this.waitForWindow();
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));
setTimeout(() => {
if (__DEV) {
this.injectScripts();
}
if (__DEV) { this.injectScripts(); }
}, 500);
}
async waitForWindow() {
const self = this;
return new Promise((resolve, reject) => {
const defer = setInterval(() => {
const windows = BrowserWindow.getAllWindows();
if (windows.length > 0) {
windows.forEach(window => {
self.ignite(window);
});
}
if (__DEV && __DEV.TESTING && windows.length > 0) {
resolve(windows[0]);
clearInterval(defer);
@ -103,11 +118,18 @@ class BetterDiscord {
resolve(windows[0]);
clearInterval(defer);
}
}, 100);
}, 10);
});
}
ignite(window) {
//Hook things that Discord removes from global. These will be removed again in the client script
const sp = path.resolve(__dirname, 'sparkplug.js').replace(/\\/g, '/');
window.webContents.executeJavaScript(`require("${sp}");`);
}
injectScripts(reload = false) {
console.log(`RELOAD? ${reload}`);
if (__DEV) {
this.windowUtils.injectScript(__DEV.clientScriptPath);
}

31
core/src/sparkplug.js Normal file
View File

@ -0,0 +1,31 @@
(() => {
if (window.__bd && window.__bd.ignited) return;
console.log('[BetterDiscord|Sparkplug]');
const ls = window.localStorage;
if (!ls) console.warn('[BetterDiscord|Sparkplug] Failed to hook localStorage :(');
const wsOrig = window.WebSocket;
window.__bd = {
localStorage: ls,
wsHook: null,
wsOrig,
ignited: true
}
window.WebSocket = function (endpoint, protocols) {
console.info(`[BetterDiscord|WebSocket Proxy] new WebSocket detected, endpoint: ${endpoint}`);
const wsHook = new wsOrig(endpoint, protocols);
if (window.__bd.setWS) {
window.__bd.setWS(wsHook);
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket sent to instance`);
} else {
window.__bd['wsHook'] = wsHook;
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket stored to __bd['wsHook']`);
}
return wsHook;
}
})();