mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-06-22 10:02:20 +00:00
fix(clipboard): restart stale listener and log join panics
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
fc61d0cd31
commit
2546354ea4
1 changed files with 20 additions and 12 deletions
|
|
@ -862,24 +862,14 @@ pub mod clipboard_listener {
|
|||
pub fn subscribe(name: String, tx: Sender<CallbackResult>) -> ResultType<()> {
|
||||
log::info!("Subscribe clipboard listener: {}", &name);
|
||||
let mut listener_lock = CLIPBOARD_LISTENER.lock().unwrap();
|
||||
let stale_handle = listener_lock
|
||||
.handle
|
||||
.as_ref()
|
||||
.map(|(_, h)| h.is_finished())
|
||||
.unwrap_or(false);
|
||||
if stale_handle {
|
||||
if let Some((shutdown, h)) = listener_lock.handle.take() {
|
||||
log::warn!("Cleaning up stale clipboard listener handle");
|
||||
h.join().ok();
|
||||
drop(shutdown);
|
||||
}
|
||||
}
|
||||
cleanup_stale_listener(&mut listener_lock);
|
||||
listener_lock
|
||||
.subscribers
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(name.clone(), tx);
|
||||
|
||||
cleanup_stale_listener(&mut listener_lock);
|
||||
if listener_lock.handle.is_none() {
|
||||
log::info!("Start clipboard listener thread");
|
||||
let handler = Handler {
|
||||
|
|
@ -905,6 +895,24 @@ pub mod clipboard_listener {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn cleanup_stale_listener(listener: &mut ClipboardListener) {
|
||||
if !listener
|
||||
.handle
|
||||
.as_ref()
|
||||
.map(|(_, h)| h.is_finished())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if let Some((shutdown, h)) = listener.handle.take() {
|
||||
log::warn!("Cleaning up stale clipboard listener handle");
|
||||
if let Err(e) = h.join() {
|
||||
log::error!("Clipboard listener thread panicked during stale cleanup: {:?}", e);
|
||||
}
|
||||
drop(shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unsubscribe(name: &str) {
|
||||
log::info!("Unsubscribe clipboard listener: {}", name);
|
||||
let mut listener_lock = CLIPBOARD_LISTENER.lock().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue