Ignore dist

This commit is contained in:
Jiiks 2018-01-16 08:40:30 +02:00
parent 602258b6d8
commit 0faad8d654
12 changed files with 1 additions and 28607 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ Installers/**/*/bin
Installers/**/*/obj
Installers/**/*/packages
.vs
dist/*

File diff suppressed because it is too large Load Diff

174
core/dist/main.js vendored
View File

@ -1,174 +0,0 @@
'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* BetterDiscord Core Entry
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
* All rights reserved.
* https://github.com/JsSucks - https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path = require('path');
/**
* DEVELOPMENT VARIABLES
*/
const clientScriptPath = path.resolve(__dirname, '..', '..', 'client', 'dist').replace(/\\/g, '/');
const __DEV = {
TESTING: false,
clientScriptPath: `${clientScriptPath}/betterdiscord.client.js`
};
const __pluginPath = path.resolve(__dirname, '..', '..', 'tests', 'plugins');
const __themePath = path.resolve(__dirname, '..', '..', 'tests', 'themes');
const { Utils, FileUtils, BDIpc, Config, WindowUtils } = require('./modules');
const { BrowserWindow } = require('electron');
const Common = {};
const dummyArgs = {
'version': '0.3.1',
'paths': [{ 'id': 'base', 'path': 'basePath' }, { 'id': 'plugins', 'path': __pluginPath }, { 'id': 'themes', 'path': __themePath }]
};
console.log(dummyArgs);
class Comms {
constructor() {
this.initListeners();
}
initListeners() {
BDIpc.on('bd-getConfig', o => {
o.reply(Common.Config.config);
});
BDIpc.on('bd-readFile', this.readFile);
BDIpc.on('bd-readJson', o => this.readFile(o, true));
}
readFile(o, json) {
return _asyncToGenerator(function* () {
const { path } = o.args;
try {
const readFile = json ? yield FileUtils.readJsonFromFile(path) : yield FileUtils.readFile(path);
o.reply(readFile);
} catch (err) {
o.reply(err);
}
})();
}
send(channel, message) {
return _asyncToGenerator(function* () {
BDIpc.send(channel, message);
})();
}
}
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();
}
init() {
var _this = this;
return _asyncToGenerator(function* () {
const window = yield _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));
_this.windowUtils.events('did-get-response-details', function () {
return _this.ignite(_this.windowUtils.window);
});
_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();
}
}, 500);
})();
}
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);
return;
}
if (windows.length === 1 && windows[0].webContents.getURL().includes("discordapp.com")) {
resolve(windows[0]);
clearInterval(defer);
}
}, 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);
}
}
get fileUtils() {
return FileUtils;
}
}
module.exports = {
BetterDiscord
};

View File

@ -1,45 +0,0 @@
'use strict';
/**
* BetterDiscord IPC Module
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
* All rights reserved.
* https://github.com/JsSucks - https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const { Module } = require('./modulebase');
const { ipcMain } = require('electron');
class BDIpcEvent extends Module {
constructor(event, args) {
super(args);
this.ipcEvent = event;
}
bindings() {
this.send = this.send.bind(this);
this.reply = this.reply.bind(this);
}
send(message) {
this.ipcEvent.sender.send(this.args.__eid, message);
}
reply(message) {
this.send(message);
}
}
class BDIpc {
static on(channel, cb) {
ipcMain.on(channel, (event, args) => cb(new BDIpcEvent(event, args)));
}
}
module.exports = { BDIpc };

View File

@ -1,34 +0,0 @@
'use strict';
/**
* BetterDiscord Config Module
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
* All rights reserved.
* https://github.com/JsSucks - https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const { Module } = require('./modulebase');
class Config extends Module {
get version() {
return this.args.version;
}
get paths() {
return this.args.paths;
}
get config() {
return {
'version': this.version,
'paths': this.paths
};
}
}
module.exports = { Config };

View File

@ -1,44 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _bdipc = require('./bdipc');
Object.defineProperty(exports, 'BDIpc', {
enumerable: true,
get: function () {
return _bdipc.BDIpc;
}
});
var _utils = require('./utils');
Object.defineProperty(exports, 'Utils', {
enumerable: true,
get: function () {
return _utils.Utils;
}
});
Object.defineProperty(exports, 'FileUtils', {
enumerable: true,
get: function () {
return _utils.FileUtils;
}
});
Object.defineProperty(exports, 'WindowUtils', {
enumerable: true,
get: function () {
return _utils.WindowUtils;
}
});
var _config = require('./config');
Object.defineProperty(exports, 'Config', {
enumerable: true,
get: function () {
return _config.Config;
}
});

View File

@ -1,42 +0,0 @@
"use strict";
/**
* BetterDiscord Module Base
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
* All rights reserved.
* https://github.com/JsSucks - https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/*
Base Module that every non-static module should extend
*/
class Module {
constructor(args) {
this.__ = {
state: args,
args
};
this.init();
}
init() {
if (this.bindings) this.bindings();
if (this.setInitialState) this.setInitialState(this.state);
}
set args(t) {}
get args() {
return this.__.args;
}
get state() {
return this.__.state;
}
}
module.exports = { Module };

View File

