minor clean up
* CloudController is now a singleton
This commit is contained in:
parent
bc36630ef2
commit
2689b03c16
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -43,15 +43,24 @@ import net.lingala.zip4j.exception.ZipException;
|
||||
public class CloudController {
|
||||
|
||||
// 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) {
|
||||
this.mwc = mwc;
|
||||
}
|
||||
|
||||
private MainWindowController mwc;
|
||||
private XMLController xmlController = new XMLController();
|
||||
private GoogleDriveController googleDriveController = new GoogleDriveController();
|
||||
private static final Logger LOGGER = LogManager.getLogger(CloudController.class.getName());
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user