From 8b73765a7db9bc29a2024f26345849a2d856b5b4 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Mon, 10 Nov 2025 08:12:46 -0800 Subject: [PATCH] Fix #745: add option to prevent screensaver on Now Playing page --- backend/config.go | 49 +++++++++++++++++++----------------- res/translations/en.json | 1 + ui/browsing/router.go | 7 +++++- ui/dialogs/settingsdialog.go | 4 +++ ui/mainwindow.go | 14 +++++++++++ 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/backend/config.go b/backend/config.go index b1facae..4c9091c 100644 --- a/backend/config.go +++ b/backend/config.go @@ -61,6 +61,8 @@ type AppConfig struct { SidebarWidthFraction float64 SidebarTab string + PreventScreensaverOnNowPlayingPage bool + FontNormalTTF string FontBoldTTF string UIScaleSize string @@ -189,29 +191,30 @@ var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists", "Artist func DefaultConfig(appVersionTag string) *Config { return &Config{ Application: AppConfig{ - WindowWidth: 1000, - WindowHeight: 800, - LastCheckedVersion: appVersionTag, - LastLaunchedVersion: "", - EnableSystemTray: true, - CloseToSystemTray: false, - StartupPage: "Albums", - SettingsTab: "General", - AllowMultiInstance: false, - MaxImageCacheSizeMB: 50, - UIScaleSize: "Normal", - SavePlayQueue: true, - SaveQueueToServer: false, - ShowTrackChangeNotification: false, - EnableLrcLib: true, - EnablePasswordStorage: true, - SkipSSLVerify: false, - EnqueueBatchSize: 100, - Language: "auto", - EnableAutoUpdateChecker: true, - RequestTimeoutSeconds: 15, - EnableOSMediaPlayerAPIs: true, - SidebarWidthFraction: 0.8, + WindowWidth: 1000, + WindowHeight: 800, + LastCheckedVersion: appVersionTag, + LastLaunchedVersion: "", + EnableSystemTray: true, + CloseToSystemTray: false, + StartupPage: "Albums", + SettingsTab: "General", + AllowMultiInstance: false, + MaxImageCacheSizeMB: 50, + UIScaleSize: "Normal", + SavePlayQueue: true, + SaveQueueToServer: false, + ShowTrackChangeNotification: false, + EnableLrcLib: true, + EnablePasswordStorage: true, + SkipSSLVerify: false, + EnqueueBatchSize: 100, + Language: "auto", + EnableAutoUpdateChecker: true, + RequestTimeoutSeconds: 15, + EnableOSMediaPlayerAPIs: true, + SidebarWidthFraction: 0.8, + PreventScreensaverOnNowPlayingPage: false, }, AlbumPage: AlbumPageConfig{ TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"}, diff --git a/res/translations/en.json b/res/translations/en.json index a67d69b..9241ad7 100644 --- a/res/translations/en.json +++ b/res/translations/en.json @@ -279,6 +279,7 @@ "Remove from queue": "Remove from queue", "Play albums": "Play albums", "Play song radio": "Play song radio", + "Prevent screensaver on Now Playing page": "Prevent screensaver on Now Playing page", "to": "to", "by": "by", "Jan": "Jan", diff --git a/ui/browsing/router.go b/ui/browsing/router.go index 601a68f..c127aa8 100644 --- a/ui/browsing/router.go +++ b/ui/browsing/router.go @@ -17,6 +17,8 @@ type Router struct { Controller *controller.Controller Nav NavigationHandler widgetPool *util.WidgetPool + + OnNavigateTo func(controller.Route) } func NewRouter(app *backend.App, controller *controller.Controller, nav NavigationHandler) Router { @@ -63,8 +65,11 @@ func (r Router) CreatePage(rte controller.Route) Page { return nil } -func (r Router) NavigateTo(rte controller.Route) { +func (r *Router) NavigateTo(rte controller.Route) { if rte != r.Nav.CurrentPage() { r.Nav.SetPage(r.CreatePage(rte)) } + if r.OnNavigateTo != nil { + r.OnNavigateTo(rte) + } } diff --git a/ui/dialogs/settingsdialog.go b/ui/dialogs/settingsdialog.go index aba1b4e..a45419f 100644 --- a/ui/dialogs/settingsdialog.go +++ b/ui/dialogs/settingsdialog.go @@ -634,12 +634,16 @@ func (s *SettingsDialog) createAdvancedTab() *container.TabItem { }) osMediaAPIs.Checked = s.config.Application.EnableOSMediaPlayerAPIs + preventScreensaver := widget.NewCheckWithData(lang.L("Prevent screensaver on Now Playing page"), + binding.BindBool(&s.config.Application.PreventScreensaverOnNowPlayingPage)) + return container.NewTabItem(lang.L("Advanced"), container.NewVBox( multi, sslSkip, update, lrclib, osMediaAPIs, + preventScreensaver, imgCacheCfg, )) } diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 1f5dfba..9e580a5 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -51,6 +51,8 @@ type MainWindow struct { // updated when changing servers or libraries librarySubmenu *fyne.Menu + + isScreensaverDisabled bool } 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, m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.content, m.Window.Canvas())) m.setInitialSize() + m.Router.OnNavigateTo = func(r controller.Route) { + if r.Page == controller.NowPlayingRoute().Page { + if m.App.Config.Application.PreventScreensaverOnNowPlayingPage && !m.isScreensaverDisabled { + fyne.CurrentApp().Driver().SetDisableScreenBlanking(true) + m.isScreensaverDisabled = true + } + } else if m.isScreensaverDisabled { + fyne.CurrentApp().Driver().SetDisableScreenBlanking(false) + m.isScreensaverDisabled = false + } + } + m.Window.SetCloseIntercept(func() { m.SaveWindowSettings() if app.Config.Application.CloseToSystemTray && m.HaveSystemTray() {