fix: reload template file

pull/77/head
1379 2 years ago committed by 1379Monitor
parent e566f93fa8
commit 52885988b1

@ -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 {

@ -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
}

@ -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 {

Loading…
Cancel
Save