@@ -3,17 +3,21 @@ const path = require('./path2')
33const kleur = require ( 'kleur' ) ;
44const Env = require ( '../env' ) ;
55const { DATA_CONF_PATH } = require ( './Constants' ) ;
6+ const { app } = require ( 'electron' ) ;
67
78class BaseModule
89{
10+ // extensions's configuration file content. Different from app.conf
911 __conf = null ;
12+
1013 window = null ;
1114 tab = null ;
1215 module_name = "" ;
1316 is_active = false ;
1417
1518 constructor ( ) { }
1619
20+ // extension's constructors are called after window creation and after app.ready().
1721 __start ( window , tab )
1822 {
1923 this . window = window ;
@@ -25,10 +29,11 @@ class BaseModule
2529 else
2630 this . conf_file_path = path . joinConfigDir ( this . module_name + '.json' ) ;
2731
28- try { this . __conf = JSON . parse ( fs . readFileSync ( this . conf_file_path , 'utf-8' ) ) ; }
29- catch ( e ) { console . log ( 'Could not load conf file for' , this . module_name , ':' , e , '.' ) ; }
32+ if ( fs . existsSync ( this . conf_file_path ) )
33+ try { this . __conf = JSON . parse ( fs . readFileSync ( this . conf_file_path , 'utf-8' ) ) ; }
34+ catch ( e ) { this . warn ( 'Could not load conf file for' , this . module_name , ':' , e , '.' ) ; }
3035
31- if ( ! this . __conf ) console . log ( '__conf not defined.' ) ;
36+ if ( ! this . __conf ) this . warn ( '__conf not defined.' ) ;
3237 else if ( this . __conf . enabled == false ) return ;
3338
3439 // this.log('Setting up', this.module_name, 'config:', this.__conf, '...');
@@ -38,7 +43,7 @@ class BaseModule
3843 this . log ( '... done' ) ;
3944 }
4045
41- // Colored logging!
46+ // Colored logging! Use this instead of console.log()
4247 log ( ...message )
4348 {
4449 if ( Env . DEBUG_MODE ) console . log ( '[' , kleur . green ( this . module_name ) , ']:' , ...message ) ;
@@ -52,15 +57,44 @@ class BaseModule
5257 if ( Env . DEBUG_MODE ) console . log ( '[' , kleur . red ( this . module_name ) , ']:' , ...message ) ;
5358 }
5459
60+ // sets active status
5561 setActive ( active = true ) { this . is_active = active ; }
5662
63+ // returns active status
5764 isActive ( ) { return this . is_active ; }
5865
59- requireDataConf ( )
66+ // returns module's private folder
67+ appData ( )
68+ {
69+ return path . joinAppData ( this . module_name ) ;
70+ }
71+
72+ // returns module's data folder
73+ joinData ( ...dir )
74+ {
75+ return path . joinDataDir ( this . module_name , ...dir ) ;
76+ }
77+
78+ // returns module's conf folder
79+ joinConf ( ...dir )
6080 {
61- try { this . __data = JSON . parse ( fs . readFileSync ( path . joinAppData ( DATA_CONF_PATH ) ) ) ; }
62- catch ( e ) { console . log ( 'Could not load conf file for' , this . module_name , ':' , e , '.' ) ; }
81+ return path . joinConfigDir ( this . module_name , ...dir ) ;
6382 }
83+
84+ // returns app.conf (config.json) content. Maybe not assigned? check main.js
85+ getAppConfig ( )
86+ {
87+ return app . conf ;
88+ }
89+
90+ //returns app.data (data.json) content
91+ static getDataFile = false ;
92+ getAppData ( )
93+ {
94+ return app . data ;
95+ }
96+
97+ // setup Windows??
6498}
6599
66100module . exports = BaseModule ;
0 commit comments