mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-27 14:59:02 +08:00
make clipboard dropped after no sub
This commit is contained in:
parent
84b5cd70ed
commit
cd73368cb9
@ -4,12 +4,18 @@ pub use crate::common::{
|
||||
CONTENT,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
ctx: Option<ClipboardContext>,
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
impl super::service::Reset for State {
|
||||
fn reset(&mut self) {
|
||||
*CONTENT.lock().unwrap() = Default::default();
|
||||
self.ctx = None;
|
||||
}
|
||||
|
||||
fn init(&mut self) {
|
||||
let ctx = match ClipboardContext::new(true) {
|
||||
Ok(ctx) => Some(ctx),
|
||||
Err(err) => {
|
||||
@ -17,13 +23,7 @@ impl Default for State {
|
||||
None
|
||||
}
|
||||
};
|
||||
Self { ctx }
|
||||
}
|
||||
}
|
||||
|
||||
impl super::service::Reset for State {
|
||||
fn reset(&mut self) {
|
||||
*CONTENT.lock().unwrap() = Default::default();
|
||||
self.ctx = ctx;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ pub struct ServiceInner<T: Subscriber + From<ConnInner>> {
|
||||
|
||||
pub trait Reset {
|
||||
fn reset(&mut self);
|
||||
fn init(&mut self) {}
|
||||
}
|
||||
|
||||
pub struct ServiceTmpl<T: Subscriber + From<ConnInner>>(Arc<RwLock<ServiceInner<T>>>);
|
||||
@ -266,15 +267,16 @@ impl<T: Subscriber + From<ConnInner>> ServiceTmpl<T> {
|
||||
while sp.active() {
|
||||
let now = time::Instant::now();
|
||||
if sp.has_subscribes() {
|
||||
if !may_reset {
|
||||
may_reset = true;
|
||||
state.init();
|
||||
}
|
||||
if let Err(err) = callback(sp.clone(), &mut state) {
|
||||
log::error!("Error of {} service: {}", sp.name(), err);
|
||||
thread::sleep(time::Duration::from_millis(MAX_ERROR_TIMEOUT));
|
||||
#[cfg(windows)]
|
||||
crate::platform::windows::try_change_desktop();
|
||||
}
|
||||
if !may_reset {
|
||||
may_reset = true;
|
||||
}
|
||||
} else if may_reset {
|
||||
state.reset();
|
||||
may_reset = false;
|
||||
|
Loading…
Reference in New Issue
Block a user