From af1ae4641edbd048493738742bae11386e9f94b6 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Mon, 26 May 2025 17:17:00 -0700 Subject: [PATCH] Add setting to disable OS media player APIs --- backend/app.go | 22 +++++++++++++--------- backend/config.go | 2 ++ main.go | 16 +++++++++------- res/translations/en.json | 1 + ui/dialogs/settingsdialog.go | 7 +++++++ 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/backend/app.go b/backend/app.go index 9e0183c..86ace5c 100644 --- a/backend/app.go +++ b/backend/app.go @@ -191,14 +191,16 @@ func StartupApp(appName, displayAppName, appVersion, appVersionTag, latestReleas } // OS media center integrations - // Linux MPRIS - a.setupMPRIS(displayAppName) - // MacOS MPNowPlayingInfoCenter - InitMPMediaHandler(a.PlaybackManager, func(id string) (string, error) { - a.ImageManager.GetCoverThumbnail(id) // ensure image is cached locally - return a.ImageManager.GetCoverArtUrl(id) - }) - // Windows SMTC is initialized from main once we have a window HWND. + if a.Config.Application.EnableOSMediaPlayerAPIs { + // Linux MPRIS + a.setupMPRIS(displayAppName) + // MacOS MPNowPlayingInfoCenter + InitMPMediaHandler(a.PlaybackManager, func(id string) (string, error) { + a.ImageManager.GetCoverThumbnail(id) // ensure image is cached locally + return a.ImageManager.GetCoverArtUrl(id) + }) + // Windows SMTC is initialized from main once we have a window HWND. + } a.startConfigWriter(a.bgrndCtx) @@ -458,7 +460,9 @@ func (a *App) Shutdown() { if a.ipcServer != nil { a.ipcServer.Shutdown(a.bgrndCtx) } - a.MPRISHandler.Shutdown() + if a.MPRISHandler != nil { + a.MPRISHandler.Shutdown() + } if a.WinSMTC != nil { a.WinSMTC.Shutdown() } diff --git a/backend/config.go b/backend/config.go index 02d7f5b..9edccc6 100644 --- a/backend/config.go +++ b/backend/config.go @@ -55,6 +55,7 @@ type AppConfig struct { DisableDPIDetection bool EnableAutoUpdateChecker bool RequestTimeoutSeconds int + EnableOSMediaPlayerAPIs bool FontNormalTTF string FontBoldTTF string @@ -192,6 +193,7 @@ func DefaultConfig(appVersionTag string) *Config { Language: "auto", EnableAutoUpdateChecker: true, RequestTimeoutSeconds: 15, + EnableOSMediaPlayerAPIs: true, }, AlbumPage: AlbumPageConfig{ TracklistColumns: []string{"Artist", "Time", "Plays", "Favorite", "Rating"}, diff --git a/main.go b/main.go index 4cfa1c3..e5ec0f5 100644 --- a/main.go +++ b/main.go @@ -91,13 +91,15 @@ func main() { mainWindow.Controller.DoConnectToServerWorkflow(defaultServer) } - mainWindow.Window.(driver.NativeWindow).RunNative(func(ctx any) { - // intialize Windows SMTC - if runtime.GOOS == "windows" { - hwnd := ctx.(driver.WindowsWindowContext).HWND - myApp.SetupWindowsSMTC(hwnd) - } - }) + if myApp.Config.Application.EnableOSMediaPlayerAPIs { + mainWindow.Window.(driver.NativeWindow).RunNative(func(ctx any) { + // intialize Windows SMTC + if runtime.GOOS == "windows" { + hwnd := ctx.(driver.WindowsWindowContext).HWND + myApp.SetupWindowsSMTC(hwnd) + } + }) + } }) fyneApp.Lifecycle().SetOnEnteredForeground(windowStartupTasks) diff --git a/res/translations/en.json b/res/translations/en.json index 22617a8..1ced3f4 100644 --- a/res/translations/en.json +++ b/res/translations/en.json @@ -76,6 +76,7 @@ "Edit Playlist": "Edit Playlist", "Edit server": "Edit server", "Enable LrcLib lyrics fetcher": "Enable LrcLib lyrics fetcher", + "Enable OS media player integration": "Enable OS media player integration", "Enable system tray": "Enable system tray", "Enabled": "Enabled", "Enter": "Enter", diff --git a/ui/dialogs/settingsdialog.go b/ui/dialogs/settingsdialog.go index 7a37247..1198b12 100644 --- a/ui/dialogs/settingsdialog.go +++ b/ui/dialogs/settingsdialog.go @@ -562,11 +562,18 @@ func (s *SettingsDialog) createAdvancedTab() *container.TabItem { widget.NewLabel("MB"), ) + osMediaAPIs := widget.NewCheck(lang.L("Enable OS media player integration"), func(b bool) { + s.config.Application.EnableOSMediaPlayerAPIs = b + s.setRestartRequired() + }) + osMediaAPIs.Checked = s.config.Application.EnableOSMediaPlayerAPIs + return container.NewTabItem(lang.L("Advanced"), container.NewVBox( multi, sslSkip, update, lrclib, + osMediaAPIs, imgCacheCfg, )) }