init: working version
This commit is contained in:
commit
7d8d7dacae
109 changed files with 15066 additions and 0 deletions
123
services/Players.qml
Normal file
123
services/Players.qml
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
pragma Singleton
|
||||
|
||||
import qs.config
|
||||
import qs.custom
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Services.Mpris
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property list<MprisPlayer> list: Mpris.players.values
|
||||
readonly property MprisPlayer active: manualActive ?? list.find(p => getIdentity(p) === Config.services.defaultPlayer) ?? list[0] ?? null
|
||||
property MprisPlayer manualActive
|
||||
|
||||
// Alias IDs (for looking up icons)
|
||||
readonly property list<var> idAliases: [
|
||||
{
|
||||
"from": "Mozilla firefox",
|
||||
"to": "Firefox"
|
||||
}
|
||||
]
|
||||
// Alias names (for displaying)
|
||||
readonly property list<var> nameAliases: [
|
||||
{
|
||||
"from": "com.github.th_ch.youtube_music",
|
||||
"to": "YT Music"
|
||||
}
|
||||
]
|
||||
|
||||
function getIdentity(player: MprisPlayer): string {
|
||||
const alias = idAliases.find(a => a.from === player.identity);
|
||||
return alias?.to ?? player.identity;
|
||||
}
|
||||
|
||||
function getName(player: MprisPlayer): string {
|
||||
const alias = nameAliases.find(a => a.from === player.identity);
|
||||
return alias?.to ?? getIdentity(player);
|
||||
}
|
||||
|
||||
CustomShortcut {
|
||||
name: "mediaToggle"
|
||||
description: "Toggle media playback"
|
||||
onPressed: {
|
||||
const active = root.active;
|
||||
if (active && active.canTogglePlaying)
|
||||
active.togglePlaying();
|
||||
}
|
||||
}
|
||||
|
||||
CustomShortcut {
|
||||
name: "mediaPrev"
|
||||
description: "Previous track"
|
||||
onPressed: {
|
||||
const active = root.active;
|
||||
if (active && active.canGoPrevious)
|
||||
active.previous();
|
||||
}
|
||||
}
|
||||
|
||||
CustomShortcut {
|
||||
name: "mediaNext"
|
||||
description: "Next track"
|
||||
onPressed: {
|
||||
const active = root.active;
|
||||
if (active && active.canGoNext)
|
||||
active.next();
|
||||
}
|
||||
}
|
||||
|
||||
CustomShortcut {
|
||||
name: "mediaStop"
|
||||
description: "Stop media playback"
|
||||
onPressed: root.active?.stop()
|
||||
}
|
||||
|
||||
IpcHandler {
|
||||
target: "mpris"
|
||||
|
||||
function getActive(prop: string): string {
|
||||
const active = root.active;
|
||||
return active ? active[prop] ?? "Invalid property" : "No active player";
|
||||
}
|
||||
|
||||
function list(): string {
|
||||
return root.list.map(p => root.get(p)).join("\n");
|
||||
}
|
||||
|
||||
function play(): void {
|
||||
const active = root.active;
|
||||
if (active?.canPlay)
|
||||
active.play();
|
||||
}
|
||||
|
||||
function pause(): void {
|
||||
const active = root.active;
|
||||
if (active?.canPause)
|
||||
active.pause();
|
||||
}
|
||||
|
||||
function playPause(): void {
|
||||
const active = root.active;
|
||||
if (active?.canTogglePlaying)
|
||||
active.togglePlaying();
|
||||
}
|
||||
|
||||
function previous(): void {
|
||||
const active = root.active;
|
||||
if (active?.canGoPrevious)
|
||||
active.previous();
|
||||
}
|
||||
|
||||
function next(): void {
|
||||
const active = root.active;
|
||||
if (active?.canGoNext)
|
||||
active.next();
|
||||
}
|
||||
|
||||
function stop(): void {
|
||||
root.active?.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue