window size saved to config, smaller font in track-list
This commit is contained in:
@@ -107,6 +107,11 @@ func NewYellowJacketApp(
|
||||
return yjApp, nil
|
||||
}
|
||||
|
||||
// WindowConfig returns the window configuration for use by the host.
|
||||
func (yj *YellowJacketApp) WindowConfig() *config.WindowConfig {
|
||||
return yj.appConfig.Window
|
||||
}
|
||||
|
||||
var startupErr error
|
||||
|
||||
// OnStartup initializes components that require the Wails runtime context.
|
||||
@@ -143,6 +148,23 @@ func (yj *YellowJacketApp) OnStartup(ctx context.Context) {
|
||||
yj.FEBindings = append(yj.FEBindings, yj.player)
|
||||
}
|
||||
|
||||
// OnBeforeClose captures window state while the window is still alive.
|
||||
func (yj *YellowJacketApp) OnBeforeClose(ctx context.Context) bool {
|
||||
w, h := wailsruntime.WindowGetSize(ctx)
|
||||
|
||||
yj.appConfig.Window.Width = w
|
||||
yj.appConfig.Window.Height = h
|
||||
|
||||
if err := yj.appConfig.Save(); err != nil {
|
||||
yj.logger.Error(
|
||||
"Failed to save window state",
|
||||
"err", err,
|
||||
)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// OnShutdown saves player state and cleans up resources before the application exits.
|
||||
func (yj *YellowJacketApp) OnShutdown(_ context.Context) {
|
||||
if yj.player != nil {
|
||||
|
||||
@@ -23,6 +23,8 @@ type Config struct {
|
||||
serveMux *http.ServeMux
|
||||
filePath string // required
|
||||
Library *library.Config `form:"Library" schema:"library,required"`
|
||||
|
||||
Window *WindowConfig `toml:"Window"`
|
||||
}
|
||||
|
||||
// NewConfig creates a new config by loading it from disk.
|
||||
@@ -36,6 +38,7 @@ func NewConfig(logger *slog.Logger) (*Config, error) {
|
||||
filePath: path.Join(confDir, "config.toml"),
|
||||
serveMux: http.NewServeMux(),
|
||||
}
|
||||
conf.applyDefaults()
|
||||
conf.logger = logger.WithGroup("config").With("config", conf)
|
||||
conf.serveMux.HandleFunc("/", conf.handle)
|
||||
|
||||
@@ -99,6 +102,8 @@ func (c *Config) Load() error {
|
||||
return fmt.Errorf("problem parsing config file %s: %w", c.filePath, err)
|
||||
}
|
||||
|
||||
c.applyDefaults()
|
||||
|
||||
// validate the config
|
||||
if err = c.Validate(); err != nil {
|
||||
return fmt.Errorf("invalid config file at %s: %w", c.filePath, err)
|
||||
@@ -130,6 +135,15 @@ func (c *Config) Save() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// applyDefaults ensures all config sections have valid defaults.
|
||||
func (c *Config) applyDefaults() {
|
||||
if c.Window == nil {
|
||||
c.Window = NewDefaultWindowConfig()
|
||||
} else {
|
||||
c.Window.applyDefaults()
|
||||
}
|
||||
}
|
||||
|
||||
// SetContext sets the Wails runtime context for event emission.
|
||||
func (c *Config) SetContext(ctx context.Context) {
|
||||
c.ctx = ctx
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package config
|
||||
|
||||
const (
|
||||
// DefaultWidth is the default window width in pixels.
|
||||
DefaultWidth = 512
|
||||
// DefaultHeight is the default window height in pixels.
|
||||
DefaultHeight = 384
|
||||
)
|
||||
|
||||
// WindowConfig holds window size preferences.
|
||||
type WindowConfig struct {
|
||||
Width int `toml:"Width"`
|
||||
Height int `toml:"Height"`
|
||||
}
|
||||
|
||||
// NewDefaultWindowConfig returns a WindowConfig with sensible defaults.
|
||||
func NewDefaultWindowConfig() *WindowConfig {
|
||||
return &WindowConfig{
|
||||
Width: DefaultWidth,
|
||||
Height: DefaultHeight,
|
||||
}
|
||||
}
|
||||
|
||||
// applyDefaults fills in zero-value fields with defaults.
|
||||
func (w *WindowConfig) applyDefaults() {
|
||||
if w.Width <= 0 {
|
||||
w.Width = DefaultWidth
|
||||
}
|
||||
|
||||
if w.Height <= 0 {
|
||||
w.Height = DefaultHeight
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user