Skip to content

Commit 8b73765

Browse files
committed
Fix #745: add option to prevent screensaver on Now Playing page
1 parent 828b5ff commit 8b73765

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

backend/config.go

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type AppConfig struct {
6161
SidebarWidthFraction float64
6262
SidebarTab string
6363

64+
PreventScreensaverOnNowPlayingPage bool
65+
6466
FontNormalTTF string
6567
FontBoldTTF string
6668
UIScaleSize string
@@ -189,29 +191,30 @@ var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists", "Artist
189191
func DefaultConfig(appVersionTag string) *Config {
190192
return &Config{
191193
Application: AppConfig{
192-
WindowWidth: 1000,
193-
WindowHeight: 800,
194-
LastCheckedVersion: appVersionTag,
195-
LastLaunchedVersion: "",
196-
EnableSystemTray: true,
197-
CloseToSystemTray: false,
198-
StartupPage: "Albums",
199-
SettingsTab: "General",
200-
AllowMultiInstance: false,
201-
MaxImageCacheSizeMB: 50,
202-
UIScaleSize: "Normal",
203-
SavePlayQueue: true,
204-
SaveQueueToServer: false,
205-
ShowTrackChangeNotification: false,
206-
EnableLrcLib: true,
207-
EnablePasswordStorage: true,
208-
SkipSSLVerify: false,
209-
EnqueueBatchSize: 100,
210-
Language: "auto",
211-
EnableAutoUpdateChecker: true,
212-
RequestTimeoutSeconds: 15,
213-
EnableOSMediaPlayerAPIs: true,
214-
SidebarWidthFraction: 0.8,
194+
WindowWidth: 1000,
195+
WindowHeight: 800,
196+
LastCheckedVersion: appVersionTag,
197+
LastLaunchedVersion: "",
198+
EnableSystemTray: true,
199+
CloseToSystemTray: false,
200+
StartupPage: "Albums",
201+
SettingsTab: "General",
202+
AllowMultiInstance: false,
203+
MaxImageCacheSizeMB: 50,
204+
UIScaleSize: "Normal",
205+
SavePlayQueue: true,
206+
SaveQueueToServer: false,
207+
ShowTrackChangeNotification: false,
208+
EnableLrcLib: true,
209+
EnablePasswordStorage: true,
210+
SkipSSLVerify: false,
211+
EnqueueBatchSize: 100,
212+
Language: "auto",
213+
EnableAutoUpdateChecker: true,
214+
RequestTimeoutSeconds: 15,
215+
EnableOSMediaPlayerAPIs: true,
216+
SidebarWidthFraction: 0.8,
217+
PreventScreensaverOnNowPlayingPage: false,
215218
},
216219
AlbumPage: AlbumPageConfig{
217220
TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"},

res/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
"Remove from queue": "Remove from queue",
280280
"Play albums": "Play albums",
281281
"Play song radio": "Play song radio",
282+
"Prevent screensaver on Now Playing page": "Prevent screensaver on Now Playing page",
282283
"to": "to",
283284
"by": "by",
284285
"Jan": "Jan",

ui/browsing/router.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type Router struct {
1717
Controller *controller.Controller
1818
Nav NavigationHandler
1919
widgetPool *util.WidgetPool
20+
21+
OnNavigateTo func(controller.Route)
2022
}
2123

2224
func NewRouter(app *backend.App, controller *controller.Controller, nav NavigationHandler) Router {
@@ -63,8 +65,11 @@ func (r Router) CreatePage(rte controller.Route) Page {
6365
return nil
6466
}
6567

66-
func (r Router) NavigateTo(rte controller.Route) {
68+
func (r *Router) NavigateTo(rte controller.Route) {
6769
if rte != r.Nav.CurrentPage() {
6870
r.Nav.SetPage(r.CreatePage(rte))
6971
}
72+
if r.OnNavigateTo != nil {
73+
r.OnNavigateTo(rte)
74+
}
7075
}

ui/dialogs/settingsdialog.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,16 @@ func (s *SettingsDialog) createAdvancedTab() *container.TabItem {
634634
})
635635
osMediaAPIs.Checked = s.config.Application.EnableOSMediaPlayerAPIs
636636

637+
preventScreensaver := widget.NewCheckWithData(lang.L("Prevent screensaver on Now Playing page"),
638+
binding.BindBool(&s.config.Application.PreventScreensaverOnNowPlayingPage))
639+
637640
return container.NewTabItem(lang.L("Advanced"), container.NewVBox(
638641
multi,
639642
sslSkip,
640643
update,
641644
lrclib,
642645
osMediaAPIs,
646+
preventScreensaver,
643647
imgCacheCfg,
644648
))
645649
}

ui/mainwindow.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type MainWindow struct {
5151

5252
// updated when changing servers or libraries
5353
librarySubmenu *fyne.Menu
54+
55+
isScreensaverDisabled bool
5456
}
5557

5658
func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string, app *backend.App) MainWindow {
@@ -156,6 +158,18 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
156158
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.content, m.Window.Canvas()))
157159
m.setInitialSize()
158160

161+
m.Router.OnNavigateTo = func(r controller.Route) {
162+
if r.Page == controller.NowPlayingRoute().Page {
163+
if m.App.Config.Application.PreventScreensaverOnNowPlayingPage && !m.isScreensaverDisabled {
164+
fyne.CurrentApp().Driver().SetDisableScreenBlanking(true)
165+
m.isScreensaverDisabled = true
166+
}
167+
} else if m.isScreensaverDisabled {
168+
fyne.CurrentApp().Driver().SetDisableScreenBlanking(false)
169+
m.isScreensaverDisabled = false
170+
}
171+
}
172+
159173
m.Window.SetCloseIntercept(func() {
160174
m.SaveWindowSettings()
161175
if app.Config.Application.CloseToSystemTray && m.HaveSystemTray() {

0 commit comments

Comments
 (0)