Browse Source

minor clean up

* CloudController is now a singleton
pull/7/head
Jannik 3 years ago
parent
commit
2689b03c16
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 4
      src/main/java/com/cemu_UI/application/Main.java
  2. 63
      src/main/java/com/cemu_UI/application/MainWindowController.java
  3. 3
      src/main/java/com/cemu_UI/application/playGame.java
  4. 17
      src/main/java/com/cemu_UI/controller/CloudController.java

4
src/main/java/com/cemu_UI/application/Main.java

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

63
src/main/java/com/cemu_UI/application/MainWindowController.java

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

3
src/main/java/com/cemu_UI/application/playGame.java

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

17
src/main/java/com/cemu_UI/controller/CloudController.java

@ -43,16 +43,25 @@ import net.lingala.zip4j.exception.ZipException;
public class CloudController {
// TODO make singleton
public CloudController(MainWindowController mwc) {
this.mwc = mwc;
}
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) {
this.mwc = mwc;
}
public static CloudController getInstance(MainWindowController mwc) {
if (instance == null) {
instance = new CloudController(mwc);
}
return instance;
}
public boolean initializeConnection(CloudService cloudService, String cemuDirectory) {
boolean success = false;
LOGGER.info("sartting cloud initialisation ...");

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close