Skip to content

Commit

Permalink
add settings option to choose startup page
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Apr 30, 2023
1 parent ae1b767 commit a9263c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions backend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type AppConfig struct {
LastCheckedVersion string
EnableSystemTray bool
CloseToSystemTray bool
StartupPage string

// Experimental - may be removed in future
FontNormalTTF string
Expand Down Expand Up @@ -102,6 +103,8 @@ type Config struct {
ReplayGain ReplayGainConfig
}

var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists"}

func DefaultConfig(appVersionTag string) *Config {
return &Config{
Application: AppConfig{
Expand All @@ -110,6 +113,7 @@ func DefaultConfig(appVersionTag string) *Config {
LastCheckedVersion: appVersionTag,
EnableSystemTray: true,
CloseToSystemTray: false,
StartupPage: "Albums",
},
AlbumPage: AlbumPageConfig{
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"},
Expand Down
11 changes: 9 additions & 2 deletions ui/dialogs/settingsdialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ func NewSettingsDialog(config *backend.Config, audioDeviceList []player.AudioDev
}

func (s *SettingsDialog) createGeneralTab() *container.TabItem {
startupPage := widget.NewSelect(backend.SupportedStartupPages, func(choice string) {
s.config.Application.StartupPage = choice
})
startupPage.SetSelected(s.config.Application.StartupPage)
if startupPage.Selected == "" {
startupPage.SetSelectedIndex(0)
}
closeToTray := widget.NewCheckWithData("Close to system tray",
binding.BindBool(&s.config.Application.CloseToSystemTray))
if !s.config.Application.EnableSystemTray {
Expand Down Expand Up @@ -154,8 +161,8 @@ func (s *SettingsDialog) createGeneralTab() *container.TabItem {
scrobbleEnabled.Checked = s.config.Scrobbling.Enabled

return container.NewTabItem("General", container.NewVBox(
systemTrayEnable,
closeToTray,
container.New(layout.NewFormLayout(), widget.NewLabel("Startup page"), startupPage),
container.NewHBox(systemTrayEnable, closeToTray),
s.newSectionSeparator(),

widget.NewRichText(&widget.TextSegment{Text: "Scrobbling", Style: boldStyle}),
Expand Down
17 changes: 12 additions & 5 deletions ui/mainwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ type MainWindow struct {
container *fyne.Container
}

var (
HomePage = controller.AlbumsRoute()
)

func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.App, size fyne.Size) MainWindow {
m := MainWindow{
App: app,
Expand Down Expand Up @@ -86,7 +82,7 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
})
app.ServerManager.OnServerConnected(func() {
m.BrowsingPane.EnableNavigationButtons()
m.Router.NavigateTo(HomePage)
m.Router.NavigateTo(m.StartupPage())
// check if found new version on startup
if t := app.UpdateChecker.VersionTagFound(); t != "" && t != app.Config.Application.LastCheckedVersion {
if t != app.VersionTag() {
Expand Down Expand Up @@ -129,6 +125,17 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
return m
}

func (m *MainWindow) StartupPage() controller.Route {
switch m.App.Config.Application.StartupPage {
case "Favorites":
return controller.FavoritesRoute()
case "Playlists":
return controller.PlaylistsRoute()
default:
return controller.AlbumsRoute()
}
}

func (m *MainWindow) SetupSystemTrayMenu(appName string, fyneApp fyne.App) {
if desk, ok := fyneApp.(desktop.App); ok {
menu := fyne.NewMenu(appName,
Expand Down

0 comments on commit a9263c8

Please sign in to comment.