minor clean up

* CloudController is now a singleton
This commit is contained in:
Jannik 2019-05-18 13:19:34 +02:00
parent bc36630ef2
commit 2689b03c16
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
4 changed files with 44 additions and 43 deletions

View File

@ -69,7 +69,7 @@ public class Main extends Application {
LOGGER.info("User: " + XMLController.getUserName() + " " + XMLController.getUserHome()); LOGGER.info("User: " + XMLController.getUserName() + " " + XMLController.getUserHome());
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
mainWindowController = new MainWindowController(this); mainWindowController = new MainWindowController();
main = this; main = this;
mainWindow(); mainWindow();
@ -98,7 +98,7 @@ public class Main extends Application {
primaryStage.setScene(scene); // append scene to stage primaryStage.setScene(scene); // append scene to stage
primaryStage.show(); // show stage primaryStage.show(); // show stage
cloudController = new CloudController(mainWindowController); // call cloudController constructor cloudController = CloudController.getInstance(mainWindowController); // call cloudController constructor
// startup checks // startup checks
// check if client_secret.json is present // check if client_secret.json is present

View File

@ -48,6 +48,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.cemu_UI.controller.CloudController;
import com.cemu_UI.controller.DBController; import com.cemu_UI.controller.DBController;
import com.cemu_UI.controller.SmmdbAPIController; import com.cemu_UI.controller.SmmdbAPIController;
import com.cemu_UI.controller.UpdateController; import com.cemu_UI.controller.UpdateController;
@ -176,13 +177,11 @@ public class MainWindowController {
@FXML private JFXTreeTableColumn<CourseTableDataType, Integer> starsColumn = new JFXTreeTableColumn<>("stars"); @FXML private JFXTreeTableColumn<CourseTableDataType, Integer> starsColumn = new JFXTreeTableColumn<>("stars");
@FXML private JFXTreeTableColumn<CourseTableDataType, Integer> timeColumn = new JFXTreeTableColumn<>("time"); @FXML private JFXTreeTableColumn<CourseTableDataType, Integer> timeColumn = new JFXTreeTableColumn<>("time");
private Main main;
private DBController dbController;
private SmmdbAPIController smmdbAPIController;
private playGame playGame;
private static MainWindowController MWC; private static MainWindowController MWC;
private UpdateController updateController;
private XMLController xmlController; private XMLController xmlController;
private DBController dbController;
private playGame playGame;
private SmmdbAPIController smmdbAPIController;
private Stage primaryStage; private Stage primaryStage;
private boolean menuTrue = false; private boolean menuTrue = false;
private boolean playTrue = false; private boolean playTrue = false;
@ -192,7 +191,7 @@ public class MainWindowController {
private String selectedGameTitle; private String selectedGameTitle;
private String id; private String id;
private String version = "0.3.2"; private String version = "0.3.2";
private String buildNumber = "085"; private String buildNumber = "087";
private String versionName = "Purple Comet"; private String versionName = "Purple Comet";
private int selectedUIDataIndex; private int selectedUIDataIndex;
private int selected; private int selected;
@ -222,9 +221,8 @@ public class MainWindowController {
private String yesterday; private String yesterday;
private String never; private String never;
public MainWindowController(Main main) { public MainWindowController() {
xmlController = new XMLController(); xmlController = new XMLController();
this.main = main;
dbController = DBController.getInstance(); dbController = DBController.getInstance();
smmdbAPIController = new SmmdbAPIController(); smmdbAPIController = new SmmdbAPIController();
} }
@ -666,7 +664,7 @@ public class MainWindowController {
smmdbAnchorPane.setVisible(false); smmdbAnchorPane.setVisible(false);
} }
settingsScrollPane.setVisible(!settingsScrollPane.isVisible()); settingsScrollPane.setVisible(!settingsScrollPane.isVisible());
xmlController.saveSettings(); // saving settings to be sure xmlController.saveSettings(); // saving settings to be sureMouseEvent.MOUSE_CLICKED, (event) -> {
} }
@FXML @FXML
@ -745,7 +743,7 @@ public class MainWindowController {
@FXML @FXML
private void updateBtnAction() { private void updateBtnAction() {
updateController = new UpdateController(this, buildNumber, XMLController.isUseBeta()); UpdateController updateController = new UpdateController(this, buildNumber, XMLController.isUseBeta());
Thread updateThread = new Thread(updateController); Thread updateThread = new Thread(updateController);
updateThread.setName("Updater"); updateThread.setName("Updater");
updateThread.start(); updateThread.start();
@ -847,28 +845,25 @@ public class MainWindowController {
XMLController.setCloudService(CloudService.GoogleDrive); XMLController.setCloudService(CloudService.GoogleDrive);
// start cloud sync in new thread // start cloud sync in new thread
Thread thread = new Thread(new Runnable() { Runnable task = () -> {
@Override if (CloudController.getInstance(MWC).initializeConnection(XMLController.getCloudService(),
public void run() { XMLController.getCemuPath())) {
CloudController.getInstance(MWC).sync(XMLController.getCloudService(),
if (main.getCloudController().initializeConnection(XMLController.getCloudService(), XMLController.getCemuPath(), XMLController.getDirCemuUIPath());
XMLController.getCemuPath())) { xmlController.saveSettings();
main.getCloudController().sync(XMLController.getCloudService(), XMLController.getCemuPath(), } else {
XMLController.getDirCemuUIPath()); cloudSyncToggleBtn.setSelected(false);
xmlController.saveSettings();
} else {
cloudSyncToggleBtn.setSelected(false);
// cloud sync init error dialog
JFXInfoAlert cloudSyncErrorDialog = new JFXInfoAlert(
XMLController.getLocalBundle().getString("cloudSyncErrorHeadingText"),
XMLController.getLocalBundle().getString("cloudSyncErrorBodyText"), btnStyle, primaryStage);
cloudSyncErrorDialog.showAndWait();
}
// cloud sync init error dialog
JFXInfoAlert cloudSyncErrorDialog = new JFXInfoAlert(
XMLController.getLocalBundle().getString("cloudSyncErrorHeadingText"),
XMLController.getLocalBundle().getString("cloudSyncErrorBodyText"), btnStyle,
primaryStage);
cloudSyncErrorDialog.showAndWait();
} }
}); };
thread.start();
new Thread(task).start();
}; };
JFXOkayCancelAlert cloudSyncWarningAlert = new JFXOkayCancelAlert( JFXOkayCancelAlert cloudSyncWarningAlert = new JFXOkayCancelAlert(
@ -1128,7 +1123,7 @@ public class MainWindowController {
if (XMLController.isAutoUpdate()) { if (XMLController.isAutoUpdate()) {
try { try {
LOGGER.info("AutoUpdate: looking for updates on startup ..."); LOGGER.info("AutoUpdate: looking for updates on startup ...");
updateController = new UpdateController(this, buildNumber, XMLController.isUseBeta()); UpdateController updateController = new UpdateController(this, buildNumber, XMLController.isUseBeta());
Thread updateThread = new Thread(updateController); Thread updateThread = new Thread(updateController);
updateThread.setName("Updater"); updateThread.setName("Updater");
updateThread.start(); updateThread.start();
@ -1387,10 +1382,6 @@ public class MainWindowController {
return resizedImage; return resizedImage;
} }
public Main getMain() {
return main;
}
public Stage getPrimaryStage() { public Stage getPrimaryStage() {
return primaryStage; return primaryStage;

View File

@ -27,6 +27,7 @@ import java.time.Instant;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.cemu_UI.controller.CloudController;
import com.cemu_UI.controller.DBController; import com.cemu_UI.controller.DBController;
import com.cemu_UI.controller.XMLController; import com.cemu_UI.controller.XMLController;
@ -93,7 +94,7 @@ public class playGame extends Thread {
//sync savegame with cloud service //sync savegame with cloud service
if (XMLController.isCloudSync()) { if (XMLController.isCloudSync()) {
XMLController.setLastLocalSync(Instant.now().getEpochSecond()); XMLController.setLastLocalSync(Instant.now().getEpochSecond());
mainWindowController.getMain().getCloudController().sync(XMLController.getCloudService(), CloudController.getInstance(mainWindowController).sync(XMLController.getCloudService(),
XMLController.getCemuPath(), XMLController.getDirCemuUIPath()); XMLController.getCemuPath(), XMLController.getDirCemuUIPath());
} }

View File

@ -43,15 +43,24 @@ import net.lingala.zip4j.exception.ZipException;
public class CloudController { public class CloudController {
// TODO make singleton // TODO make singleton
private MainWindowController mwc;
private static CloudController instance = null;
private XMLController xmlController = new XMLController();
private GoogleDriveController googleDriveController = new GoogleDriveController();
private static final Logger LOGGER = LogManager.getLogger(CloudController.class.getName());
public CloudController(MainWindowController mwc) { public CloudController(MainWindowController mwc) {
this.mwc = mwc; this.mwc = mwc;
} }
private MainWindowController mwc; public static CloudController getInstance(MainWindowController mwc) {
private XMLController xmlController = new XMLController(); if (instance == null) {
private GoogleDriveController googleDriveController = new GoogleDriveController(); instance = new CloudController(mwc);
private static final Logger LOGGER = LogManager.getLogger(CloudController.class.getName()); }
return instance;
}
public boolean initializeConnection(CloudService cloudService, String cemuDirectory) { public boolean initializeConnection(CloudService cloudService, String cemuDirectory) {
boolean success = false; boolean success = false;