bootstrap

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package bootstrap wires together the application's startup sequence: loading or interactively creating config, authenticating against Spotify, starting optional librespot playback, and launching the Bubbletea TUI.

Run is the single entry point called from main. The other exported functions (SetupLog, LoadOrSetupConfig, ResolveRuntime, Authenticate, StartLibrespot) are composed by Run but are also individually testable.

Lifetime: Run owns a root context that is cancelled on return, which propagates shutdown to background goroutines started by auth and librespot (token refresh, reconnect transfers).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadOrSetupConfig

func LoadOrSetupConfig(r io.Reader, w io.Writer) (*config.Config, error)

LoadOrSetupConfig loads the config file. If no config exists, it runs first-time setup by prompting the user via the provided reader and writer. Pass nil for r/w to use os.Stdin/os.Stdout.

func Run

func Run() error

Run is the main application entry point. It loads config, authenticates, starts services, and runs the TUI. Returns an error on startup or runtime failure.

The supporting pieces live in sibling files: setup.go (log/config/runtime resolve), auth_session.go (Spotify auth), librespot.go (optional local playback subprocess + audio pipe).

func SetupLog

func SetupLog() func()

SetupLog configures the global logger to write to debug.log in the config directory. Returns a cleanup function that closes the log file. If the log file can't be opened (missing home dir, read-only fs, etc.) the reason is printed to stderr so subsequent debug sessions aren't blind to why log output is missing.

Types

type AuthSession

type AuthSession struct {
	Client    *spotify.Client
	Cleanup   func()
	SaveErrCh <-chan error    // emits token-persistence failures
	RevokedCh <-chan struct{} // fires once if the refresh token is permanently invalid
}

AuthSession holds the result of authentication.

func Authenticate

func Authenticate(ctx context.Context, rc RuntimeConfig) (*AuthSession, error)

Authenticate connects to Spotify and returns a ready-to-use session. If no saved token exists, it runs the interactive login flow. ctx is the parent lifetime — cancelling it aborts login and stops the proactive token-refresh goroutine owned by the returned session.

type LibrespotServices

type LibrespotServices struct {
	Options []ui.ModelOption
	Cleanup func()
}

LibrespotServices holds the result of librespot/audio startup.

func StartLibrespot

func StartLibrespot(ctx context.Context, rc RuntimeConfig, client *spotify.Client) (*LibrespotServices, error)

StartLibrespot starts the librespot process and audio pipe reader if enabled by the config. Returns UI model options and a cleanup function, or an error if librespot was enabled but failed to start. If librespot is not enabled, returns (nil, nil). ctx is the app's root context, used so the reconnect handler's transfer requests are cancellable at shutdown.

type RuntimeConfig

type RuntimeConfig struct {
	*config.Config
	ResolvedRedirectURL string
	ResolvedDeviceName  string
}

RuntimeConfig holds the resolved configuration with defaults applied. ResolvedRedirectURL and ResolvedDeviceName are the final values after applying defaults — use these instead of the raw Config fields.

func ResolveRuntime

func ResolveRuntime(cfg *config.Config) RuntimeConfig

ResolveRuntime applies defaults to the raw config and returns a RuntimeConfig ready for use by the rest of the application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL