WindowUtils and script inject
This commit is contained in:
parent
3ab286f81e
commit
149a4e0dec
|
@ -88,7 +88,7 @@ var _require = __webpack_require__(1),
|
|||
var BetterDiscord = function BetterDiscord() {
|
||||
_classCallCheck(this, BetterDiscord);
|
||||
|
||||
Logger.log("Hi!");
|
||||
Logger.log("Test Log");
|
||||
};
|
||||
|
||||
var bdInstance = new BetterDiscord();
|
||||
|
|
|
@ -15,7 +15,7 @@ const { Logger } = require('./modules');
|
|||
class BetterDiscord {
|
||||
|
||||
constructor() {
|
||||
Logger.log("Hi!");
|
||||
Logger.log("Test Log");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,16 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const { Utils, FileUtils, BDIpc, Config } = require('./modules');
|
||||
/**
|
||||
* DEVELOPMENT VARIABLES
|
||||
*/
|
||||
const __DEV = {
|
||||
TESTING: true,
|
||||
clietScriptPath: "G:/Github/JsSucks/BetterDiscordApp/client/dist/betterdiscord.client.js"
|
||||
};
|
||||
|
||||
const { Utils, FileUtils, BDIpc, Config, WindowUtils } = require('./modules');
|
||||
const { BrowserWindow } = require('electron');
|
||||
|
||||
const Common = {};
|
||||
|
||||
|
@ -55,6 +64,40 @@ class BetterDiscord {
|
|||
constructor(args) {
|
||||
Common.Config = new Config(args || dummyArgs);
|
||||
this.comms = new Comms();
|
||||
this.init();
|
||||
}
|
||||
|
||||
init() {
|
||||
var _this = this;
|
||||
|
||||
return _asyncToGenerator(function* () {
|
||||
const window = yield _this.waitForWindow();
|
||||
_this.windowUtils = new WindowUtils({ window });
|
||||
setTimeout(function () {
|
||||
if (__DEV) {
|
||||
_this.windowUtils.injectScript(__DEV.clietScriptPath);
|
||||
}
|
||||
}, 500);
|
||||
})();
|
||||
}
|
||||
|
||||
waitForWindow() {
|
||||
return _asyncToGenerator(function* () {
|
||||
return new Promise(function (resolve, reject) {
|
||||
const defer = setInterval(function () {
|
||||
const windows = BrowserWindow.getAllWindows();
|
||||
if (__DEV && __DEV.TESTING && windows.length > 0) {
|
||||
resolve(windows[0]);
|
||||
clearInterval(defer);
|
||||
return;
|
||||
} else if (false) {
|
||||
//TODO Check for Discord loading finished
|
||||
resolve(windows[0]);
|
||||
clearInterval(defer);
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
get fileUtils() {
|
||||
|
|
|
@ -27,6 +27,12 @@ Object.defineProperty(exports, 'FileUtils', {
|
|||
return _utils.FileUtils;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'WindowUtils', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return _utils.WindowUtils;
|
||||
}
|
||||
});
|
||||
|
||||
var _config = require('./config');
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
|
|||
const path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
const { Module } = require('./modulebase');
|
||||
|
||||
class Utils {
|
||||
|
||||
static tryParseJson(jsonString) {
|
||||
|
@ -122,7 +124,39 @@ class FileUtils {
|
|||
}
|
||||
}
|
||||
|
||||
class WindowUtils extends Module {
|
||||
|
||||
bindings() {
|
||||
this.openDevTools = this.openDevTools.bind(this);
|
||||
this.executeJavascript = this.executeJavascript.bind(this);
|
||||
this.injectScript = this.injectScript.bind(this);
|
||||
}
|
||||
|
||||
get window() {
|
||||
return this.state.window;
|
||||
}
|
||||
|
||||
get webContents() {
|
||||
return this.window.webContents;
|
||||
}
|
||||
|
||||
openDevTools() {
|
||||
this.webContents.openDevTools();
|
||||
}
|
||||
|
||||
executeJavascript(script) {
|
||||
this.webContents.executeJavaScript(script);
|
||||
}
|
||||
|
||||
injectScript(fpath, variable) {
|
||||
console.log(`Injecting: ${fpath}`);
|
||||
if (variable) this.executeJavascript(`${variable} = require("${fpath}");`);else this.executeJavascript(`require("${fpath}");`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Utils,
|
||||
FileUtils
|
||||
FileUtils,
|
||||
WindowUtils
|
||||
};
|
|
@ -8,7 +8,17 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const { Utils, FileUtils, BDIpc, Config } = require('./modules');
|
||||
|
||||
/**
|
||||
* DEVELOPMENT VARIABLES
|
||||
*/
|
||||
const __DEV = {
|
||||
TESTING: true,
|
||||
clietScriptPath: "G:/Github/JsSucks/BetterDiscordApp/client/dist/betterdiscord.client.js"
|
||||
}
|
||||
|
||||
const { Utils, FileUtils, BDIpc, Config, WindowUtils } = require('./modules');
|
||||
const { BrowserWindow } = require('electron');
|
||||
|
||||
const Common = {};
|
||||
|
||||
|
@ -53,6 +63,33 @@ class BetterDiscord {
|
|||
constructor(args) {
|
||||
Common.Config = new Config(args || dummyArgs);
|
||||
this.comms = new Comms();
|
||||
this.init();
|
||||
}
|
||||
|
||||
async init() {
|
||||
const window = await this.waitForWindow();
|
||||
this.windowUtils = new WindowUtils({ window });
|
||||
setTimeout(() => {
|
||||
if (__DEV) {
|
||||
this.windowUtils.injectScript(__DEV.clietScriptPath);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
||||
async waitForWindow() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const defer = setInterval(() => {
|
||||
const windows = BrowserWindow.getAllWindows();
|
||||
if (__DEV && __DEV.TESTING && windows.length > 0) {
|
||||
resolve(windows[0]);
|
||||
clearInterval(defer);
|
||||
return;
|
||||
}else if (false) { //TODO Check for Discord loading finished
|
||||
resolve(windows[0]);
|
||||
clearInterval(defer);
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
|
||||
get fileUtils() { return FileUtils; }
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export { BDIpc } from './bdipc';
|
||||
export { Utils, FileUtils } from './utils';
|
||||
export { Utils, FileUtils, WindowUtils } from './utils';
|
||||
export { Config } from './config';
|
|
@ -12,6 +12,8 @@ const
|
|||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
const { Module } = require('./modulebase');
|
||||
|
||||
class Utils {
|
||||
|
||||
static async tryParseJson(jsonString) {
|
||||
|
@ -105,7 +107,40 @@ class FileUtils {
|
|||
}
|
||||
}
|
||||
|
||||
class WindowUtils extends Module {
|
||||
|
||||
bindings() {
|
||||
this.openDevTools = this.openDevTools.bind(this);
|
||||
this.executeJavascript = this.executeJavascript.bind(this);
|
||||
this.injectScript = this.injectScript.bind(this);
|
||||
}
|
||||
|
||||
get window() {
|
||||
return this.state.window;
|
||||
}
|
||||
|
||||
get webContents() {
|
||||
return this.window.webContents;
|
||||
}
|
||||
|
||||
openDevTools() {
|
||||
this.webContents.openDevTools();
|
||||
}
|
||||
|
||||
executeJavascript(script) {
|
||||
this.webContents.executeJavaScript(script);
|
||||
}
|
||||
|
||||
injectScript(fpath, variable) {
|
||||
console.log(`Injecting: ${fpath}`);
|
||||
if (variable) this.executeJavascript(`${variable} = require("${fpath}");`);
|
||||
else this.executeJavascript(`require("${fpath}");`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Utils,
|
||||
FileUtils
|
||||
FileUtils,
|
||||
WindowUtils
|
||||
}
|
|
@ -6,10 +6,9 @@ const url = require('url');
|
|||
const config = require('./config.json');
|
||||
|
||||
let bw;
|
||||
|
||||
const bd = new BetterDiscord(config);
|
||||
|
||||
const bd = new BetterDiscord(Object.assign(config));
|
||||
app.on('ready', () => {
|
||||
|
||||
bw = new BrowserWindow({ width: 1920, height: 1080 });
|
||||
bw.webContents.openDevTools();
|
||||
bw.loadURL(url.format({
|
||||
|
@ -18,4 +17,5 @@ app.on('ready', () => {
|
|||
slashes: true
|
||||
}));
|
||||
bw.on('closed', () => app.quit());
|
||||
|
||||
});
|
Loading…
Reference in New Issue