🚧 Need to thing of a way to rewrite this to be less of a mess tbh,
This commit is contained in:
parent
1ce1afcbab
commit
f3a92fbdfd
3 changed files with 17 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -252,6 +252,7 @@ dependencies = [
|
||||||
"pulsectl-rs",
|
"pulsectl-rs",
|
||||||
"relm4",
|
"relm4",
|
||||||
"tracker",
|
"tracker",
|
||||||
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -16,5 +16,6 @@ relm4 = { git = "https://github.com/AaronErhardt/relm4", rev = "7404ad64ca8763f6
|
||||||
tracker = "0.1.1"
|
tracker = "0.1.1"
|
||||||
freedesktop-desktop-entry = "0.5.0"
|
freedesktop-desktop-entry = "0.5.0"
|
||||||
mpris2-zbus = { git = "https://github.com/pop-os/mpris2-zbus" }
|
mpris2-zbus = { git = "https://github.com/pop-os/mpris2-zbus" }
|
||||||
|
zbus = "2.1.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use libpulse_binding::{
|
||||||
context::subscribe::{Facility, InterestMaskSet, Operation},
|
context::subscribe::{Facility, InterestMaskSet, Operation},
|
||||||
volume::Volume,
|
volume::Volume,
|
||||||
};
|
};
|
||||||
|
use mpris2_zbus::media_player::MediaPlayer;
|
||||||
use pulsectl::{
|
use pulsectl::{
|
||||||
controllers::{
|
controllers::{
|
||||||
types::{ApplicationInfo, DeviceInfo},
|
types::{ApplicationInfo, DeviceInfo},
|
||||||
|
|
@ -25,6 +26,7 @@ use relm4::{
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, rc::Rc};
|
use std::{collections::HashMap, rc::Rc};
|
||||||
use tracker::track;
|
use tracker::track;
|
||||||
|
use zbus::Connection;
|
||||||
|
|
||||||
pub enum AppInput {
|
pub enum AppInput {
|
||||||
Inputs,
|
Inputs,
|
||||||
|
|
@ -34,6 +36,14 @@ pub enum AppInput {
|
||||||
NowPlaying,
|
NowPlaying,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
struct NowPlayingInfo {
|
||||||
|
title: String,
|
||||||
|
artist: String,
|
||||||
|
album: String,
|
||||||
|
art_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[track]
|
#[track]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
#[no_eq]
|
#[no_eq]
|
||||||
|
|
@ -45,7 +55,7 @@ pub struct App {
|
||||||
#[no_eq]
|
#[no_eq]
|
||||||
outputs: Vec<DeviceInfo>,
|
outputs: Vec<DeviceInfo>,
|
||||||
#[no_eq]
|
#[no_eq]
|
||||||
now_playing: Vec<ApplicationInfo>,
|
now_playing: Vec<NowPlayingInfo>,
|
||||||
#[do_not_track]
|
#[do_not_track]
|
||||||
desktop_icons: HashMap<DesktopApplication, String>,
|
desktop_icons: HashMap<DesktopApplication, String>,
|
||||||
#[do_not_track]
|
#[do_not_track]
|
||||||
|
|
@ -62,7 +72,7 @@ impl Default for App {
|
||||||
SinkController::create().expect("failed to create output controller");
|
SinkController::create().expect("failed to create output controller");
|
||||||
let default_output = output_controller.get_default_device().ok();
|
let default_output = output_controller.get_default_device().ok();
|
||||||
let outputs = output_controller.list_devices().unwrap_or_default();
|
let outputs = output_controller.list_devices().unwrap_or_default();
|
||||||
let now_playing = output_controller.list_applications().unwrap_or_default();
|
let now_playing = Vec::new();
|
||||||
let desktop_icons = parse_desktop_icons();
|
let desktop_icons = parse_desktop_icons();
|
||||||
let handler = Handler::connect("com.system76.cosmic.applets.audio")
|
let handler = Handler::connect("com.system76.cosmic.applets.audio")
|
||||||
.expect("failed to connect to pulse");
|
.expect("failed to connect to pulse");
|
||||||
|
|
@ -133,24 +143,22 @@ impl App {
|
||||||
|
|
||||||
fn subscribe_for_updates(&self, input: &Sender<AppInput>) {
|
fn subscribe_for_updates(&self, input: &Sender<AppInput>) {
|
||||||
let mut context = self.handler.context.borrow_mut();
|
let mut context = self.handler.context.borrow_mut();
|
||||||
let input = input.clone();
|
let input_clone = input.clone();
|
||||||
context.set_subscribe_callback(Some(Box::new(move |facility, operation, _idx| {
|
context.set_subscribe_callback(Some(Box::new(move |facility, operation, _idx| {
|
||||||
if !matches!(operation, Some(Operation::Changed)) {
|
if !matches!(operation, Some(Operation::Changed)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match facility {
|
match facility {
|
||||||
Some(Facility::Sink) => {
|
Some(Facility::Sink) => {
|
||||||
send!(input, AppInput::OutputVolume);
|
send!(input_clone, AppInput::OutputVolume);
|
||||||
send!(input, AppInput::NowPlaying);
|
|
||||||
}
|
}
|
||||||
Some(Facility::Source) => {
|
Some(Facility::Source) => {
|
||||||
send!(input, AppInput::InputVolume);
|
send!(input_clone, AppInput::InputVolume);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
context.subscribe(InterestMaskSet::SINK | InterestMaskSet::SOURCE, |_| {});
|
context.subscribe(InterestMaskSet::SINK | InterestMaskSet::SOURCE, |_| {});
|
||||||
}
|
|
||||||
|
|
||||||
fn refresh_input_list(&mut self) {
|
fn refresh_input_list(&mut self) {
|
||||||
let mut input_controller =
|
let mut input_controller =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue