Skip to content

Commit

Permalink
Merge pull request #284 from JsSucks/installer-compliance
Browse files Browse the repository at this point in the history
Installer compliance
  • Loading branch information
Jiiks authored Feb 28, 2019
2 parents 726db7f + b8d16c6 commit d3db696
Show file tree
Hide file tree
Showing 33 changed files with 5,169 additions and 3,357 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ user.config.json
/.vs
/npm-debug.log
/tests/ext/extensions
/tests/userdata
6 changes: 3 additions & 3 deletions client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

import { DOM, BdUI, BdMenu, Modals, Toasts, Notifications, BdContextMenu, DiscordContextMenu } from 'ui';
import BdCss from './styles/index.scss';
import { Events, CssEditor, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, BdWebApi, Connectivity, Cache, Reflection, PackageInstaller } from 'modules';
import { Events, Globals, Settings, Database, Updater, ModuleManager, PluginManager, ThemeManager, ExtModuleManager, Vendor, Patcher, MonkeyPatch, ReactComponents, ReactHelpers, ReactAutoPatcher, DiscordApi, BdWebApi, Connectivity, Cache, Reflection, PackageInstaller } from 'modules';
import { ClientLogger as Logger, ClientIPC, Utils } from 'common';
import { BuiltinManager, EmoteModule, ReactDevtoolsModule, VueDevtoolsModule, TrackingProtection, E2EE } from 'builtin';
import electron from 'electron';
import path from 'path';
import { setTimeout } from 'timers';

const tests = typeof PRODUCTION === 'undefined';
const ignoreExternal = false;
const ignoreExternal = true;

class BetterDiscord {

Expand All @@ -30,7 +30,7 @@ class BetterDiscord {
this._bd = {
DOM, BdUI, BdMenu, Modals, Reflection, Toasts, Notifications, BdContextMenu, DiscordContextMenu,

Events, CssEditor, Globals, Settings, Database, Updater,
Events, Globals, Settings, Database, Updater,
ModuleManager, PluginManager, ThemeManager, ExtModuleManager, PackageInstaller,
Vendor,

Expand Down
8 changes: 8 additions & 0 deletions client/src/modules/csseditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export default new class {
ClientIPC.on('bd-get-scss', () => this.scss, true);
ClientIPC.on('bd-update-scss', (e, scss) => this.updateScss(scss));
ClientIPC.on('bd-save-csseditor-bounds', (e, bounds) => this.saveEditorBounds(bounds));
ClientIPC.on('bd-editor-runScript', (e, script) => {
try {
new Function(script)();
e.reply('ok');
} catch (err) {
e.reply({ err: err.stack || err });
}
});

ClientIPC.on('bd-save-scss', async (e, scss) => {
await this.updateScss(scss);
Expand Down
66 changes: 66 additions & 0 deletions client/src/modules/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* BetterDiscord Editor Module
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* 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.
*/

import Module from './imodule';
import { DOM } from 'ui';

export default new class extends Module {

get name() { return 'Editor' }
get delay() { return false; }

setInitialState(state) {
return {
editorBounds: undefined
};
}

initialize() {
super.initialize();
(async () => {
try {
// TODO this is temporary
const userScss = await this.send('readDataFile', 'user.scss');
const compiled = await this.send('compileSass', { data: userScss });
this.injectStyle('customcss', compiled.css.toString());
} catch (err) {
console.warn('SCSS Compilation error', err);
}
})();
}

events(ipc) {
ipc.on('editor-runScript', (e, script) => {
try {
new Function(script)();
e.reply('ok');
} catch (err) {
e.reply({ err: err.stack || err });
}
});

ipc.on('editor-injectStyle', (e, { id, style }) => {
this.injectStyle(id, style);
e.reply('ok');
});
}

injectStyle(id, style) {
return DOM.injectStyle(style, `userstyle-${id}`);
}

/**
* Show editor, flashes if already visible.
*/
async show() {
await this.send('editor-open', this.state.editorBounds);
}

}
73 changes: 73 additions & 0 deletions client/src/modules/imodule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* 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
*/

import { ClientLogger as Logger, ClientIPC } from 'common';

export default class Module {

constructor(args) {
this.__ = {
state: args || {},
args
};
this.setState = this.setState.bind(this);

if (this.delay) { // If delay is set then module is set to load delayed from modulemanager
this.initialize = this.initialize.bind(this);
this.init = this.initialize;
} else {
this.initialize();
this.init = () => { };
}
}

initialize() {
if (this.bindings) this.bindings();
if (this.setInitialState) this.setState(this.setInitialState(this.state));
if (this.events) this.events(ClientIPC);
}

setState(newState) {
const oldState = this.state;
Object.assign(this.state, newState);
if (this.stateChanged) this.stateChanged(oldState, newState);
}

set args(t) { }
get args() { return this.__.args; }

set state(state) { return this.__.state = state; }
get state() { return this.__.state; }

async send(channel, message) {
return ClientIPC.send(channel, message);
}

log(msg) {
Logger.log(this.name, msg);
}

warn(msg) {
Logger.log(this.name, msg);
}

err(msg) {
Logger.log(this.name, msg);
}

info(msg) {
Logger.log(this.name, msg);
}

}
3 changes: 1 addition & 2 deletions client/src/modules/modulemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

import { ClientLogger as Logger } from 'common';
import { SocketProxy, EventHook, CssEditor } from 'modules';
import { SocketProxy, EventHook } from 'modules';
import { ProfileBadges, ClassNormaliser } from 'ui';
import Updater from './updater';

Expand All @@ -27,7 +27,6 @@ export default class {
new ClassNormaliser(),
new SocketProxy(),
new EventHook(),
CssEditor,
Updater
]);
}
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/modules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as Events } from './events';
export { default as CssEditor } from './csseditor';
export { default as Editor } from './editor';
export { default as Globals } from './globals';
export { default as Settings } from './settings';
export { default as Database } from './database';
Expand Down
Loading

0 comments on commit d3db696

Please sign in to comment.