mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-06 00:51:28 +03:00
Async (#30)
- manual eventloop now replaced by asycn-await using the tokio runtime - dns no longer blocks the event loop - simplifies logic - makes xdg-desktop-portal easier to integrate
This commit is contained in:
committed by
GitHub
parent
d4d6f05802
commit
ab2514e508
@@ -42,7 +42,7 @@ pub fn start() -> Result<(JoinHandle<()>, JoinHandle<()>)> {
|
||||
for event in events.iter() {
|
||||
let json = serde_json::to_string(&event).unwrap();
|
||||
let bytes = json.as_bytes();
|
||||
let len = bytes.len().to_ne_bytes();
|
||||
let len = bytes.len().to_be_bytes();
|
||||
if let Err(e) = tx.write(&len) {
|
||||
log::error!("error sending message: {e}");
|
||||
};
|
||||
@@ -77,7 +77,7 @@ pub fn start() -> Result<(JoinHandle<()>, JoinHandle<()>)> {
|
||||
Err(e) if e.kind() == ErrorKind::UnexpectedEof => break,
|
||||
Err(e) => break log::error!("{e}"),
|
||||
};
|
||||
let len = usize::from_ne_bytes(len);
|
||||
let len = usize::from_be_bytes(len);
|
||||
|
||||
// read payload
|
||||
let mut buf: Vec<u8> = vec![0u8; len];
|
||||
|
||||
@@ -15,6 +15,7 @@ use self::client_object::ClientObject;
|
||||
use super::FrontendNotify;
|
||||
|
||||
pub fn start() -> Result<JoinHandle<glib::ExitCode>> {
|
||||
log::debug!("starting gtk frontend");
|
||||
thread::Builder::new()
|
||||
.name("gtk-thread".into())
|
||||
.spawn(gtk_main)
|
||||
@@ -58,6 +59,7 @@ fn build_ui(app: &Application) {
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
log::debug!("connecting to lan-mouse-socket ... ");
|
||||
let socket_path = Path::new(xdg_runtime_dir.as_str())
|
||||
.join("lan-mouse-socket.sock");
|
||||
let Ok(mut rx) = UnixStream::connect(&socket_path) else {
|
||||
@@ -71,6 +73,7 @@ fn build_ui(app: &Application) {
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
log::debug!("connected to lan-mouse-socket");
|
||||
|
||||
let (sender, receiver) = MainContext::channel::<FrontendNotify>(Priority::default());
|
||||
|
||||
@@ -83,7 +86,7 @@ fn build_ui(app: &Application) {
|
||||
Err(e) if e.kind() == ErrorKind::UnexpectedEof => break Ok(()),
|
||||
Err(e) => break Err(e),
|
||||
};
|
||||
let len = usize::from_ne_bytes(len);
|
||||
let len = usize::from_be_bytes(len);
|
||||
|
||||
// read payload
|
||||
let mut buf = vec![0u8; len];
|
||||
|
||||
@@ -141,7 +141,7 @@ impl Window {
|
||||
let mut stream = self.imp().stream.borrow_mut();
|
||||
let stream = stream.as_mut().unwrap();
|
||||
let bytes = json.as_bytes();
|
||||
let len = bytes.len().to_ne_bytes();
|
||||
let len = bytes.len().to_be_bytes();
|
||||
if let Err(e) = stream.write(&len) {
|
||||
log::error!("error sending message: {e}");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user