Skip to content

Commit

Permalink
Fixes #10 - on init change theme if nextTheme is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas authored and farion committed Jun 4, 2023
1 parent 2ea6000 commit bc1f4da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class ThemeSettingsDTO {
private ThemeDTO activeTheme;
private ThemeDTO nextTheme;
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public static synchronized SettingsProvider getInstance() {

private ThemeProvider getActiveTheme() {
if (activeThemeProvider == null) {
if(configDTO.getThemesSettings().getNextTheme() != null) {
configDTO.getThemesSettings().setActiveTheme(configDTO.getThemesSettings().getNextTheme());
configDTO.getThemesSettings().setNextTheme(null);
saveDTO();
}
String activeThemeName = configDTO.getThemesSettings().getActiveTheme().getName();
ArrayList<ThemeProvider> themes = new ArrayList<>(PluginManager.getInstance().getExtensions(ThemeProviderHook.class));
activeThemeProvider = themes.stream().filter(t -> t.getName().equals(activeThemeName)).findFirst().orElse(new LightThemeProvider());
Expand Down Expand Up @@ -127,7 +132,6 @@ public ThemeSettingsDTO getThemeSettings() {
}

public void saveSettings(boolean showRestartRequiredDialog) {
this.activeThemeProvider = null;
saveDTO();
saveToUserDirectory(CSS_FILE_NAME, getActiveTheme().getCss());
ConfigDispatcher.getInstance().onSettingsUpdated(showRestartRequiredDialog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ public ThemeProvider fromString(String string) {

themeComboBox.getSelectionModel().select(themes.
stream()
.filter(t -> t.getName().equals(SettingsProvider.getInstance().getThemeSettings().getActiveTheme().getName()))
.filter(t -> {
if(SettingsProvider.getInstance().getThemeSettings().getNextTheme() != null) {
return t.getName().equals(SettingsProvider.getInstance().getThemeSettings().getNextTheme().getName());
}
return t.getName().equals(SettingsProvider.getInstance().getThemeSettings().getActiveTheme().getName());
})
.findFirst()
.orElse(new LightThemeProvider()));

Expand Down Expand Up @@ -253,7 +258,7 @@ private void saveSettings() {
settings.setSearchUpdates(searchUpdatesCheckbox.isSelected());
ThemeProvider selectedTheme = themeComboBox.getSelectionModel().getSelectedItem();
settings.setSavedLocale(languageComboBox.getSelectionModel().getSelectedItem().getLocale());
SettingsProvider.getInstance().getThemeSettings().setActiveTheme(new ThemeDTO(selectedTheme.getName(), selectedTheme.getIconMode()));
SettingsProvider.getInstance().getThemeSettings().setNextTheme(new ThemeDTO(selectedTheme.getName(), selectedTheme.getIconMode()));
SettingsProvider.getInstance().saveSettings(true);
}

Expand Down

0 comments on commit bc1f4da

Please sign in to comment.