Skip to content

Commit

Permalink
Add hook to re/unload UI assets
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Apr 24, 2020
1 parent d2d6913 commit 5c7739e
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion ui/module.go
@@ -1,13 +1,51 @@
package ui

import (
"context"

resources "github.com/cookieo9/resources-go"
"github.com/safing/portbase/log"
"github.com/safing/portbase/modules"
)

const (
eventReload = "reload"
)

var (
module *modules.Module
)

func init() {
modules.Register("ui", prep, nil, nil, "api", "updates")
module = modules.Register("ui", prep, start, nil, "api", "updates")
}

func prep() error {
module.RegisterEvent(eventReload)

return registerRoutes()
}

func start() error {
return module.RegisterEventHook("ui", eventReload, "reload assets", reloadUI)
}

func reloadUI(ctx context.Context, _ interface{}) error {
log.Info("core: user/UI requested UI reload")

appsLock.Lock()
defer appsLock.Unlock()

// close all bundles
for id, bundle := range apps {
err := bundle.Close()
if err != nil {
log.Warningf("ui: failed to close bundle %s: %s", id, err)
}
}

// reset index
apps = make(map[string]*resources.BundleSequence)

return nil
}

0 comments on commit 5c7739e

Please sign in to comment.