From 1467036efd7591ed5d1c10b4bbb34c5b9cb5a4fc Mon Sep 17 00:00:00 2001 From: Deluan Date: Fri, 11 Nov 2022 16:31:28 -0500 Subject: [PATCH] Add `DefaultUIVolume` option. Closes #1679 --- conf/configuration.go | 2 ++ consts/consts.go | 2 ++ server/serve_index.go | 1 + server/serve_index_test.go | 11 +++++++++++ ui/src/config.js | 1 + ui/src/reducers/playerReducer.js | 2 +- 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/conf/configuration.go b/conf/configuration.go index 945e21394..f265f3bbe 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -49,6 +49,7 @@ type configOptions struct { EnableUserEditing bool DefaultTheme string DefaultLanguage string + DefaultUIVolume int EnableCoverAnimation bool GATrackingID string EnableLogRedacting bool @@ -240,6 +241,7 @@ func init() { viper.SetDefault("enableuserediting", true) viper.SetDefault("defaulttheme", "Dark") viper.SetDefault("defaultlanguage", "") + viper.SetDefault("defaultuivolume", consts.DefaultUIVolume) viper.SetDefault("enablecoveranimation", true) viper.SetDefault("gatrackingid", "") viper.SetDefault("enablelogredacting", true) diff --git a/consts/consts.go b/consts/consts.go index 2942de273..0a749d3f8 100644 --- a/consts/consts.go +++ b/consts/consts.go @@ -51,6 +51,8 @@ const ( PlaceholderAlbumArt = "placeholder.png" PlaceholderAvatar = "logo-192x192.png" + DefaultUIVolume = 100 + DefaultHttpClientTimeOut = 10 * time.Second DefaultScannerExtractor = "taglib" diff --git a/server/serve_index.go b/server/serve_index.go index 6ad363a36..5102525df 100644 --- a/server/serve_index.go +++ b/server/serve_index.go @@ -39,6 +39,7 @@ func serveIndex(ds model.DataStore, fs fs.FS) http.HandlerFunc { "enableStarRating": conf.Server.EnableStarRating, "defaultTheme": conf.Server.DefaultTheme, "defaultLanguage": conf.Server.DefaultLanguage, + "defaultUIVolume": conf.Server.DefaultUIVolume, "enableCoverAnimation": conf.Server.EnableCoverAnimation, "gaTrackingId": conf.Server.GATrackingID, "losslessFormats": strings.ToUpper(strings.Join(consts.LosslessFormats, ",")), diff --git a/server/serve_index_test.go b/server/serve_index_test.go index 223309de4..154ec5c72 100644 --- a/server/serve_index_test.go +++ b/server/serve_index_test.go @@ -170,6 +170,17 @@ var _ = Describe("serveIndex", func() { Expect(config).To(HaveKeyWithValue("defaultLanguage", "pt")) }) + It("sets the defaultUIVolume", func() { + conf.Server.DefaultUIVolume = 45 + r := httptest.NewRequest("GET", "/index.html", nil) + w := httptest.NewRecorder() + + serveIndex(ds, fs)(w, r) + + config := extractAppConfig(w.Body.String()) + Expect(config).To(HaveKeyWithValue("defaultUIVolume", float64(45))) + }) + It("sets the enableCoverAnimation", func() { conf.Server.EnableCoverAnimation = true r := httptest.NewRequest("GET", "/index.html", nil) diff --git a/ui/src/config.js b/ui/src/config.js index 97b0d9655..6f2621106 100644 --- a/ui/src/config.js +++ b/ui/src/config.js @@ -19,6 +19,7 @@ const defaultConfig = { enableStarRating: true, defaultTheme: 'Dark', defaultLanguage: '', + defaultUIVolume: 100, enableUserEditing: true, devEnableShare: true, devSidebarPlaylists: true, diff --git a/ui/src/reducers/playerReducer.js b/ui/src/reducers/playerReducer.js index f82e48f4f..428be7fcf 100644 --- a/ui/src/reducers/playerReducer.js +++ b/ui/src/reducers/playerReducer.js @@ -16,7 +16,7 @@ const initialState = { queue: [], current: {}, clear: false, - volume: 0.5, // 50% + volume: config.defaultUIVolume / 100, savedPlayIndex: 0, }