From 76820377ae2c694b2b312e57ebc73b6246a6a96d Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 8 Dec 2020 17:24:22 +0200 Subject: [PATCH] change theme on all app windows --- .../com/sparrowwallet/sparrow/AppController.java | 12 +++++++++--- .../sparrow/event/ThemeChangedEvent.java | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/sparrowwallet/sparrow/event/ThemeChangedEvent.java diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index dc009033..57c35261 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -1014,10 +1014,16 @@ public class AppController implements Initializable { Config.get().setTheme(selectedTheme); } - if(selectedTheme == Theme.DARK) { - tabs.getScene().getStylesheets().add(getClass().getResource("darktheme.css").toExternalForm()); + EventManager.get().post(new ThemeChangedEvent(selectedTheme)); + } + + @Subscribe + public void themeChanged(ThemeChangedEvent event) { + String darkCss = getClass().getResource("darktheme.css").toExternalForm(); + if(event.getTheme() == Theme.DARK && !tabs.getScene().getStylesheets().contains(darkCss)) { + tabs.getScene().getStylesheets().add(darkCss); } else { - tabs.getScene().getStylesheets().remove(getClass().getResource("darktheme.css").toExternalForm()); + tabs.getScene().getStylesheets().remove(darkCss); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/event/ThemeChangedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/ThemeChangedEvent.java new file mode 100644 index 00000000..3970fd58 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/ThemeChangedEvent.java @@ -0,0 +1,15 @@ +package com.sparrowwallet.sparrow.event; + +import com.sparrowwallet.sparrow.Theme; + +public class ThemeChangedEvent { + private final Theme theme; + + public ThemeChangedEvent(Theme theme) { + this.theme = theme; + } + + public Theme getTheme() { + return theme; + } +}