Skip to content

Commit

Permalink
Fix dark mode slider switch not disabling dark mode on first try
Browse files Browse the repository at this point in the history
Apparently the preferences property listener I was using doesn't call
the event handler on the first change for some reason. This is a
workaround to change the CSS theme directly from the slider switch.

Needs review and testing! Fixes bisq-network#3447
  • Loading branch information
wiz committed Dec 6, 2019
1 parent d0bed93 commit 864f206
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ public void setUseAnimations(boolean useAnimations) {
this.useAnimationsProperty.set(useAnimations);
}

public void setCssTheme(boolean useDarkMode) {
this.cssThemeProperty.set(useDarkMode == true ? 1 : 0);
public void setCssTheme(int cssTheme) {
this.cssThemeProperty.set(cssTheme);
}

public void addFiatCurrency(FiatCurrency tradeCurrency) {
Expand Down
3 changes: 0 additions & 3 deletions desktop/src/main/java/bisq/desktop/app/BisqApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ private Scene createAndConfigScene(MainView mainView, Injector injector) {
addSceneKeyEventHandler(scene, injector);

Preferences preferences = injector.getInstance(Preferences.class);
preferences.getCssThemeProperty().addListener((ov) -> {
CssTheme.loadSceneStyles(scene, preferences.getCssTheme());
});
CssTheme.loadSceneStyles(scene, preferences.getCssTheme());

return scene;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import bisq.desktop.components.InputTextField;
import bisq.desktop.components.PasswordTextField;
import bisq.desktop.components.TitledGroupBg;
import bisq.desktop.main.MainView;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.util.CssTheme;
import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.ImageUtil;
import bisq.desktop.util.Layout;
Expand Down Expand Up @@ -74,6 +76,7 @@
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.Scene;

import javafx.geometry.HPos;
import javafx.geometry.Insets;
Expand Down Expand Up @@ -794,8 +797,15 @@ private void activateDisplayPreferences() {
useAnimations.setSelected(preferences.isUseAnimations());
useAnimations.setOnAction(e -> preferences.setUseAnimations(useAnimations.isSelected()));

useDarkMode.setSelected(preferences.getCssTheme() == 1);
useDarkMode.setOnAction(e -> preferences.setCssTheme(useDarkMode.isSelected()));
useDarkMode.setSelected(preferences.getCssTheme() == CssTheme.CSS_THEME_DARK);
useDarkMode.setOnAction(e ->
{
int theme = (useDarkMode.isSelected() ? CssTheme.CSS_THEME_DARK : CssTheme.CSS_THEME_LIGHT);
preferences.setCssTheme(theme);

Scene scene = MainView.getRootContainer().getScene();
CssTheme.loadSceneStyles(scene, theme);
});

// useStickyMarketPriceCheckBox.setSelected(preferences.isUseStickyMarketPrice());
// useStickyMarketPriceCheckBox.setOnAction(e -> preferences.setUseStickyMarketPrice(useStickyMarketPriceCheckBox.isSelected()));
Expand Down

0 comments on commit 864f206

Please sign in to comment.