diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/atlas/config.go | 5 | ||||
-rw-r--r-- | pkg/atlas/server.go | 36 |
2 files changed, 41 insertions, 0 deletions
diff --git a/pkg/atlas/config.go b/pkg/atlas/config.go index 4300d04..a416ff7 100644 --- a/pkg/atlas/config.go +++ b/pkg/atlas/config.go @@ -145,6 +145,11 @@ type Config struct { // - file:/path/to/mainmenupromos.json API0_MainMenuPromos string `env:"ATLAS_API0_MAINMENUPROMOS=none"` + // If provided, the mainmenupromos will be merged with the provided source + // (same syntax as API0_MAINEMENUPROMOS) if the client is older than the + // API0_MinimumLauncherVersion. + API0_MainMenuPromos_UpdateNeeded string `env:"ATLAS_API0_MAINMENUPROMOS_UPDATENEEDED"` + // The email address to use for Origin login. If not provided, usernames are // not resolved during authentication. If it begins with @, it is treated // as the name of a systemd credential to load. diff --git a/pkg/atlas/server.go b/pkg/atlas/server.go index e780b87..d1f7c7d 100644 --- a/pkg/atlas/server.go +++ b/pkg/atlas/server.go @@ -299,6 +299,9 @@ func NewServer(c *Config) (*Server, error) { } else { return nil, fmt.Errorf("initialize main menu promos: %w", err) } + if err := configureMainMenuPromosUpdateNeeded(c, s.API0); err != nil { + return nil, fmt.Errorf("configure main menu promos when update needed: %w", err) + } if ip2l, err := configureIP2Location(c); err == nil { if ip2l != nil { s.reload = append(s.reload, func() { @@ -685,6 +688,39 @@ func configureMainMenuPromos(c *Config) (func(*http.Request) api0.MainMenuPromos } } +func configureMainMenuPromosUpdateNeeded(c *Config, h *api0.Handler) error { + switch typ, arg, _ := strings.Cut(c.API0_MainMenuPromos_UpdateNeeded, ":"); typ { + case "none": + return nil + case "file": + p, err := filepath.Abs(arg) + if err != nil { + return fmt.Errorf("file: resolve %q: %w", arg, err) + } + fn1 := h.MainMenuPromos + h.MainMenuPromos = func(r *http.Request) api0.MainMenuPromos { + var mmp api0.MainMenuPromos + if fn1 != nil { + mmp = fn1(r) + } + if r == nil || !h.CheckLauncherVersion(r) { + if buf, err1 := os.ReadFile(p); err1 != nil { + err = err1 + } else if err = json.Unmarshal(buf, &mmp); err != nil { + err = err1 + } + } + return mmp + } + if h.MainMenuPromos(nil); err != nil { + return fmt.Errorf("file: %w", err) + } + return nil + default: + return fmt.Errorf("unknown source %q", typ) + } +} + func configureIP2Location(c *Config) (*ip2xMgr, error) { if c.IP2Location == "" { return nil, nil |