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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,5 @@ func main() {
|
||||
fyneApp.Run()
|
||||
|
||||
// shutdown tasks
|
||||
myApp.Config.WriteConfigFile(configPath())
|
||||
myApp.Shutdown()
|
||||
}
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ func NewBottomPanel(p *player.Player, nav func(browsing.Route)) *BottomPanel {
|
||||
p.Seek(fmt.Sprintf("%d", int(f*100)), player.SeekAbsolutePercent)
|
||||
})
|
||||
|
||||
bp.AuxControls = widgets.NewAuxControls()
|
||||
bp.AuxControls = widgets.NewAuxControls(p.GetVolume())
|
||||
bp.AuxControls.VolumeControl.OnVolumeChanged = func(v int) {
|
||||
_ = p.SetVolume(v)
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ type AuxControls struct {
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewAuxControls() *AuxControls {
|
||||
func NewAuxControls(initialVolume int) *AuxControls {
|
||||
a := &AuxControls{
|
||||
VolumeControl: NewVolumeControl(),
|
||||
VolumeControl: NewVolumeControl(initialVolume),
|
||||
}
|
||||
a.container = container.NewHBox(layout.NewSpacer(), a.VolumeControl)
|
||||
return a
|
||||
@@ -97,16 +97,16 @@ type VolumeControl struct {
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewVolumeControl() *VolumeControl {
|
||||
func NewVolumeControl(initialVol int) *VolumeControl {
|
||||
v := &VolumeControl{}
|
||||
v.ExtendBaseWidget(v)
|
||||
v.icon = newTappableIcon(theme.VolumeUpIcon())
|
||||
v.icon.OnTapped = v.toggleMute
|
||||
v.slider = NewVolumeSlider(100)
|
||||
v.lastVol = 100
|
||||
v.lastVol = initialVol
|
||||
v.slider.Step = 1
|
||||
v.slider.Orientation = widget.Horizontal
|
||||
v.slider.Value = 100
|
||||
v.slider.Value = float64(v.lastVol)
|
||||
v.slider.OnChanged = v.onChanged
|
||||
v.container = container.NewHBox(container.NewCenter(v.icon), v.slider)
|
||||
return v
|
||||
|
||||
Reference in New Issue
Block a user