mirror of https://github.com/halo-dev/halo
Remove theme property in theme activated event
parent
31be6e18a7
commit
b4ec2b2318
|
@ -58,9 +58,11 @@ public class FreemarkerConfigAwareListener {
|
||||||
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
|
@Order(Ordered.HIGHEST_PRECEDENCE + 1)
|
||||||
public void onApplicationStartedEvent(ApplicationStartedEvent applicationStartedEvent) {
|
public void onApplicationStartedEvent(ApplicationStartedEvent applicationStartedEvent) {
|
||||||
try {
|
try {
|
||||||
|
configuration.setSharedVariable("theme", themeService.getActivatedTheme());
|
||||||
configuration.setSharedVariable("options", optionsService.listOptions());
|
configuration.setSharedVariable("options", optionsService.listOptions());
|
||||||
configuration.setSharedVariable("user", userService.getCurrentUser().orElse(null));
|
configuration.setSharedVariable("user", userService.getCurrentUser().orElse(null));
|
||||||
configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
|
configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
|
||||||
|
log.info("Initialized freemarker configuration");
|
||||||
} catch (TemplateModelException e) {
|
} catch (TemplateModelException e) {
|
||||||
log.warn("Failed to configure freemarker", e);
|
log.warn("Failed to configure freemarker", e);
|
||||||
// Ignore this error
|
// Ignore this error
|
||||||
|
@ -70,8 +72,10 @@ public class FreemarkerConfigAwareListener {
|
||||||
@Async
|
@Async
|
||||||
@EventListener
|
@EventListener
|
||||||
public void onThemeActivatedEvent(ThemeActivatedEvent themeActivatedEvent) {
|
public void onThemeActivatedEvent(ThemeActivatedEvent themeActivatedEvent) {
|
||||||
|
log.debug("Received theme activated event");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ThemeProperty activatedTheme = themeActivatedEvent.getThemeProperty();
|
ThemeProperty activatedTheme = themeService.getActivatedTheme();
|
||||||
log.debug("Set shared variable theme: [{}]", activatedTheme);
|
log.debug("Set shared variable theme: [{}]", activatedTheme);
|
||||||
configuration.setSharedVariable("theme", activatedTheme);
|
configuration.setSharedVariable("theme", activatedTheme);
|
||||||
Map<String, Object> options = optionService.listOptions();
|
Map<String, Object> options = optionService.listOptions();
|
||||||
|
@ -81,6 +85,7 @@ public class FreemarkerConfigAwareListener {
|
||||||
configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
|
configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
|
||||||
} catch (TemplateModelException e) {
|
} catch (TemplateModelException e) {
|
||||||
log.warn("Failed to configure freemarker", e);
|
log.warn("Failed to configure freemarker", e);
|
||||||
|
// Ignore this error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,21 +13,13 @@ import run.halo.app.handler.theme.config.support.ThemeProperty;
|
||||||
*/
|
*/
|
||||||
public class ThemeActivatedEvent extends ApplicationEvent {
|
public class ThemeActivatedEvent extends ApplicationEvent {
|
||||||
|
|
||||||
private final ThemeProperty themeProperty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ApplicationEvent.
|
* Creates a new ApplicationEvent.
|
||||||
*
|
*
|
||||||
* @param source the object on which the event initially occurred (never {@code null})
|
* @param source the object on which the event initially occurred (never {@code null})
|
||||||
* @param themeProperty theme property must not be null
|
|
||||||
*/
|
*/
|
||||||
public ThemeActivatedEvent(Object source, @NonNull ThemeProperty themeProperty) {
|
public ThemeActivatedEvent(Object source) {
|
||||||
super(source);
|
super(source);
|
||||||
Assert.notNull(themeProperty, "Activated theme property must not be null");
|
|
||||||
this.themeProperty = themeProperty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThemeProperty getThemeProperty() {
|
|
||||||
return themeProperty;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,7 +332,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
clearThemeCache();
|
clearThemeCache();
|
||||||
|
|
||||||
// Publish a theme activated event
|
// Publish a theme activated event
|
||||||
eventPublisher.publishEvent(new ThemeActivatedEvent(this, themeProperty));
|
eventPublisher.publishEvent(new ThemeActivatedEvent(this));
|
||||||
|
|
||||||
return themeProperty;
|
return themeProperty;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue