1111const path = require ( 'path' ) ;
1212const 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' ) ;
3015const { 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
4850class 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 ; }
0 commit comments