From 10adaf955b73ad510b1ca442ceb0943f79e9aeea Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Wed, 29 Oct 2025 20:30:16 +0100 Subject: [PATCH] AudioVisualizer: add setting to auto hide if no media is playing --- Assets/Translations/de.json | 4 ++ Assets/Translations/en.json | 4 ++ Assets/Translations/es.json | 4 ++ Assets/Translations/fr.json | 4 ++ Assets/Translations/pt.json | 4 ++ Assets/Translations/zh-CN.json | 4 ++ Modules/Bar/Widgets/AudioVisualizer.qml | 45 +++++++++---------- .../AudioVisualizerSettings.qml | 11 +++++ Services/BarWidgetRegistry.qml | 3 +- 9 files changed, 58 insertions(+), 25 deletions(-) diff --git a/Assets/Translations/de.json b/Assets/Translations/de.json index d3ef2fad..128ae357 100644 --- a/Assets/Translations/de.json +++ b/Assets/Translations/de.json @@ -1251,6 +1251,10 @@ "width": { "label": "Breite", "description": "Benutzerdefinierte Komponentenbreite." + }, + "hide-when-idle": { + "label": "Ausblenden, wenn keine Medien wiedergegeben werden", + "description": "Wenn aktiviert, wird der Visualizer ausgeblendet, sofern keine Wiedergabe läuft." } } } diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index 41151955..31d69b2c 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -1234,6 +1234,10 @@ "width": { "label": "Width", "description": "Custom component width." + }, + "hide-when-idle": { + "label": "Hide when no media is playing", + "description": "When enabled, the visualizer is hidden unless a player is actively playing." } } } diff --git a/Assets/Translations/es.json b/Assets/Translations/es.json index 1988fb7e..a9d86422 100644 --- a/Assets/Translations/es.json +++ b/Assets/Translations/es.json @@ -1234,6 +1234,10 @@ "width": { "label": "Ancho", "description": "Ancho del componente personalizado." + }, + "hide-when-idle": { + "label": "Ocultar cuando no se reproduce", + "description": "Si está activado, el visualizador se oculta salvo que haya reproducción activa." } } } diff --git a/Assets/Translations/fr.json b/Assets/Translations/fr.json index a918c945..67e966d4 100644 --- a/Assets/Translations/fr.json +++ b/Assets/Translations/fr.json @@ -1234,6 +1234,10 @@ "width": { "label": "Largeur", "description": "Largeur personnalisée du composant." + }, + "hide-when-idle": { + "label": "Masquer lorsqu'aucun média n'est en lecture", + "description": "Si activé, le visualiseur est masqué sauf lorsqu'un lecteur est en lecture." } } } diff --git a/Assets/Translations/pt.json b/Assets/Translations/pt.json index 1c78cea8..f6d05dd2 100644 --- a/Assets/Translations/pt.json +++ b/Assets/Translations/pt.json @@ -1234,6 +1234,10 @@ "width": { "label": "Largura", "description": "Largura do componente personalizado." + }, + "hide-when-idle": { + "label": "Ocultar quando não houver reprodução", + "description": "Quando ativado, o visualizador fica oculto a menos que haja reprodução ativa." } } } diff --git a/Assets/Translations/zh-CN.json b/Assets/Translations/zh-CN.json index 3fae37a5..24be85ae 100644 --- a/Assets/Translations/zh-CN.json +++ b/Assets/Translations/zh-CN.json @@ -1234,6 +1234,10 @@ "width": { "label": "宽度", "description": "自定义组件的宽度。" + }, + "hide-when-idle": { + "label": "无媒体播放时隐藏", + "description": "启用后,除非正在播放媒体,否则隐藏可视化显示。" } } } diff --git a/Modules/Bar/Widgets/AudioVisualizer.qml b/Modules/Bar/Widgets/AudioVisualizer.qml index d951e380..e6ebdc08 100644 --- a/Modules/Bar/Widgets/AudioVisualizer.qml +++ b/Modules/Bar/Widgets/AudioVisualizer.qml @@ -29,9 +29,25 @@ Item { // Resolve settings: try user settings or defaults from BarWidgetRegistry readonly property int visualizerWidth: widgetSettings.width !== undefined ? widgetSettings.width : widgetMetadata.width + readonly property bool hideWhenIdle: widgetSettings.hideWhenIdle !== undefined ? widgetSettings.hideWhenIdle : (widgetMetadata.hideWhenIdle !== undefined ? widgetMetadata.hideWhenIdle : false) + readonly property bool shouldShow: (currentVisualizerType !== "" && currentVisualizerType !== "none") && (!hideWhenIdle || MediaService.isPlaying) - implicitWidth: visualizerWidth - implicitHeight: Style.capsuleHeight + implicitWidth: shouldShow ? visualizerWidth : 0 + implicitHeight: shouldShow ? Style.capsuleHeight : 0 + visible: shouldShow + + Behavior on implicitWidth { + NumberAnimation { + duration: Style.animationNormal + easing.type: Easing.InOutCubic + } + } + Behavior on implicitHeight { + NumberAnimation { + duration: Style.animationNormal + easing.type: Easing.InOutCubic + } + } Rectangle { id: background @@ -43,27 +59,14 @@ Item { // Store visualizer type to force re-evaluation readonly property string currentVisualizerType: Settings.data.audio.visualizerType - // Timer to delay reload - Timer { - id: reloadTimer - interval: 50 - onTriggered: { - visualizerLoader.active = true - } - } - - // Force reload when visualizer type changes - onCurrentVisualizerTypeChanged: { - visualizerLoader.active = false - reloadTimer.restart() - } + // When visualizer type or playback changes, shouldShow updates automatically // The Loader dynamically loads the appropriate visualizer based on settings Loader { id: visualizerLoader anchors.fill: parent anchors.margins: Style.marginS - active: false + active: shouldShow asynchronous: false sourceComponent: { @@ -99,13 +102,7 @@ Item { } } - // Initial activation on component complete - Component.onCompleted: { - if (currentVisualizerType !== "" && currentVisualizerType !== "none") { - visualizerLoader.active = true - } - } - + // No imperative activation needed; bound to shouldShow Component { id: linearComponent LinearSpectrum { diff --git a/Modules/Settings/Bar/WidgetSettings/AudioVisualizerSettings.qml b/Modules/Settings/Bar/WidgetSettings/AudioVisualizerSettings.qml index 768ce805..0585c0b7 100644 --- a/Modules/Settings/Bar/WidgetSettings/AudioVisualizerSettings.qml +++ b/Modules/Settings/Bar/WidgetSettings/AudioVisualizerSettings.qml @@ -13,9 +13,13 @@ ColumnLayout { property var widgetData: null property var widgetMetadata: null + // Local state + property bool valueHideWhenIdle: widgetData.hideWhenIdle !== undefined ? widgetData.hideWhenIdle : (widgetMetadata.hideWhenIdle !== undefined ? widgetMetadata.hideWhenIdle : false) + function saveSettings() { var settings = Object.assign({}, widgetData || {}) settings.width = parseInt(widthInput.text) || widgetMetadata.width + settings.hideWhenIdle = valueHideWhenIdle return settings } @@ -27,4 +31,11 @@ ColumnLayout { text: widgetData.width || widgetMetadata.width placeholderText: I18n.tr("placeholders.enter-width-pixels") } + + NToggle { + label: I18n.tr("bar.widget-settings.audio-visualizer.hide-when-idle.label") + description: I18n.tr("bar.widget-settings.audio-visualizer.hide-when-idle.description") + checked: valueHideWhenIdle + onToggled: checked => valueHideWhenIdle = checked + } } diff --git a/Services/BarWidgetRegistry.qml b/Services/BarWidgetRegistry.qml index 59423385..e8b2b993 100644 --- a/Services/BarWidgetRegistry.qml +++ b/Services/BarWidgetRegistry.qml @@ -52,7 +52,8 @@ Singleton { }, "AudioVisualizer": { "allowUserSettings": true, - "width": 200 + "width": 200, + "hideWhenIdle": false }, "Battery": { "allowUserSettings": true,