remember volume setting across restarts
This commit is contained in:
@@ -46,6 +46,8 @@ func StartupApp() (*App, error) {
|
||||
if err := a.initMPV(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a.Config.LocalPlayback.Volume = clamp(a.Config.LocalPlayback.Volume, 0, 100)
|
||||
a.Player.SetVolume(a.Config.LocalPlayback.Volume)
|
||||
|
||||
a.ServerManager = NewServerManager()
|
||||
a.PlaybackManager = NewPlaybackManager(a.bgrndCtx, a.ServerManager, a.Player)
|
||||
@@ -91,10 +93,21 @@ func (a *App) LoginToDefaultServer() error {
|
||||
|
||||
func (a *App) Shutdown() {
|
||||
a.Player.Stop()
|
||||
a.Config.LocalPlayback.Volume = a.Player.GetVolume()
|
||||
a.cancel()
|
||||
a.Player.Destroy()
|
||||
a.Config.WriteConfigFile(configPath())
|
||||
}
|
||||
|
||||
func configPath() string {
|
||||
return path.Join(configdir.LocalConfig(AppName), configFile)
|
||||
}
|
||||
|
||||
func clamp(i, min, max int) int {
|
||||
if i < min {
|
||||
i = min
|
||||
} else if i > max {
|
||||
i = max
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
@@ -32,12 +32,17 @@ type PlaylistPageConfig struct {
|
||||
TracklistColumns []string
|
||||
}
|
||||
|
||||
type LocalPlaybackConfig struct {
|
||||
Volume int
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Application AppConfig
|
||||
Servers []*ServerConfig
|
||||
AlbumPage AlbumPageConfig
|
||||
NowPlayingPage NowPlayingPageConfig
|
||||
PlaylistPage PlaylistPageConfig
|
||||
LocalPlayback LocalPlaybackConfig
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
@@ -55,6 +60,9 @@ func DefaultConfig() *Config {
|
||||
PlaylistPage: PlaylistPageConfig{
|
||||
TracklistColumns: []string{"Artist", "Album", "Time", "Plays"},
|
||||
},
|
||||
LocalPlayback: LocalPlaybackConfig{
|
||||
Volume: 100,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user