config: player aliases + config default player

Closes #441
This commit is contained in:
2 * r + 2 * t 2025-08-23 21:34:31 +10:00
parent d75ac8ef35
commit 0d9ab6ae49
4 changed files with 20 additions and 4 deletions

View file

@ -315,6 +315,10 @@ All configuration options are in `~/.config/caelestia/shell.json`.
}, },
"services": { "services": {
"audioIncrement": 0.1, "audioIncrement": 0.1,
"defaultPlayer": "Spotify",
"playerAliases": [{
"com.github.th_ch.youtube_music": "YT Music"
}],
"weatherLocation": "10,10", "weatherLocation": "10,10",
"useFahrenheit": false, "useFahrenheit": false,
"useTwelveHourClock": false, "useTwelveHourClock": false,

View file

@ -7,4 +7,10 @@ JsonObject {
property bool useTwelveHourClock: Qt.locale().timeFormat(Locale.ShortFormat).toLowerCase().includes("a") property bool useTwelveHourClock: Qt.locale().timeFormat(Locale.ShortFormat).toLowerCase().includes("a")
property real audioIncrement: 0.1 property real audioIncrement: 0.1
property bool smartScheme: true property bool smartScheme: true
property string defaultPlayer: "Spotify"
property list<var> playerAliases: [
{
"com.github.th_ch.youtube_music": "YT Music"
}
]
} }

View file

@ -372,7 +372,7 @@ Item {
StyledText { StyledText {
Layout.fillWidth: true Layout.fillWidth: true
Layout.maximumWidth: playerSelector.implicitWidth - implicitHeight - parent.spacing - Appearance.padding.normal * 2 Layout.maximumWidth: playerSelector.implicitWidth - implicitHeight - parent.spacing - Appearance.padding.normal * 2
text: Players.active?.identity ?? "No players" text: Players.active ? Players.getIdentity(Players.active) : qsTr("No players")
color: Players.active ? Colours.palette.m3onSurface : Colours.palette.m3onSurfaceVariant color: Players.active ? Colours.palette.m3onSurface : Colours.palette.m3onSurfaceVariant
elide: Text.ElideRight elide: Text.ElideRight
} }
@ -444,7 +444,7 @@ Item {
} }
StyledText { StyledText {
text: player.modelData.identity text: Players.getIdentity(player.modelData)
color: Colours.palette.m3onSecondaryContainer color: Colours.palette.m3onSecondaryContainer
} }
} }

View file

@ -1,6 +1,7 @@
pragma Singleton pragma Singleton
import qs.components.misc import qs.components.misc
import qs.config
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
import Quickshell.Services.Mpris import Quickshell.Services.Mpris
@ -9,9 +10,14 @@ Singleton {
id: root id: root
readonly property list<MprisPlayer> list: Mpris.players.values readonly property list<MprisPlayer> list: Mpris.players.values
readonly property MprisPlayer active: manualActive ?? list.find(p => p.identity === "Spotify") ?? list[0] ?? null readonly property MprisPlayer active: manualActive ?? list.find(p => getIdentity(p) === Config.services.defaultPlayer) ?? list[0] ?? null
property MprisPlayer manualActive property MprisPlayer manualActive
function getIdentity(player: MprisPlayer): string {
const alias = Config.services.playerAliases.find(a => a.from === player.identity);
return alias?.to ?? player.identity;
}
CustomShortcut { CustomShortcut {
name: "mediaToggle" name: "mediaToggle"
description: "Toggle media playback" description: "Toggle media playback"
@ -57,7 +63,7 @@ Singleton {
} }
function list(): string { function list(): string {
return root.list.map(p => p.identity).join("\n"); return root.list.map(p => root.getIdentity(p)).join("\n");
} }
function play(): void { function play(): void {