From adbb1bd562fe9f9ba966f2e7b66fd07d8f65ef1f Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Mon, 21 Jun 2021 20:39:55 +0200 Subject: [PATCH] Fix memory leak caused by minimizing to tray --- CHANGELOG.md | 6 +++++- .../main/java/ctbrec/ui/CamrecApplication.java | 16 ++++++++++++++++ .../main/java/ctbrec/ui/DesktopIntegration.java | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c91025ab..ea21a438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +4.4.2 +======================== +* Fixed memory leak caused by minimizing to tray + 4.4.1 ======================== -* Fix camsoda stream URLs +* Fixed camsoda stream URLs 4.4.0 ======================== diff --git a/client/src/main/java/ctbrec/ui/CamrecApplication.java b/client/src/main/java/ctbrec/ui/CamrecApplication.java index aff48d0e..8e345bf6 100644 --- a/client/src/main/java/ctbrec/ui/CamrecApplication.java +++ b/client/src/main/java/ctbrec/ui/CamrecApplication.java @@ -151,6 +151,14 @@ public class CamrecApplication extends Application { LOG.error(ex.getMessage(), ex); } } + if (Objects.equals("stage_restored", evt.get("event"))) { + LOG.debug("Main stage restored"); + Platform.runLater(() -> { + if (tabPane.getSelectionModel().getSelectedItem() instanceof TabSelectionListener) { + ((TabSelectionListener) tabPane.getSelectionModel().getSelectedItem()).selected(); + } + }); + } } }); } @@ -289,8 +297,16 @@ public class CamrecApplication extends Application { primaryStage.iconifiedProperty().addListener((obs, oldV, newV) -> { if (newV.booleanValue() && Config.getInstance().getSettings().minimizeToTray && primaryStage.isShowing()) { DesktopIntegration.minimizeToTray(primaryStage); + suspendTabUpdates(); } }); + + } + + private void suspendTabUpdates() { + tabPane.getTabs().stream() + .filter(TabSelectionListener.class::isInstance) + .forEach(t -> ((TabSelectionListener)t).deselected()); } private javafx.event.EventHandler createShutdownHandler() { diff --git a/client/src/main/java/ctbrec/ui/DesktopIntegration.java b/client/src/main/java/ctbrec/ui/DesktopIntegration.java index 1140116a..c8acb709 100644 --- a/client/src/main/java/ctbrec/ui/DesktopIntegration.java +++ b/client/src/main/java/ctbrec/ui/DesktopIntegration.java @@ -262,6 +262,7 @@ public class DesktopIntegration { stage.setIconified(false); stage.show(); stage.toFront(); + EventBusHolder.BUS.post(Map.of("event", "stage_restored")); }); }