ignore everything in ui
This commit is contained in:
parent
20abc525d3
commit
0f762c1e58
|
@ -10,13 +10,20 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const { Global, Logger, Utils, PluginManager, BDIpc, WebpackModules, SocketProxy } = require('./modules');
|
||||
const { Global, Logger, Utils, PluginManager, BDIpc, WebpackModules, SocketProxy, Events } = require('./modules');
|
||||
//const { UI } = require('./modules/ui/index.jsx');
|
||||
|
||||
class BetterDiscord {
|
||||
|
||||
constructor() {
|
||||
window.bdUtils = Utils;
|
||||
window.wpm = WebpackModules;
|
||||
Events.on('global-ready', e => {
|
||||
const { UI } = require('./modules/ui/ui.jsx');
|
||||
console.log(UI);
|
||||
this.ui = new UI();
|
||||
});
|
||||
// this.UI = new UI();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@
|
|||
const { Module } = require('./modulebase');
|
||||
const { Events } = require('./events');
|
||||
const { BDIpc } = require('./bdipc');
|
||||
const { WebpackModules } = require('./webpackmodules');
|
||||
|
||||
class Global extends Module {
|
||||
|
||||
constructor(args) {
|
||||
super(args);
|
||||
this.first();
|
||||
window.gl = this;
|
||||
}
|
||||
|
||||
bindings() {
|
||||
|
@ -29,6 +31,13 @@ class Global extends Module {
|
|||
(async () => {
|
||||
const config = await BDIpc.send('getConfig');
|
||||
this.setState(config);
|
||||
/* const getReact = await WebpackModules.getModuleByProps(('createElement', 'cloneElement'));
|
||||
this.React = getReact[0].exports;
|
||||
window.React = this.React;
|
||||
const getReactDom = await WebpackModules.getModuleByProps(('render', 'findDOMNode'));
|
||||
this.reactDOM = getReactDom[0].exports;*/
|
||||
// this.setState(Object.assign(config, { React, reactDOM }));
|
||||
Events.emit('global-ready');
|
||||
})();
|
||||
|
||||
if (window.__bd) {
|
||||
|
@ -51,6 +60,10 @@ class Global extends Module {
|
|||
return this.state[name];
|
||||
}
|
||||
|
||||
getLoadedModule(name) {
|
||||
return this[name];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const _instance = new Global();
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
const { WebpackModules } = require('../../');
|
||||
const React = WebpackModules.getModuleByNameSync('React', true);
|
||||
|
||||
class SidebarHeader extends React.Component {
|
||||
|
||||
render() {
|
||||
const { text } = this.props;
|
||||
return (
|
||||
<div className='bd-header'>{text}</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SidebarItem extends React.Component {
|
||||
|
||||
render() {
|
||||
const { text, active } = this.props;
|
||||
return (
|
||||
<div className={`bd-item${active ? ' active' : ''}`}>{text}</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Sidebar extends React.Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className='bd-sidebar'>
|
||||
{this.props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {Sidebar, SidebarHeader, SidebarItem}
|
|
@ -0,0 +1,23 @@
|
|||
const { WebpackModules } = require('../../');
|
||||
const React = WebpackModules.getModuleByNameSync('React', true);
|
||||
|
||||
class SidebarView extends React.Component {
|
||||
|
||||
render() {
|
||||
const { sidebar } = this.props;
|
||||
return (
|
||||
<div className='bd-sidebar-view'>
|
||||
<div className='bd-sidebar-region'>
|
||||
<div className='bd-scrollerWrap'>
|
||||
<div className='bd-scroller'>
|
||||
{sidebar}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = SidebarView;
|
|
@ -0,0 +1,2 @@
|
|||
const { Global } = require('../');
|
||||
export default Global.getObject('React');
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* BetterDiscord Client Renderer
|
||||
* 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 { WebpackModules } = require('../');
|
||||
|
||||
class Renderer {
|
||||
|
||||
static async render(component, root) {
|
||||
if (!this.React) this.React = await this.getReact();
|
||||
if (!this.reactDom) this.reactDom = await this.getReactDom();
|
||||
const React = this.React;
|
||||
window.React = React;
|
||||
this.reactDom.render(component, root);
|
||||
}
|
||||
|
||||
static async getReact() {
|
||||
const getReact = await WebpackModules.getModuleByProps(('createElement', 'cloneElement'));
|
||||
return getReact[0].exports;
|
||||
}
|
||||
|
||||
static async getReactDom() {
|
||||
const getReactDom = await WebpackModules.getModuleByProps(('render', 'findDOMNode'));
|
||||
return getReactDom[0].exports;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = { Renderer };
|
|
@ -0,0 +1,186 @@
|
|||
/**
|
||||
* BetterDiscord Client UI 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 $ = require('jquery');
|
||||
const { Sidebar, SidebarHeader, SidebarItem } = require('./components/sidebar.jsx');
|
||||
const SidebarView = require('./components/sidebarview.jsx');
|
||||
|
||||
const { WebpackModules } = require('../');
|
||||
const React = WebpackModules.getModuleByNameSync('React', true);
|
||||
|
||||
const { Renderer } = require('./renderer.jsx');
|
||||
class UI {
|
||||
|
||||
constructor() {
|
||||
window.jQuery = $;
|
||||
this.visible = false;
|
||||
this.injectButton();
|
||||
}
|
||||
|
||||
async injectButton() {
|
||||
const defer = setInterval(() => {
|
||||
if (!this.titleWrapper.length) return;
|
||||
clearInterval(defer);
|
||||
this.injectCss();
|
||||
this.titleWrapper.append(this.settingsButton = this.createSettingsButton);
|
||||
|
||||
$('body').append($('<div/>', {
|
||||
class: 'bd-settingspanel',
|
||||
id: 'okaythen'
|
||||
}));
|
||||
$('body').append($('<div/>',{
|
||||
class: 'bd-settingspanel-dimmer',
|
||||
id: 'bd-dimmer',
|
||||
click: this.toggleSettings.bind(this)
|
||||
}));
|
||||
|
||||
const items = [
|
||||
<SidebarHeader text="BetterDiscord" />,
|
||||
<SidebarItem text="Core" />,
|
||||
<SidebarItem text="UI"/>
|
||||
];
|
||||
|
||||
Renderer.render(<SidebarView sidebar={<Sidebar>{items}</Sidebar>}/>, document.getElementById('okaythen'));
|
||||
}, 100);
|
||||
}
|
||||
|
||||
toggleSettings() {
|
||||
$('.bd-settingsbutton').toggleClass('active');
|
||||
$('#okaythen').toggleClass('active');
|
||||
$('#bd-dimmer').toggleClass('active');
|
||||
}
|
||||
|
||||
//TODO This is temporary
|
||||
injectCss() {
|
||||
$('head').append($('<style/>', {
|
||||
text: tempcss
|
||||
}));
|
||||
}
|
||||
|
||||
get createSettingsButton() {
|
||||
return $('<div/>', {
|
||||
class: 'bd-settingsbutton',
|
||||
click: this.toggleSettings.bind(this)
|
||||
}).append($('<div/>', {
|
||||
class: 'bd-wordmark'
|
||||
}));
|
||||
}
|
||||
|
||||
get titleWrapper() {
|
||||
return $('body');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = { UI }
|
||||
|
||||
|
||||
var tempcss = `
|
||||
|
||||
.bd-settingspanel-dimmer {
|
||||
background: rgba(0,0,0,.6);
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
top: 22px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
transition: all .5s ease-in-out;
|
||||
z-index: 90000;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.bd-settingspanel-dimmer.active {
|
||||
pointer-events: all;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.bd-settings-button {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 10px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ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MS4ybDAsMS4yYy0yLjcsOTktMjQuMywxODgtNjQuMywyNjQuNmMtMzguNSw3My44LTkzLjgsMTM2LjItMTY0LjYsMTg1LjNjLTIyLjYsMTUuNy00Ni45LDMwLjEtNzIuNiw0My4xaDcyLjVjMzQ2LjIsMS45LDY3MS0xNzEuMiw2NzEtNTY3LjlWNzE2LjdDMTkzMy41LDMxMi4yLDE2MDguNywxMzUuMiwxMjYyLjUsMTM1LjJ6Ii8+PC9nPjwvc3ZnPg==);
|
||||
background-size: 100% 100%;
|
||||
cursor: pointer;
|
||||
filter: grayscale(100%);
|
||||
opacity: .5;
|
||||
transition: all .4s ease-in-out;
|
||||
}
|
||||
|
||||
.bd-settings-button.active,
|
||||
.bd-settings-button:hover {
|
||||
opacity: 1;
|
||||
filter: none;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
.bd-settingspanel {
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
width: 50%;
|
||||
background: #2f3136;
|
||||
z-index: 90001;
|
||||
left: 0;
|
||||
top: 22px;
|
||||
bottom: 0;
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
|
||||
.bd-settingspanel.active {
|
||||
animation: slideanim 1s forwards;
|
||||
}
|
||||
|
||||
.bd-settingsbutton {
|
||||
z-index: 10000;
|
||||
width: 114px;
|
||||
height: 15px;
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
left: 4px;
|
||||
cursor: pointer;
|
||||
-webkit-app-region: no-drag;
|
||||
}
|
||||
|
||||
.bd-wordmark {
|
||||
width: 52px;
|
||||
height: 16px;
|
||||
background-size: 100% 10px;
|
||||
position: absolute;
|
||||
left: 4px;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOTQwIiBoZWlnaHQ9IjE4OC4wMDAwMDAwMDAwMDAwMyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4gPGc+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43MDAwMTIsMGwwLC00OC41MDAwMDRsMjcuNzAwMDEyLDBjMjkuNTk5OTc2LDAgMjkuNTk5OTc2LDQ4LjUwMDAwNCAwLDQ4LjUwMDAwNHoiIGZpbGw9IiMzRTgyRTUiLz4gIDwvZz4gPC9nPjwvc3ZnPg==);
|
||||
filter: grayscale(100%);
|
||||
opacity: .5;
|
||||
transition: all .4s ease-in-out;
|
||||
}
|
||||
|
||||
.bd-settingsbutton.active .bd-wordmark,
|
||||
.bd-settingsbutton:hover .bd-wordmark {
|
||||
filter: none;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
[class^="wordmark"] svg {
|
||||
margin-left: 52px;
|
||||
}
|
||||
|
||||
@keyframes slideanim {
|
||||
50% {
|
||||
transform:translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(-5%);
|
||||
}
|
||||
}
|
||||
`;
|
|
@ -8,30 +8,63 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const KnownModules = {
|
||||
'React': ('createElement', 'cloneElement'),
|
||||
'react-dom': ('render', 'findDOMNode')
|
||||
};
|
||||
|
||||
const Cache = {};
|
||||
|
||||
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];
|
||||
const { exports } = module;
|
||||
static getModuleByNameSync(name, first, fallback) {
|
||||
//TODO return not first from cache?
|
||||
if (Cache.hasOwnProperty(name)) return Cache[name];
|
||||
if (KnownModules.hasOwnProperty(name)) fallback = KnownModules[name];
|
||||
if (!fallback) return null;
|
||||
return Cache[name] = this.getModuleByPropsSync(fallback, first);
|
||||
}
|
||||
|
||||
if (!exports || typeof exports !== 'object') continue;
|
||||
if (!(props in exports)) continue;
|
||||
rm.push(module);
|
||||
// resolve(module);
|
||||
// break;
|
||||
}
|
||||
resolve(rm);
|
||||
reject(null);
|
||||
});
|
||||
static getModuleByPropsSync(props, first) {
|
||||
const modules = this.getAllModulesSync();
|
||||
const rm = [];
|
||||
for (let index in modules) {
|
||||
if (!modules.hasOwnProperty(index)) continue;
|
||||
const module = modules[index];
|
||||
const { exports } = module;
|
||||
|
||||
if (!exports || typeof exports !== 'object') continue;
|
||||
if (!(props in exports)) continue;
|
||||
rm.push(module);
|
||||
}
|
||||
return first ? rm[0].exports : rm;
|
||||
}
|
||||
|
||||
static async getModuleByName(name, first, fallback) {
|
||||
if (Cache.hasOwnProperty(name)) return Cache[name];
|
||||
if (KnownModules.hasOwnProperty(name)) fallback = KnownModules[name];
|
||||
if (!fallback) return null;
|
||||
return Cache[name] = await this.getModuleByProps(fallback, first);
|
||||
}
|
||||
|
||||
static async getModuleByProps(props, first) {
|
||||
const modules = await this.getAllModules();
|
||||
|
||||
const rm = [];
|
||||
for (let index in modules) {
|
||||
if (!modules.hasOwnProperty(index)) continue;
|
||||
const module = modules[index];
|
||||
const { exports } = module;
|
||||
|
||||
if (!exports || typeof exports !== 'object') continue;
|
||||
if (!(props in exports)) continue;
|
||||
rm.push(module);
|
||||
}
|
||||
return first ? rm[0].exports : rm;
|
||||
}
|
||||
|
||||
/*This will most likely not work for most modules*/
|
||||
static async getModuleByName(name) {
|
||||
/* static async getModuleByName(name) {
|
||||
const modules = await this.getAllModules();
|
||||
return new Promise((resolve, reject) => {
|
||||
for (let index in modules) {
|
||||
|
@ -51,6 +84,19 @@ class WebpackModules {
|
|||
|
||||
reject(null);
|
||||
});
|
||||
}*/
|
||||
|
||||
static getAllModulesSync() {
|
||||
const id = 'bd-webpackmodulessync';
|
||||
const __webpack_require__ = window['webpackJsonp'](
|
||||
[],
|
||||
{
|
||||
[id]: (module, exports, __webpack_require__) => exports.default = __webpack_require__
|
||||
},
|
||||
[id]).default;
|
||||
delete __webpack_require__.m[id];
|
||||
delete __webpack_require__.c[id];
|
||||
return __webpack_require__.c;
|
||||
}
|
||||
|
||||
static async getAllModules() {
|
||||
|
|
|
@ -7,7 +7,7 @@ const jsLoader = {
|
|||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
query: {
|
||||
// presets: ['es2015', 'react']
|
||||
presets: ['react']
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue