Skip to content

Commit 196ef94

Browse files
committed
Add getters for wireplumber plugins to manager.
1 parent 3564d22 commit 196ef94

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

src/backend/manager.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mod imp {
3232
#[derive(Default, Properties)]
3333
#[properties(wrapper_type = super::PwvucontrolManager)]
3434
pub struct PwvucontrolManager {
35+
#[property(get)]
3536
pub wp_core: OnceCell<wp::core::Core>,
3637
pub wp_object_manager: OnceCell<wp::registry::ObjectManager>,
3738

@@ -43,6 +44,11 @@ mod imp {
4344
pub metadata_om: OnceCell<wp::registry::ObjectManager>,
4445
pub metadata: RefCell<Option<wp::pw::Metadata>>,
4546

47+
#[property(get)]
48+
pub default_nodes_api: OnceCell<Plugin>,
49+
#[property(get)]
50+
pub mixer_api: OnceCell<Plugin>,
51+
4652
#[property(get, set, construct_only)]
4753
application: RefCell<Option<PwvucontrolApplication>>,
4854
}
@@ -211,17 +217,19 @@ mod imp {
211217
}));
212218

213219
glib::MainContext::default().spawn_local(clone!(@weak self as manager, @weak wp_core as core, @weak wp_om as om => async move {
214-
let plugin_names = vec!["mixer-api", "default-nodes-api"];
220+
let plugin_names = vec![("mixer-api", &manager.mixer_api), ("default-nodes-api", &manager.default_nodes_api)];
221+
215222
let mut count = 0;
216-
for plugin_name in plugin_names {
223+
for (plugin_name, plugin_cell) in plugin_names.iter() {
217224
if let Some(plugin) = Plugin::find(&core, plugin_name) {
218225
let result = plugin.activate_future(PluginFeatures::ENABLED).await;
219226
if result.is_err() {
220227
pwvucontrol_critical!("Cannot activate plugin {plugin_name}");
221228
} else {
229+
plugin_cell.set(plugin).expect("Plugin not set");
222230
pwvucontrol_info!("Activated plugin {plugin_name}");
223231
count += 1;
224-
if count == 2 {
232+
if count == plugin_names.len() {
225233
core.install_object_manager(&om);
226234
}
227235
}

src/backend/pwnodeobject.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ pub mod imp {
8181
#[property(get, set, construct_only)]
8282
pub(super) wpnode: OnceCell<wp::pw::Node>,
8383

84-
pub(super) mixerapi: OnceCell<wp::plugin::Plugin>,
85-
8684
pub(super) block: Cell<bool>,
8785
}
8886

@@ -104,7 +102,6 @@ pub mod imp {
104102
format: Default::default(),
105103
channellock: Default::default(),
106104
wpnode: OnceCell::default(),
107-
mixerapi: Default::default(),
108105
block: Default::default()
109106
}
110107
}

src/backend/pwnodeobject/mixerapi.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,8 @@ use super::*;
1010

1111
impl PwNodeObject {
1212
pub(crate) fn get_mixer_api(&self) {
13-
let imp = self.imp();
14-
1513
let manager = PwvucontrolManager::default();
16-
let core = manager.imp().wp_core.get().expect("Core setup");
17-
18-
let mixerapi = wp::plugin::Plugin::find(core, "mixer-api").expect("Get mixer-api");
19-
20-
imp.mixerapi
21-
.set(mixerapi)
22-
.expect("mixerapi only set once in PwNodeObject");
14+
let mixerapi = manager.mixer_api();
2315

2416
let changed_handler = closure_local!(@watch self as widget => move |_mixerapi: &wp::plugin::Plugin, id: u32|{
2517
if id == widget.boundid() {
@@ -29,16 +21,14 @@ impl PwNodeObject {
2921
}
3022
});
3123

32-
imp.mixerapi.get().unwrap().connect_closure("changed", true, changed_handler);
24+
mixerapi.connect_closure("changed", true, changed_handler);
3325
}
3426

3527
pub(crate) fn send_volume_using_mixerapi(&self, what: PropertyChanged) {
3628
let imp = self.imp();
3729
let node = imp.wpnode.get().expect("node in send_volume");
38-
let mixerapi = imp
39-
.mixerapi
40-
.get()
41-
.expect("Mixer api must be set on PwNodeObject");
30+
let manager = PwvucontrolManager::default();
31+
let mixerapi = manager.mixer_api();
4232
let bound_id = node.bound_id();
4333
let result =
4434
mixerapi.emit_by_name::<Option<glib::Variant>>("get-volume", &[&node.bound_id()]);
@@ -110,11 +100,8 @@ impl PwNodeObject {
110100
}
111101

112102
pub(crate) fn update_volume_using_mixerapi(&self) {
113-
let mixerapi = self
114-
.imp()
115-
.mixerapi
116-
.get()
117-
.expect("Mixer api must be set on PwNodeObject");
103+
let manager = PwvucontrolManager::default();
104+
let mixerapi = manager.mixer_api();
118105
let node = self
119106
.imp()
120107
.wpnode

src/ui/volumebox.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ mod imp {
153153

154154
let manager = PwvucontrolManager::default();
155155

156-
let core = manager.imp().wp_core.get().expect("Core");
157-
let defaultnodesapi =
158-
wp::plugin::Plugin::find(core, "default-nodes-api").expect("Get mixer-api");
156+
let defaultnodesapi = manager.default_nodes_api();
159157
let widget = self.obj();
160158
let defaultnodesapi_closure = closure_local!(@watch widget => move |defaultnodesapi: wp::plugin::Plugin| {
161159
let id: u32 = defaultnodesapi.emit_by_name("get-default-node", &[&"Audio/Sink"]);

0 commit comments

Comments
 (0)