diff --git a/event/listener/template_config.go b/event/listener/template_config.go index 22fa12b..6a7a4c0 100644 --- a/event/listener/template_config.go +++ b/event/listener/template_config.go @@ -51,6 +51,7 @@ func NewTemplateConfigListener(bus event.Bus, bus.Subscribe(event.OptionUpdateEventName, t.HandleOptionUpdateEvent) bus.Subscribe(event.StartEventName, t.HandleStartEvent) bus.Subscribe(event.ThemeActivatedEventName, t.HandleThemeUpdateEvent) + bus.Subscribe(event.ThemeFileUpdatedEventName, t.HandleThemeFileUpdateEvent) } func (t *TemplateConfigListener) HandleThemeUpdateEvent(ctx context.Context, themeUpdateEvent event.Event) error { diff --git a/service/impl/theme.go b/service/impl/theme.go index 9f64730..cfa9ebc 100644 --- a/service/impl/theme.go +++ b/service/impl/theme.go @@ -157,7 +157,6 @@ func (t *themeServiceImpl) UpdateThemeFile(ctx context.Context, themeID, absPath if err != nil { return xerr.WithMsg(err, "write to file err") } - t.Event.Publish(ctx, &event.ThemeFileUpdatedEvent{}) return nil } diff --git a/template/template.go b/template/template.go index 6fde0ec..4227e94 100644 --- a/template/template.go +++ b/template/template.go @@ -1,6 +1,7 @@ package template import ( + "context" htmlTemplate "html/template" "io" "io/fs" @@ -13,6 +14,7 @@ import ( "github.com/fsnotify/fsnotify" "go.uber.org/zap" + "github.com/go-sonic/sonic/event" "github.com/go-sonic/sonic/util/xerr" ) @@ -25,13 +27,15 @@ type Template struct { logger *zap.Logger paths []string funcMap map[string]any + bus event.Bus } -func NewTemplate(logger *zap.Logger) *Template { +func NewTemplate(logger *zap.Logger, bus event.Bus) *Template { t := &Template{ sharedVariable: map[string]any{}, logger: logger, funcMap: map[string]any{}, + bus: bus, } t.addUtilFunc() watcher, err := fsnotify.NewWatcher() @@ -44,7 +48,8 @@ func NewTemplate(logger *zap.Logger) *Template { } func (t *Template) Reload(paths []string) error { - return t.Load(paths) + t.bus.Publish(context.Background(), &event.ThemeFileUpdatedEvent{}) + return nil } func (t *Template) Load(paths []string) error {