audio: audio device changed toasts (#684)
* Added toast notifications for audio device changes * rename to toasts * moved into audio service * fixes --------- Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
parent
7aaa14438f
commit
bef5359702
3 changed files with 45 additions and 1 deletions
|
|
@ -567,7 +567,11 @@ default, you must create it manually.
|
|||
},
|
||||
"utilities": {
|
||||
"enabled": true,
|
||||
"maxToasts": 4
|
||||
"maxToasts": 4,
|
||||
"toasts": {
|
||||
"audioOutputChanged": true,
|
||||
"audioInputChanged": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -5,8 +5,14 @@ JsonObject {
|
|||
property int maxToasts: 4
|
||||
|
||||
property Sizes sizes: Sizes {}
|
||||
property Toasts toasts: Toasts {}
|
||||
|
||||
component Sizes: JsonObject {
|
||||
property int width: 430
|
||||
}
|
||||
|
||||
component Toasts: JsonObject {
|
||||
property bool audioOutputChanged: true
|
||||
property bool audioInputChanged: true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,17 @@ pragma Singleton
|
|||
|
||||
import qs.config
|
||||
import Caelestia.Services
|
||||
import Caelestia
|
||||
import Quickshell
|
||||
import Quickshell.Services.Pipewire
|
||||
import QtQuick
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property string previousSinkName: ""
|
||||
property string previousSourceName: ""
|
||||
|
||||
readonly property var nodes: Pipewire.nodes.values.reduce((acc, node) => {
|
||||
if (!node.isStream) {
|
||||
if (node.isSink)
|
||||
|
|
@ -74,6 +79,35 @@ Singleton {
|
|||
Pipewire.preferredDefaultAudioSource = newSource;
|
||||
}
|
||||
|
||||
onSinkChanged: {
|
||||
if (!sink?.ready)
|
||||
return;
|
||||
|
||||
const newSinkName = sink.description || sink.name || qsTr("Unknown Device");
|
||||
|
||||
if (previousSinkName && previousSinkName !== newSinkName && Config.utilities.toasts.audioOutputChanged)
|
||||
Toaster.toast(qsTr("Audio output changed"), qsTr("Now using: %1").arg(newSinkName), "volume_up");
|
||||
|
||||
previousSinkName = newSinkName;
|
||||
}
|
||||
|
||||
onSourceChanged: {
|
||||
if (!source?.ready)
|
||||
return;
|
||||
|
||||
const newSourceName = source.description || source.name || qsTr("Unknown Device");
|
||||
|
||||
if (previousSourceName && previousSourceName !== newSourceName && Config.utilities.toasts.audioInputChanged)
|
||||
Toaster.toast(qsTr("Audio input changed"), qsTr("Now using: %1").arg(newSourceName), "mic");
|
||||
|
||||
previousSourceName = newSourceName;
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
previousSinkName = sink?.description || sink?.name || qsTr("Unknown Device");
|
||||
previousSourceName = source?.description || source?.name || qsTr("Unknown Device");
|
||||
}
|
||||
|
||||
PwObjectTracker {
|
||||
objects: [...root.sinks, ...root.sources]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue