Skip to content

Commit 122036f

Browse files
authored
Merge pull request #180 from JsSucks/configs
Configs
2 parents e1456f5 + a150c3c commit 122036f

30 files changed

Lines changed: 770 additions & 59 deletions

File tree

client/src/modules/contentmanager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default class {
4444
* returns {String}
4545
*/
4646
static get contentPath() {
47-
return this._contentPath ? this._contentPath : (this._contentPath = Globals.getObject('paths').find(path => path.id === this.pathId).path);
47+
return Globals.getPath(this.pathId);
4848
}
4949

5050
/**

client/src/modules/globals.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,16 @@ export default new class extends Module {
6363
return this.state[name];
6464
}
6565

66+
getPath(id) {
67+
return this.state.paths.find(path => path.id === id).path;
68+
}
69+
70+
static get paths() {
71+
return this.state.paths;
72+
}
73+
74+
static get version() {
75+
return this.state.version;
76+
}
77+
6678
}

client/src/modules/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ export default new class Settings {
133133
}
134134

135135
get dataPath() {
136-
return this._dataPath ? this._dataPath : (this._dataPath = Globals.getObject('paths').find(p => p.id === 'data').path);
136+
return Globals.getPath('data');
137137
}
138138
}

client/src/modules/updater.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export default class {
4848
try {
4949
Events.emit('update-check-end');
5050
Logger.info('Updater',
51-
`Latest Version: ${e.version} - Current Version: ${Globals.getObject('version')}`);
52-
if (e.version !== Globals.getObject('version')) {
51+
`Latest Version: ${e.version} - Current Version: ${Globals.version}`);
52+
if (e.version !== Globals.version) {
5353
this.updatesAvailable = true;
5454
Events.emit('updates-available');
5555
}

core/src/main.js

Lines changed: 37 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,41 @@
1111
const path = require('path');
1212
const sass = require('node-sass');
1313

14-
/**
15-
* DEVELOPMENT VARIABLES
16-
*/
17-
const clientScriptPath = path.resolve(__dirname, '..', '..', 'client', 'dist').replace(/\\/g, '/');
18-
19-
const __DEV = {
20-
TESTING: false,
21-
clientScriptPath: `${clientScriptPath}/betterdiscord.client.js`
22-
}
23-
24-
const __dataPath = path.resolve(__dirname, '..', '..', 'tests', 'data');
25-
const __pluginPath = path.resolve(__dirname, '..', '..', 'tests', 'plugins');
26-
const __themePath = path.resolve(__dirname, '..', '..', 'tests', 'themes');
27-
const __modulePath = path.resolve(__dirname, '..', '..', 'tests', 'modules');
28-
29-
const { Utils, FileUtils, BDIpc, Config, WindowUtils, CSSEditor, Database } = require('./modules');
14+
const { FileUtils, BDIpc, Config, WindowUtils, CSSEditor, Database } = require('./modules');
3015
const { BrowserWindow, dialog } = require('electron');
3116

32-
const Common = {};
17+
const tests = true;
18+
const _clientScript = tests
19+
? path.resolve(__dirname, '..', '..', 'client', 'dist', 'betterdiscord.client.js')
20+
: path.resolve(__dirname, 'betterdiscord.client.js');
21+
const _dataPath = tests
22+
? path.resolve(__dirname, '..', '..', 'tests', 'data')
23+
: path.resolve(__dirname, 'data');
24+
const _extPath = tests
25+
? path.resolve(__dirname, '..', '..', 'tests', 'ext')
26+
: path.resolve(__dirname, 'ext');
27+
const _pluginPath = path.resolve(_extPath, 'plugins');
28+
const _themePath = path.resolve(_extPath, 'themes');
29+
const _modulePath = path.resolve(_extPath, 'modules');
30+
31+
const paths = [
32+
{ id: 'cs', path: _clientScript.replace(/\\/g, '/') },
33+
{ id: 'data', path: _dataPath.replace(/\\/g, '/') },
34+
{ id: 'ext', path: _extPath.replace(/\\/g, '/') },
35+
{ id: 'plugins', path: _pluginPath.replace(/\\/g, '/') },
36+
{ id: 'themes', path: _themePath.replace(/\\/g, '/') },
37+
{ id: 'modules', path: _modulePath.replace(/\\/g, '/') }
38+
];
39+
40+
const sparkplug = path.resolve(__dirname, 'sparkplug.js').replace(/\\/g, '/');
3341

34-
const dummyArgs = {
35-
'version': '2.0.0a',
36-
'paths': [
37-
{ 'id': 'base', 'path': 'basePath' },
38-
{ 'id': 'data', 'path': __dataPath },
39-
{ 'id': 'plugins', 'path': __pluginPath },
40-
{ 'id': 'themes', 'path': __themePath },
41-
{ 'id': 'modules', 'path': __modulePath }
42-
]
43-
};
44-
const dbInstance = new Database(dummyArgs.paths.find(path => path.id === 'data').path);
45-
console.log(dummyArgs);
42+
const Common = {};
43+
const globals = {
44+
version: '2.0.0a',
45+
paths
46+
}
4647

48+
const dbInstance = new Database(paths.find(path => path.id === 'data').path);
4749

4850
class Comms {
4951

@@ -120,15 +122,14 @@ class BetterDiscord {
120122

121123
constructor(args) {
122124
if (BetterDiscord.loaded) {
123-
// Creating two BetterDiscord objects???
124125
console.log('Creating two BetterDiscord objects???');
125126
return null;
126127
}
127128
BetterDiscord.loaded = true;
128129

129130
this.injectScripts = this.injectScripts.bind(this);
130131
this.ignite = this.ignite.bind(this);
131-
Common.Config = new Config(args || dummyArgs);
132+
Common.Config = new Config(globals);
132133
this.comms = new Comms(this);
133134
this.init();
134135
}
@@ -139,16 +140,6 @@ class BetterDiscord {
139140

140141
this.csseditor = new CSSEditor(this);
141142

142-
//Log some events for now
143-
//this.windowUtils.webContents.on('did-start-loading', e => this.windowUtils.executeJavascript(`console.info('did-start-loading');`));
144-
//this.windowUtils.webContents.on('did-stop-loading', e => this.windowUtils.executeJavascript(`console.info('did-stop-loading');`));
145-
//this.windowUtils.webContents.on('did-get-response-details', e => this.ignite(this.windowUtils.window));
146-
//this.windowUtils.webContents.on('page-favicon-updated', e => this.windowUtils.executeJavascript(`console.info('page-favicon-updated');`));
147-
//this.windowUtils.webContents.on('will-navigate', e => this.windowUtils.executeJavascript(`console.info('will-navigate');`));
148-
//this.windowUtils.webContents.on('did-navigate', e => this.windowUtils.executeJavascript(`console.info('did-navigate');`));
149-
//this.windowUtils.webContents.on('did-navigate-in-page', e => this.windowUtils.executeJavascript(`console.info('did-navigate-in-page');`));
150-
//this.windowUtils.webContents.on('did-finish-load', e => this.injectScripts(true));
151-
152143
this.windowUtils.events('did-get-response-details', () => this.ignite(this.windowUtils.window));
153144
this.windowUtils.events('did-finish-load', e => this.injectScripts(true));
154145

@@ -157,13 +148,13 @@ class BetterDiscord {
157148
});
158149

159150
setTimeout(() => {
160-
if (__DEV) { this.injectScripts(); }
151+
this.injectScripts();
161152
}, 500);
162153
}
163154

164155
async waitForWindow() {
165156
const self = this;
166-
return new Promise((resolve, reject) => {
157+
return new Promise(resolve => {
167158
const defer = setInterval(() => {
168159
const windows = BrowserWindow.getAllWindows();
169160

@@ -173,13 +164,7 @@ class BetterDiscord {
173164
});
174165
}
175166

176-
if (__DEV && __DEV.TESTING && windows.length > 0) {
177-
resolve(windows[0]);
178-
clearInterval(defer);
179-
return;
180-
}
181-
182-
if (windows.length === 1 && windows[0].webContents.getURL().includes("discordapp.com")) {
167+
if (windows.length === 1 && windows[0].webContents.getURL().includes('discordapp.com')) {
183168
resolve(windows[0]);
184169
clearInterval(defer);
185170
}
@@ -189,15 +174,12 @@ class BetterDiscord {
189174

190175
ignite(window) {
191176
//Hook things that Discord removes from global. These will be removed again in the client script
192-
const sp = path.resolve(__dirname, 'sparkplug.js').replace(/\\/g, '/');
193-
window.webContents.executeJavaScript(`require("${sp}");`);
177+
window.webContents.executeJavaScript(`require("${sparkplug}");`);
194178
}
195179

196180
injectScripts(reload = false) {
197181
console.log(`RELOAD? ${reload}`);
198-
if (__DEV) {
199-
this.windowUtils.injectScript(__DEV.clientScriptPath);
200-
}
182+
this.windowUtils.injectScript(paths.find(path => path.id === 'cs').path);
201183
}
202184

203185
get fileUtils() { return FileUtils; }
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)