@@ -11,7 +11,7 @@ import * as React from "react";
11
11
import Dropzone from "react-dropzone" ;
12
12
import { shell , ipcRenderer } from "electron" ;
13
13
import { Redirect } from "react-router" ;
14
- import { isValidServerConfig , isValidClientConfig } from "@renderer/helpers/utils" ;
14
+ import { isValidServerConfig , isValidClientConfig , checkFirebaseUrl , invokeMain } from "@renderer/helpers/utils" ;
15
15
import "./PreDashboardView.css" ;
16
16
import { Config } from "@server/databases/server/entity" ;
17
17
@@ -27,6 +27,7 @@ interface State {
27
27
enableNgrok : boolean ;
28
28
showModal : boolean ;
29
29
serverUrl : string ;
30
+ smsSupport : boolean ;
30
31
}
31
32
32
33
class PreDashboardView extends React . Component < unknown , State > {
@@ -45,7 +46,8 @@ class PreDashboardView extends React.Component<unknown, State> {
45
46
inputPassword : "" ,
46
47
enableNgrok : true ,
47
48
showModal : false ,
48
- serverUrl : ""
49
+ serverUrl : "" ,
50
+ smsSupport : false
49
51
} ;
50
52
}
51
53
@@ -147,25 +149,29 @@ class PreDashboardView extends React.Component<unknown, State> {
147
149
const binaryStr = reader . result ;
148
150
const valid = isValidServerConfig ( binaryStr as string ) ;
149
151
const validClient = isValidClientConfig ( binaryStr as string ) ;
152
+ const jsonData = JSON . parse ( binaryStr as string ) ;
150
153
151
154
if ( valid ) {
152
- ipcRenderer . invoke ( "set-fcm-server" , JSON . parse ( binaryStr as string ) ) ;
155
+ ipcRenderer . invoke ( "set-fcm-server" , jsonData ) ;
153
156
this . setState ( { fcmServer : binaryStr } ) ;
154
157
} else if ( validClient ) {
155
- ipcRenderer . invoke ( "set-fcm-client" , JSON . parse ( binaryStr as string ) ) ;
156
- this . setState ( { fcmClient : binaryStr } ) ;
157
-
158
- this . invokeMain ( "show-dialog" , {
159
- type : "warning" ,
160
- buttons : [ "OK" ] ,
161
- title : "BlueBubbles Warning" ,
162
- message : "We've corrected a mistake you made" ,
163
- detail :
164
- `The file you chose was for the FCM Client configuration and ` +
165
- `we've saved it as such. Now, please choose the correct server configuration.`
166
- } ) ;
158
+ const test = checkFirebaseUrl ( jsonData ) ;
159
+ if ( test ) {
160
+ ipcRenderer . invoke ( "set-fcm-client" , jsonData ) ;
161
+ this . setState ( { fcmClient : binaryStr } ) ;
162
+
163
+ invokeMain ( "show-dialog" , {
164
+ type : "warning" ,
165
+ buttons : [ "OK" ] ,
166
+ title : "BlueBubbles Warning" ,
167
+ message : "We've corrected a mistake you made" ,
168
+ detail :
169
+ `The file you chose was for the FCM Client configuration and ` +
170
+ `we've saved it as such. Now, please choose the correct server configuration.`
171
+ } ) ;
172
+ }
167
173
} else {
168
- this . invokeMain ( "show-dialog" , {
174
+ invokeMain ( "show-dialog" , {
169
175
type : "error" ,
170
176
buttons : [ "OK" ] ,
171
177
title : "BlueBubbles Error" ,
@@ -178,10 +184,6 @@ class PreDashboardView extends React.Component<unknown, State> {
178
184
reader . readAsText ( acceptedFiles [ 0 ] ) ;
179
185
} ;
180
186
181
- async invokeMain ( event : string , args : any ) : Promise < any > {
182
- return ipcRenderer . invoke ( event , args ) ;
183
- }
184
-
185
187
handleClientFile = ( acceptedFiles : any ) => {
186
188
const reader = new FileReader ( ) ;
187
189
@@ -192,25 +194,19 @@ class PreDashboardView extends React.Component<unknown, State> {
192
194
const binaryStr = reader . result ;
193
195
const valid = isValidClientConfig ( binaryStr as string ) ;
194
196
const validServer = isValidServerConfig ( binaryStr as string ) ;
197
+ const jsonData = JSON . parse ( binaryStr as string ) ;
195
198
196
199
if ( valid ) {
197
- ipcRenderer . invoke ( "set-fcm-client" , JSON . parse ( binaryStr as string ) ) ;
198
- this . setState ( { fcmClient : binaryStr } ) ;
200
+ const test = checkFirebaseUrl ( jsonData ) ;
201
+ if ( test ) {
202
+ ipcRenderer . invoke ( "set-fcm-client" , jsonData ) ;
203
+ this . setState ( { fcmClient : binaryStr } ) ;
204
+ }
199
205
} else if ( validServer ) {
200
206
ipcRenderer . invoke ( "set-fcm-server" , JSON . parse ( binaryStr as string ) ) ;
201
207
this . setState ( { fcmServer : binaryStr } ) ;
202
-
203
- this . invokeMain ( "show-dialog" , {
204
- type : "warning" ,
205
- buttons : [ "OK" ] ,
206
- title : "BlueBubbles Warning" ,
207
- message : "We've corrected a mistake you made" ,
208
- detail :
209
- `The file you chose was for the FCM Server configuration and ` +
210
- `we've saved it as such. Now, please choose the correct client configuration.`
211
- } ) ;
212
208
} else {
213
- this . invokeMain ( "show-dialog" , {
209
+ invokeMain ( "show-dialog" , {
214
210
type : "error" ,
215
211
buttons : [ "OK" ] ,
216
212
title : "BlueBubbles Error" ,
@@ -228,7 +224,6 @@ class PreDashboardView extends React.Component<unknown, State> {
228
224
}
229
225
230
226
completeTutorial ( ) {
231
- console . log ( this . state ) ;
232
227
ipcRenderer . invoke ( "toggle-tutorial" , true ) ;
233
228
this . setState ( { redirect : "/dashboard" } ) ;
234
229
}
@@ -237,11 +232,19 @@ class PreDashboardView extends React.Component<unknown, State> {
237
232
this . setState ( { [ e . target . name ] : e . target . value } as any ) ;
238
233
} ;
239
234
240
- handleNgrokCheckboxChange ( e : React . ChangeEvent < HTMLInputElement > ) {
241
- this . setState ( { enableNgrok : e . target . checked } ) ;
242
- ipcRenderer . invoke ( "toggle-ngrok" , e . target . checked ) ;
243
- if ( ! e . target . checked ) {
244
- this . setState ( { showModal : true } ) ;
235
+ handleCheckboxChange ( e : React . ChangeEvent < HTMLInputElement > , stateVar : string ) {
236
+ this . setState ( { [ stateVar ] : e . target . checked } as any ) ;
237
+
238
+ if ( e . target . id === "toggleNgrok" ) {
239
+ ipcRenderer . invoke ( "toggle-ngrok" , e . target . checked ) ;
240
+
241
+ if ( ! e . target . checked ) {
242
+ this . setState ( { showModal : true } ) ;
243
+ }
244
+ } else {
245
+ ipcRenderer . invoke ( "set-config" , {
246
+ [ e . target . id ] : e . target . checked
247
+ } ) ;
245
248
}
246
249
}
247
250
@@ -358,7 +361,19 @@ class PreDashboardView extends React.Component<unknown, State> {
358
361
< input
359
362
id = "toggleNgrok"
360
363
checked = { this . state . enableNgrok }
361
- onChange = { e => this . handleNgrokCheckboxChange ( e ) }
364
+ onChange = { e => this . handleCheckboxChange ( e , "enableNgrok" ) }
365
+ type = "checkbox"
366
+ />
367
+ < i />
368
+ </ div >
369
+ </ div >
370
+ < div id = "setNgrokContainer" >
371
+ < h3 > SMS Support (Android Client): </ h3 >
372
+ < div style = { { marginTop : "3px" } } >
373
+ < input
374
+ id = "sms_support"
375
+ checked = { this . state . smsSupport }
376
+ onChange = { e => this . handleCheckboxChange ( e , "smsSupport" ) }
362
377
type = "checkbox"
363
378
/>
364
379
< i />
0 commit comments