From e0f3d26ea109a0f77a4c765f6a161e95537e0f05 Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Thu, 2 Sep 2021 15:48:13 +0200 Subject: [PATCH] Remove dialog on scheduled service error because it locks up the tab somehow --- .../java/ctbrec/ui/CamrecApplication.java | 23 ++++++++++++------- .../java/ctbrec/ui/tabs/ThumbOverviewTab.java | 21 +++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index 9d80fc41..ca40f8d6 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -76,6 +76,7 @@ import ctbrec.ui.tabs.recorded.RecordedTab; import javafx.application.Application; import javafx.application.HostServices; import javafx.application.Platform; +import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Alert; @@ -290,14 +291,7 @@ public class CamrecApplication extends Application { setWindowMinimizeListener(primaryStage); // register changelistener to activate / deactivate tabs, when the user switches between them - tabPane.getSelectionModel().selectedItemProperty().addListener((ov, from, to) -> { - if (from instanceof TabSelectionListener) { - ((TabSelectionListener) from).deselected(); - } - if (to instanceof TabSelectionListener) { - ((TabSelectionListener) to).selected(); - } - }); + tabPane.getSelectionModel().selectedItemProperty().addListener(this::tabChanged); statusBar.getChildren().add(statusLabel); HBox.setMargin(statusLabel, new Insets(10, 10, 10, 10)); @@ -315,6 +309,19 @@ public class CamrecApplication extends Application { } + private void tabChanged(ObservableValue ov, Tab from, Tab to) { + try { + if (from instanceof TabSelectionListener) { + ((TabSelectionListener) from).deselected(); + } + if (to instanceof TabSelectionListener) { + ((TabSelectionListener) to).selected(); + } + } catch (Exception e) { + LOG.error("Error switching tabs", e); + } + } + private void suspendTabUpdates() { tabPane.getTabs().stream() .filter(TabSelectionListener.class::isInstance) diff --git a/client/src/main/java/ctbrec/ui/tabs/ThumbOverviewTab.java b/client/src/main/java/ctbrec/ui/tabs/ThumbOverviewTab.java index 1d4257ca..96edf6c1 100644 --- a/client/src/main/java/ctbrec/ui/tabs/ThumbOverviewTab.java +++ b/client/src/main/java/ctbrec/ui/tabs/ThumbOverviewTab.java @@ -29,7 +29,6 @@ import ctbrec.recorder.Recorder; import ctbrec.sites.Site; import ctbrec.sites.mfc.MyFreeCamsClient; import ctbrec.sites.mfc.MyFreeCamsModel; -import ctbrec.ui.AutosizeAlert; import ctbrec.ui.DesktopIntegration; import ctbrec.ui.SiteUiFactory; import ctbrec.ui.TokenLabel; @@ -61,7 +60,6 @@ import javafx.geometry.Pos; import javafx.scene.Cursor; import javafx.scene.Node; import javafx.scene.Parent; -import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.control.ContextMenu; @@ -471,8 +469,10 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener { var selectedModels = getSelectedThumbCells(cell).stream().map(ThumbCell::getModel).collect(Collectors.toList()); ModelMenuContributor.newContributor(getTabPane(), Config.getInstance(), recorder) .withStartStopCallback(m -> { - getTabPane().setCursor(Cursor.DEFAULT); - getThumbCell(m).ifPresent(ThumbCell::update); + Platform.runLater(() -> { + getTabPane().setCursor(Cursor.DEFAULT); + getThumbCell(m).ifPresent(ThumbCell::update); + }); }) .withFollowCallback( (mdl, fllw, success) -> { if (Boolean.TRUE.equals(fllw) && Boolean.TRUE.equals(success)) { @@ -623,24 +623,15 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener { }; protected void onFail(WorkerStateEvent event) { - if (updatesSuspended) { - return; - } - Alert alert = new AutosizeAlert(Alert.AlertType.ERROR, getTabPane().getScene()); - alert.setTitle("Error"); - alert.setHeaderText("Couldn't fetch model list"); if (event.getSource().getException() != null) { if (event.getSource().getException() instanceof SocketTimeoutException) { LOG.debug("Fetching model list timed out"); - return; } else { - alert.setContentText(event.getSource().getException().getLocalizedMessage()); + LOG.error("Couldn't update model list", event.getSource().getException()); } - LOG.error("Couldn't update model list", event.getSource().getException()); } else { - alert.setContentText(event.getEventType().toString()); + LOG.error("Couldn't update model list {}", event.getEventType()); } - alert.showAndWait(); } void filter() {