Skip to content

Commit 614030b

Browse files
committed
Clean up levelprovider fd loop
1 parent a457a6a commit 614030b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/ui/levelprovider.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::{fmt::Debug, time::Duration};
44

55
use crate::ui::PwVolumeBox;
6-
use glib::{self, clone, ControlFlow};
6+
use glib::{self, clone, ControlFlow, SourceId};
77
use pipewire::{context::Context, loop_::Loop, properties::*, spa, spa::utils::Direction, stream::*};
88
use std::os::fd::AsRawFd;
99

@@ -14,6 +14,7 @@ pub struct LevelbarProvider {
1414
_context: Context,
1515
stream: Option<Stream>,
1616
_listener: StreamListener<f32>,
17+
sig: Option<SourceId>,
1718
}
1819

1920
impl Debug for LevelbarProvider {
@@ -30,7 +31,7 @@ impl LevelbarProvider {
3031

3132
let fd = loop_.fd();
3233

33-
glib::source::unix_fd_add_local(fd.as_raw_fd(), glib::IOCondition::all(), {
34+
let sig = glib::source::unix_fd_add_local(fd.as_raw_fd(), glib::IOCondition::all(), {
3435
let loop_ = loop_.clone();
3536
move |_, _| {
3637
loop_.iterate(Duration::ZERO);
@@ -99,6 +100,7 @@ impl LevelbarProvider {
99100
_context: context,
100101
stream: Some(stream),
101102
_listener: listener,
103+
sig: Some(sig)
102104
})
103105
}
104106
}
@@ -108,6 +110,9 @@ impl Drop for LevelbarProvider {
108110
if let Some(stream) = self.stream.take() {
109111
stream.disconnect().unwrap();
110112
}
113+
if let Some(sig) = self.sig.take() {
114+
sig.remove();
115+
}
111116
}
112117
}
113118

0 commit comments

Comments
 (0)