1
0
Fork 0
mirror of https://github.com/icewind1991/clipboard-sync synced 2026-06-03 18:34:07 +02:00

exit on error, let systemd restart us

This commit is contained in:
Robin Appelman 2020-03-19 16:37:19 +01:00
commit 5e1543938b

View file

@ -7,7 +7,7 @@ use std::env;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::Duration; use std::time::Duration;
use std::{thread, thread::JoinHandle}; use std::{thread, thread::JoinHandle};
use ws::{connect, Message, Sender}; use ws::{connect, CloseCode, Message, Sender};
mod clip; mod clip;
mod common; mod common;
@ -56,7 +56,7 @@ fn main() {
.unwrap(); .unwrap();
} }
const HUNDRED_MS: Duration = Duration::from_millis(500); const SLEEP: Duration = Duration::from_millis(500);
fn clipboard_thread( fn clipboard_thread(
session: String, session: String,
@ -66,7 +66,7 @@ fn clipboard_thread(
thread::spawn(move || { thread::spawn(move || {
let mut ctx: ClipboardHandler = ClipboardHandler::new().unwrap(); let mut ctx: ClipboardHandler = ClipboardHandler::new().unwrap();
thread::sleep(HUNDRED_MS); thread::sleep(SLEEP);
// we need to do the listen after returning the closure for the websocket // we need to do the listen after returning the closure for the websocket
// thus we can't send this message in the factory // thus we can't send this message in the factory
@ -77,12 +77,13 @@ fn clipboard_thread(
}, },
); );
loop { loop {
thread::sleep(HUNDRED_MS); thread::sleep(SLEEP);
let new_clipboard = match ctx.get_contents() { let new_clipboard = match ctx.get_contents() {
Ok(content) => content, Ok(content) => content,
Err(e) => { Err(e) => {
eprintln!("{}", e); eprintln!("{}", e);
continue; let _ = out.close(CloseCode::Normal);
break;
} }
}; };
let mut clip = current_clipboard.lock().unwrap(); let mut clip = current_clipboard.lock().unwrap();