From 95df2b93598659c0c726ebc4dd3513ef6c3a1ced Mon Sep 17 00:00:00 2001 From: Jannik Date: Thu, 7 Dec 2017 22:52:32 +0100 Subject: [PATCH] fixed a few cloud sync bugs * fixed a bug where cemu_UI faild to set the correct text to the playBtn * fixed cemu_UI crashing when activationg cloud sync under linux --- .../java/com/cemu_UI/application/Main.java | 3 +- .../application/MainWindowController.java | 37 ++++++++++++------- .../cemu_UI/controller/CloudController.java | 6 +-- .../GoogleDriveController.java | 6 +-- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/cemu_UI/application/Main.java b/src/main/java/com/cemu_UI/application/Main.java index 56a42c4..2e61ea7 100644 --- a/src/main/java/com/cemu_UI/application/Main.java +++ b/src/main/java/com/cemu_UI/application/Main.java @@ -71,7 +71,6 @@ public class Main extends Application { public void start(Stage primaryStage) { try { this.primaryStage = primaryStage; - cloudController = new CloudController(mainWindowController); mainWindow(); initActions(); } catch (Exception e) { @@ -90,6 +89,7 @@ public class Main extends Application { mainWindowController = loader.getController(); // Link of FXMLController and controller class mainWindowController.setMain(this); // call setMain + cloudController = new CloudController(mainWindowController); // call cloudController constructor // get OS and the specific paths if (System.getProperty("os.name").equals("Linux")) { @@ -158,6 +158,7 @@ public class Main extends Application { // loading settings and initialize UI, dbController.main() loads all databases mainWindowController.init(); mainWindowController.dbController.main(); + // if cloud sync is activated start sync if(mainWindowController.isCloudSync()) { cloudController.initializeConnection(mainWindowController.getCloudService(), mainWindowController.getCemuPath()); cloudController.stratupCheck(mainWindowController.getCloudService(), mainWindowController.getCemuPath()); diff --git a/src/main/java/com/cemu_UI/application/MainWindowController.java b/src/main/java/com/cemu_UI/application/MainWindowController.java index 9b96208..6794546 100644 --- a/src/main/java/com/cemu_UI/application/MainWindowController.java +++ b/src/main/java/com/cemu_UI/application/MainWindowController.java @@ -975,21 +975,30 @@ public class MainWindowController { cloudSync = true; //TODO rework for other cloud services cloudService = "GoogleDrive"; + + // start cloud sync in new thread + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + + if (main.cloudController.initializeConnection(getCloudService(), getCemuPath())) { + main.cloudController.sync(getCloudService(), getCemuPath()); + saveSettings(); + } else { + cloudSyncToggleBtn.setSelected(false); - if (main.cloudController.initializeConnection(getCloudService(), getCemuPath())) { - main.cloudController.sync(getCloudService(), getCemuPath()); - saveSettings(); - } else { - cloudSyncToggleBtn.setSelected(false); - - //cloud sync init error dialog - String headingText = "Error while initializing cloud sync!"; - String bodyText = "There was some truble adding your game." - + "\nPlease upload the app.log (which can be found in the cemu_UI directory)" - + "\nto \"https://github.com/Seil0/cemu_UI/issues\" so we can fix this."; - JFXInfoDialog cloudSyncErrorDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 450, 170, main.pane); - cloudSyncErrorDialog.show(); - } + //cloud sync init error dialog + String headingText = "Error while initializing cloud sync!"; + String bodyText = "There was some truble adding your game." + + "\nPlease upload the app.log (which can be found in the cemu_UI directory)" + + "\nto \"https://github.com/Seil0/cemu_UI/issues\" so we can fix this."; + JFXInfoDialog cloudSyncErrorDialog = new JFXInfoDialog(headingText, bodyText, dialogBtnStyle, 450, 170, main.pane); + cloudSyncErrorDialog.show(); + } + + } + }); + thread.start(); } }; diff --git a/src/main/java/com/cemu_UI/controller/CloudController.java b/src/main/java/com/cemu_UI/controller/CloudController.java index 67bbf38..f2db2fd 100644 --- a/src/main/java/com/cemu_UI/controller/CloudController.java +++ b/src/main/java/com/cemu_UI/controller/CloudController.java @@ -54,7 +54,7 @@ public class CloudController { LOGGER.error("error while initialize connection", e); return success; } - success = true; + success = true; } if(cloudService.equals("Dropbox")) { @@ -106,7 +106,7 @@ public class CloudController { @Override public void run() { Platform.runLater(() -> { - mwc.getPlayBtn().setText("syncing..."); // FIXME we get a NullPointerException here, because playBtn dosen't exist + mwc.getPlayBtn().setText("syncing..."); }); LOGGER.info("starting synchronization in new thread ..."); @@ -121,7 +121,7 @@ public class CloudController { } Platform.runLater(() -> { - mwc.getPlayBtn().setText("play"); // FIXME we get a NullPointerException here, because playBtn dosen't exist + mwc.getPlayBtn().setText("play"); mwc.saveSettings(); }); LOGGER.info("synchronization successful!"); diff --git a/src/main/java/com/cemu_UI/vendorCloudController/GoogleDriveController.java b/src/main/java/com/cemu_UI/vendorCloudController/GoogleDriveController.java index 7977c8c..51d55ab 100644 --- a/src/main/java/com/cemu_UI/vendorCloudController/GoogleDriveController.java +++ b/src/main/java/com/cemu_UI/vendorCloudController/GoogleDriveController.java @@ -102,11 +102,7 @@ public class GoogleDriveController { public Credential authorize() throws IOException { // Load client secrets. InputStream in = getClass().getClassLoader().getResourceAsStream("client_secret.json"); - GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); - - //FIXME Linux fails to open a new browser window, application crashes - // see: https://github.com/Seil0/cemu_UI/issues/10 - // Build flow and trigger user authorization request. + GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) .setDataStoreFactory(DATA_STORE_FACTORY) .setAccessType("offline")