@ -1,171 +0,0 @@
'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* BetterDiscord Utils Module
* Copyright (c) 2015-present JsSucks - https://github.com/JsSucks
* All rights reserved.
* https://github.com/JsSucks - https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const path = require('path'),
fs = require('fs');
const { Module } = require('./modulebase');
class Utils {
static tryParseJson(jsonString) {
return _asyncToGenerator(function* () {
try {
return JSON.parse(jsonString);
} catch (err) {
throw {
'message': 'Failed to parse json',
err
};
}
})();
}
static get timestamp() {
return 'Timestamp';
}
}
class FileUtils {
static fileExists(path) {
return _asyncToGenerator(function* () {
return new Promise(function (resolve, reject) {
fs.stat(path, function (err, stats) {
if (err) return reject({
'message': `No such file or directory: ${err.path}`,
err
});
if (!stats.isFile()) return reject({
'message': `Not a file: ${path}`,
stats
});
resolve();
});
});
})();
}
static directoryExists(path) {
return _asyncToGenerator(function* () {
return new Promise(function (resolve) {
fs.stat(path, function (err, stats) {
if (err) return reject({
'message': `Directory does not exist: ${path}`,
err
});
if (!stats.isDirectory()) return reject({
'message': `Not a directory: ${path}`,
stats
});
resolve();
});
});
})();
}
static readFile(path) {
var _this = this;
return _asyncToGenerator(function* () {
try {
yield _this.fileExists(path);
} catch (err) {
throw err;
}
return new Promise(function (resolve) {
fs.readFile(path, 'utf-8', function (err, data) {
if (err) reject({
'message': `Could not read file: ${path}`,
err
});
resolve(data);
});
});
})();
}
static readJsonFromFile(path) {
var _this2 = this;
return _asyncToGenerator(function* () {
let readFile;
try {
readFile = yield _this2.readFile(path);
} catch (err) {
throw err;
}
try {
const parsed = yield Utils.tryParseJson(readFile);
return parsed;
} catch (err) {
throw Object.assign(err, { path });
}
})();
}
}
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}");`);
}
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 = {
Utils,
FileUtils,
WindowUtils
};

View File

@ -1,43 +0,0 @@
'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
};
class WSHook extends window.WebSocket {
constructor(url, protocols) {
super(url, protocols);
this.hook(url, protocols);
}
hook(url, protocols) {
console.info(`[BetterDiscord|WebSocket Proxy] new WebSocket detected, url: ${url}`);
if (!url.includes('gateway.discord.gg')) return;
if (window.__bd.setWS) {
window.__bd.setWS(this);
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket sent to instance`);
return;
}
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket stored to __bd['wsHook']`);
window.__bd.wsHook = this;
}
}
window.WebSocket = WSHook;
})();

48
core/dist/test.js vendored
View File

@ -1,48 +0,0 @@
const { BetterDiscord } = require('./main.js');
const _bd = new BetterDiscord();
const fileUtils = _bd.fileUtils;
//console.log(fileUtils.readJsonFromFile);
function dirExistsTest() {
fileUtils.readJsonFromFile('test.json').then(data => {
if(data.err) {
console.log("ERR");
console.log(data);
} else {
console.log(data);
}
}).catch(err => { console.log(err) });
}
String.prototype.padLeft = Number.prototype.padLeft = function(prefix, len) {
let str = this.toString();
while(str.length < len) str = prefix + str;
return str;
}
String.prototype.padRight = Number.prototype.padLeft = function(suffix, len) {
let str = this.toString();
while(str.length < len) str = str + suffix;
return str;
}
//console.log("".padStart);
//
//let date = new Date();
//let dateString = `[${date.getDate().padLeft("0", 2)}/${date.getMonth()+1}/${date.getYear()}]`;
//console.log(dateString);
//dirExistsTest();
const original = String.prototype.toString;
String.prototype.toString = function() {
let str = original.apply(this);
if(str === "foo") return "bar";
return str;
}
String.prototype.toString = proxy;

3
core/dist/test.json vendored
View File

@ -1,3 +0,0 @@
{
"foo": "bar
}

97
core/dist/utils.js vendored
View File

@ -1,97 +0,0 @@
'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
const path = require('path'),
fs = require('fs');
class Utils {
static tryParseJson(jsonString) {
return _asyncToGenerator(function* () {
try {
return JSON.parse(jsonString);
} catch (err) {
throw { "message": "Failed to parse json", err };
}
})();
}
static get timestamp() {
return "lol".padStart(10, "g");
}
}
class FileUtils {
static fileExists(path) {
return _asyncToGenerator(function* () {
return new Promise(function (resolve, reject) {
fs.stat(path, function (err, stats) {
if (err) return reject({ "message": `No such file or directory: ${err.path}`, err });
if (!stats.isFile()) return reject({ "message": `Not a file: ${path}`, stats });
resolve();
});
});
})();
}
static directoryExists(path) {
return _asyncToGenerator(function* () {
return new Promise(function (resolve) {
fs.stat(path, function (err, stats) {
if (err) return reject({ "message": `Directory does not exist: ${path}`, err });
if (!stats.isDirectory()) return reject({ "message": `Not a directory: ${path}`, stats });
resolve();
});
});
})();
}
static readFile(path) {
var _this = this;
return _asyncToGenerator(function* () {
let fileExists;
try {
fileExists = yield _this.fileExists(path);
} catch (err) {
throw err;
}
return new Promise(function (resolve) {
fs.readFile(path, function (err, data) {
if (err) reject({ "message": `Could not read file: ${path}`, err });
resolve(data);
});
});
})();
}
static readJsonFromFile(path) {
var _this2 = this;
return _asyncToGenerator(function* () {
let readFile;
try {
readFile = yield _this2.readFile(path);
} catch (err) {
throw err;
}
let parsed;
try {
const parsed = yield Utils.tryParseJson(readFile);
return parsed;
} catch (err) {
throw Object.assign(err, { path });
}
})();
}
}
module.exports = {
Utils,
FileUtils
};