Skip to content

Commit

Permalink
feat: Watch all active themes when in dev bundle mode (#16748)
Browse files Browse the repository at this point in the history
Allows HMR to work also for themes in the jar-resources, if somebody updates them e.g. using a file watcher
  • Loading branch information
Artur- committed May 5, 2023
1 parent 4321671 commit 747e693
Showing 1 changed file with 12 additions and 6 deletions.
Expand Up @@ -19,6 +19,8 @@

import java.io.File;
import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -61,7 +63,7 @@ private static final class DevModeHandlerAlreadyStartedAttribute

private DevModeHandler devModeHandler;
private BrowserLauncher browserLauncher;
private ThemeLiveUpdater themeLiveUpdater;
private Set<ThemeLiveUpdater> themeLiveUpdaters = new HashSet<>();

@Override
public Class<?>[] getHandlesTypes() {
Expand Down Expand Up @@ -112,10 +114,13 @@ private void startWatchingThemeFolder(VaadinContext context) {
+ "Skipping watching the theme files");
return;
}
String themeName = maybeThemeName.get();
File themeFolder = ThemeUtils.getThemeFolder(
FrontendUtils.getProjectFrontendDir(config), themeName);
themeLiveUpdater = new ThemeLiveUpdater(themeFolder, context);
List<String> activeThemes = ThemeUtils.getActiveThemes(config);
for (String themeName : activeThemes) {
File themeFolder = ThemeUtils.getThemeFolder(
FrontendUtils.getProjectFrontendDir(config), themeName);
themeLiveUpdaters
.add(new ThemeLiveUpdater(themeFolder, context));
}
} catch (Exception e) {
getLogger().error("Failed to start live-reload for theme files", e);
}
Expand All @@ -126,9 +131,10 @@ public void stopDevModeHandler() {
devModeHandler.stop();
devModeHandler = null;
}
if (themeLiveUpdater != null) {
for (ThemeLiveUpdater themeLiveUpdater : themeLiveUpdaters) {
themeLiveUpdater.stop();
}
themeLiveUpdaters.clear();
}

@Override
Expand Down

0 comments on commit 747e693

Please sign in to comment.