1
1
// node requirements
2
- const {
3
- dialog, app, BrowserWindow, ipcMain,
4
- } = require ( 'electron' ) ;
2
+ const { dialog, app, BrowserWindow, ipcMain } = require ( 'electron' ) ;
5
3
const fs = require ( 'fs' ) ;
6
4
const path = require ( 'path' ) ;
7
5
const connectSQL = require ( './model/sql-connect' ) ;
@@ -20,9 +18,9 @@ function createWindow() {
20
18
// assign win to an instance of a new browser window.
21
19
win = new BrowserWindow ( {
22
20
// giving our window its width
23
- width : 900 ,
21
+ width : 1920 ,
24
22
// giving our window its hieght
25
- height : 800 ,
23
+ height : 1080 ,
26
24
// specify the path of the icon -- Which icon is this?.. note too tsure --> Ousman
27
25
icon : path . join ( __dirname , 'app/assets/icons/icon.png' ) ,
28
26
// enable node inegreation --> node intgeration, default is usally false --> Ousman
@@ -44,11 +42,16 @@ function createWindow() {
44
42
// read json from settings.json
45
43
fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
46
44
encoding : 'UTF-8' ,
47
- } ) ,
45
+ } )
48
46
) ;
49
47
// reassign state.splash
50
48
state . splash = true ;
51
- fs . writeFileSync ( path . resolve ( __dirname , './user/settings.json' ) , JSON . stringify ( state ) , { encoding : 'UTF-8' } ) ; win = null ;
49
+ fs . writeFileSync (
50
+ path . resolve ( __dirname , './user/settings.json' ) ,
51
+ JSON . stringify ( state ) ,
52
+ { encoding : 'UTF-8' }
53
+ ) ;
54
+ win = null ;
52
55
} ) ;
53
56
}
54
57
@@ -62,11 +65,15 @@ app.on('window-all-closed', () => {
62
65
// read json from settings.json
63
66
fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
64
67
encoding : 'UTF-8' ,
65
- } ) ,
68
+ } )
66
69
) ;
67
70
// reassign state.splash
68
71
state . splash = true ;
69
- fs . writeFileSync ( path . resolve ( __dirname , './user/settings.json' ) , JSON . stringify ( state ) , { encoding : 'UTF-8' } ) ;
72
+ fs . writeFileSync (
73
+ path . resolve ( __dirname , './user/settings.json' ) ,
74
+ JSON . stringify ( state ) ,
75
+ { encoding : 'UTF-8' }
76
+ ) ;
70
77
// process platform is a property that return a string identifying the OS platform on which NodeJs process is running --> Ousman
71
78
if ( process . platform !== 'darwin' ) {
72
79
// quits application
@@ -85,29 +92,33 @@ app.on('activate', () => {
85
92
// Fired by the useEffect hook inside of the Splash.jsx component, this message route will toggle
86
93
// splash property inside of settings.json to false once the Splash page renders itself just once
87
94
ipcMain . on ( 'toggleSplash' , ( message ) => {
88
- //console.log('toggleSplash message received');
95
+ // console.log('toggleSplash message received');
89
96
const state = JSON . parse (
90
97
// read json from settings.json
91
98
fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
92
99
encoding : 'UTF-8' ,
93
- } ) ,
100
+ } )
94
101
) ;
95
102
// reassign state.splash to false
96
103
state . splash = false ;
97
104
98
105
// overwrite settings.json with false splash property
99
- fs . writeFileSync ( path . resolve ( __dirname , './user/settings.json' ) , JSON . stringify ( state ) , { encoding : 'UTF-8' } ) ;
106
+ fs . writeFileSync (
107
+ path . resolve ( __dirname , './user/settings.json' ) ,
108
+ JSON . stringify ( state ) ,
109
+ { encoding : 'UTF-8' }
110
+ ) ;
100
111
101
112
message . returnValue = state . splash ;
102
113
} ) ;
103
114
104
115
ipcMain . on ( 'checkSplash' , ( message ) => {
105
- //sconsole.log('checkSplash message received');
116
+ // sconsole.log('checkSplash message received');
106
117
const state = JSON . parse (
107
118
// read json from settings.json
108
119
fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
109
120
encoding : 'UTF-8' ,
110
- } ) ,
121
+ } )
111
122
) ;
112
123
113
124
message . returnValue = state . splash ;
@@ -116,13 +127,13 @@ ipcMain.on('checkSplash', (message) => {
116
127
// Load settings JSON and returns current setup status back to the render process.
117
128
// ipc 'setup' route --> Ousman
118
129
ipcMain . on ( 'setup' , ( message ) => {
119
- //console.log('setup message received');
130
+ // console.log('setup message received');
120
131
// assigns state to the returned the object returned from settings.json --> Ousman
121
132
const state = JSON . parse (
122
133
// read json from settings.json
123
134
fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
124
135
encoding : 'UTF-8' ,
125
- } ) ,
136
+ } )
126
137
) ;
127
138
// destructure setupRequired from state constant ---> Ousman
128
139
const { setupRequired } = state ;
@@ -137,21 +148,24 @@ ipcMain.on('submit', (message, newService) => {
137
148
const state = JSON . parse (
138
149
fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
139
150
encoding : 'UTF-8' ,
140
- } ) ,
151
+ } )
141
152
) ;
142
153
143
- // Checks if setup is required by checking if the value for the state key 'setupRequired' is true
154
+ // Checks if setup is required by checking if the value for the state key 'setupRequired' is true
144
155
if ( state . setupRequired ) {
145
156
// If setup is required, the value for key 'setupRequired' is reassign to false and the value for key 'services' is reassign to an array with newService as its only element
146
157
state . setupRequired = false ;
147
158
state . services = [ JSON . parse ( newService ) ] ;
148
159
} else {
149
160
// Else the newService is pushed into the services array
150
161
state . services . push ( JSON . parse ( newService ) ) ;
151
- }
162
+ }
152
163
153
164
// Rewrites user/settings.json to show state
154
- fs . writeFileSync ( path . resolve ( __dirname , './user/settings.json' ) , JSON . stringify ( state ) ) ;
165
+ fs . writeFileSync (
166
+ path . resolve ( __dirname , './user/settings.json' ) ,
167
+ JSON . stringify ( state )
168
+ ) ;
155
169
} ) ;
156
170
157
171
// Load settings JSON and returns updated state back to the render process.
@@ -161,7 +175,7 @@ ipcMain.on('dashboard', (message) => {
161
175
const state = JSON . parse (
162
176
fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
163
177
encoding : 'UTF-8' ,
164
- } ) ,
178
+ } )
165
179
) ;
166
180
// destructure services from state... what is services? --> Ousman
167
181
const { services } = state ;
@@ -180,31 +194,36 @@ ipcMain.on('deleteService', (message, index) => {
180
194
let state = JSON . parse (
181
195
fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
182
196
encoding : 'UTF-8' ,
183
- } ) ,
197
+ } )
184
198
) ;
185
199
186
200
// Send a response back with the updated services
187
201
const { splash } = state ;
188
- // Checks if there is more than one services in the services array
202
+ // Checks if there is more than one services in the services array
189
203
if ( state . services . length > 1 ) {
190
- // If true, removes the service at position 'index'
204
+ // If true, removes the service at position 'index'
191
205
state . services . splice ( index , 1 ) ;
192
206
} else {
193
- // Else reassign state to what the user/setting.json file was originally before any database was save
207
+ // Else reassign state to what the user/setting.json file was originally before any database was save
194
208
state = { setupRequired : true , services : [ 'hard' , 'coded' , 'in' ] , splash } ;
195
209
}
196
210
197
211
// Rewrites json from settings.json
198
- fs . writeFileSync ( path . resolve ( __dirname , './user/settings.json' ) , JSON . stringify ( state ) , { encoding : 'UTF-8' } ) ;
212
+ fs . writeFileSync (
213
+ path . resolve ( __dirname , './user/settings.json' ) ,
214
+ JSON . stringify ( state ) ,
215
+ { encoding : 'UTF-8' }
216
+ ) ;
199
217
message . sender . send ( 'deleteResponse' , state . services ) ;
200
218
} ) ;
201
219
202
-
203
220
// Queries the database for communications information and returns it back to the render process.
204
221
ipcMain . on ( 'overviewRequest' , ( message , index ) => {
205
222
console . log ( 'hello from overview request' ) ;
206
223
const { services } = JSON . parse (
207
- fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , { encoding : 'UTF-8' } ) ,
224
+ fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
225
+ encoding : 'UTF-8' ,
226
+ } )
208
227
) ;
209
228
210
229
const databaseType = services [ index ] [ 1 ] ;
@@ -233,14 +252,16 @@ ipcMain.on('overviewRequest', (message, index) => {
233
252
const errorAlert = {
234
253
type : 'error' ,
235
254
title : 'Error in Main process' ,
236
- message : 'Database information could not be retreived. Check that table exists.' ,
255
+ message :
256
+ 'Database information could not be retreived. Check that table exists.' ,
237
257
} ;
238
258
239
259
// after requiring dialog in the topmost section of main. We invoke the method showMessagebox passing the error object we created --> Ousman
240
260
dialog . showMessageBox ( errorAlert ) ;
241
261
242
-
243
- message . sender . send ( JSON . stringify ( 'Database info could not be retreived.' ) ) ;
262
+ message . sender . send (
263
+ JSON . stringify ( 'Database info could not be retreived.' )
264
+ ) ;
244
265
} else {
245
266
console . log ( 'Connected to SQL Database' ) ;
246
267
const queryResults = JSON . stringify ( result . rows ) ;
@@ -256,7 +277,9 @@ ipcMain.on('overviewRequest', (message, index) => {
256
277
ipcMain . on ( 'detailsRequest' , ( message , index ) => {
257
278
console . log ( 'detailsRequest message received' ) ;
258
279
const databaseType = JSON . parse (
259
- fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , { encoding : 'UTF-8' } ) ,
280
+ fs . readFileSync ( path . resolve ( __dirname , './user/settings.json' ) , {
281
+ encoding : 'UTF-8' ,
282
+ } )
260
283
) . services [ index ] [ 1 ] ;
261
284
262
285
if ( databaseType === 'MongoDB' ) {
@@ -267,14 +290,18 @@ ipcMain.on('detailsRequest', (message, index) => {
267
290
const queryResults = JSON . stringify ( data ) ;
268
291
// Asynchronous event emitter used to transmit query results back to the render process.
269
292
message . sender . send ( 'detailsResponse' , queryResults ) ;
293
+ console . log ( 'Message Sent' ) ;
270
294
} ) ;
271
295
}
272
296
273
297
if ( databaseType === 'SQL' ) {
274
298
const getHealth = 'SELECT * FROM healthInfo' ;
275
299
pool . query ( getHealth , ( err , result ) => {
276
300
if ( err ) {
277
- message . sender . send ( 'detailsResponse' , JSON . stringify ( 'Database info could not be retreived.' ) ) ;
301
+ message . sender . send (
302
+ 'detailsResponse' ,
303
+ JSON . stringify ( 'Database info could not be retreived.' )
304
+ ) ;
278
305
}
279
306
const queryResults = JSON . stringify ( result . rows ) ;
280
307
// Asynchronous event emitter used to transmit query results back to the render process.
@@ -283,4 +310,3 @@ ipcMain.on('detailsRequest', (message, index) => {
283
310
} ) ;
284
311
}
285
312
} ) ;
286
-
0 commit comments