|
@@ -9,6 +9,7 @@ import fr.insa.clavardator.ui.dialogs.SnackbarController;
|
9
|
9
|
import fr.insa.clavardator.ui.users.UserListController;
|
10
|
10
|
import fr.insa.clavardator.users.CurrentUser;
|
11
|
11
|
import fr.insa.clavardator.users.UserList;
|
|
12
|
+import fr.insa.clavardator.util.ConfigLoader;
|
12
|
13
|
import fr.insa.clavardator.util.Log;
|
13
|
14
|
import javafx.application.Platform;
|
14
|
15
|
import javafx.fxml.FXML;
|
|
@@ -67,15 +68,15 @@ public class MainController implements Initializable {
|
67
|
68
|
* @param newState The new user state
|
68
|
69
|
*/
|
69
|
70
|
private void onCurrentUserStateChange(CurrentUser.State newState) {
|
70
|
|
- if (newState == CurrentUser.State.VALID)
|
71
|
|
- startChat();
|
72
|
|
- else if (newState != CurrentUser.State.UNINITIALIZED) {
|
73
|
|
- final boolean isError = newState == CurrentUser.State.INVALID;
|
74
|
|
- if (isError) {
|
75
|
|
- endChat();
|
76
|
|
- }
|
77
|
|
- Platform.runLater(() -> showLogin(isError));
|
|
71
|
+ if (newState == CurrentUser.State.VALID)
|
|
72
|
+ startChat();
|
|
73
|
+ else if (newState != CurrentUser.State.UNINITIALIZED) {
|
|
74
|
+ final boolean isError = newState == CurrentUser.State.INVALID;
|
|
75
|
+ if (isError) {
|
|
76
|
+ endChat();
|
78
|
77
|
}
|
|
78
|
+ Platform.runLater(() -> showLogin(isError));
|
|
79
|
+ }
|
79
|
80
|
}
|
80
|
81
|
|
81
|
82
|
/**
|
|
@@ -252,14 +253,21 @@ public class MainController implements Initializable {
|
252
|
253
|
/**
|
253
|
254
|
* Creates database if needed, then init current user, and finally load user list
|
254
|
255
|
*/
|
255
|
|
- private void initDb() {
|
256
|
|
- final DatabaseController db = new DatabaseController();
|
257
|
|
- db.initTables(() -> {
|
258
|
|
- userList.retrievedPreviousUsers(
|
259
|
|
- () -> currentUser.init(this::onInitError),
|
260
|
|
- this::onInitError
|
261
|
|
- );
|
262
|
|
- }, this::onInitError);
|
|
256
|
+ private void initBackend() {
|
|
257
|
+ ConfigLoader.load((ConfigLoader.Config config) -> {
|
|
258
|
+ final String serverUri = config.getServerUri();
|
|
259
|
+ if (serverUri != null) {
|
|
260
|
+ Log.v("INIT", "Found server URI: " + serverUri);
|
|
261
|
+ } else {
|
|
262
|
+ Log.v("INIT", "Server URI not found. Proceeding without");
|
|
263
|
+ }
|
|
264
|
+ final DatabaseController db = new DatabaseController();
|
|
265
|
+ db.initTables(
|
|
266
|
+ () -> userList.retrievedPreviousUsers(
|
|
267
|
+ () -> currentUser.init(this::onInitError),
|
|
268
|
+ this::onInitError
|
|
269
|
+ ), this::onInitError);
|
|
270
|
+ });
|
263
|
271
|
}
|
264
|
272
|
|
265
|
273
|
/**
|
|
@@ -273,6 +281,6 @@ public class MainController implements Initializable {
|
273
|
281
|
listController.setUserList(userList);
|
274
|
282
|
listController.setRefreshUserListener(this::discoverActiveUsers);
|
275
|
283
|
editUserDialogController.setUserList(userList);
|
276
|
|
- initDb();
|
|
284
|
+ initBackend();
|
277
|
285
|
}
|
278
|
286
|
}
|