From c6c0bd4e4bbf7eeb50fab355568cfc97c6d3a97f Mon Sep 17 00:00:00 2001 From: Tuxinal <24763016+tuxinal@users.noreply.github.com> Date: Fri, 7 Feb 2025 01:05:24 +0330 Subject: [PATCH] just enough error handling to make it not crash on wayland without GlobalShortcuts bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- package.json | 2 +- src/errors.rs | 2 -- src/js.rs | 16 ++++++++-------- src/lib.rs | 2 +- src/linux.rs | 22 ++++++++++------------ 7 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c24e50c..dd0319f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1383,7 +1383,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "venbind" -version = "0.0.2" +version = "0.0.3" dependencies = [ "ashpd", "cmake", diff --git a/Cargo.toml b/Cargo.toml index 50353b1..7c4ae19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "venbind" -version = "0.0.2" +version = "0.0.3" edition = "2021" [lib] diff --git a/package.json b/package.json index 5efa177..cdf2e8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "venbind", - "version": "0.0.2", + "version": "0.0.3", "description": "", "types": "./lib/venbind.d.ts", "scripts": {}, diff --git a/src/errors.rs b/src/errors.rs index b42b139..8d2371f 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -6,8 +6,6 @@ pub type Result = std::result::Result; pub enum VenbindError { #[error("Something went wrong with libuiohook")] // TODO: better log LibUIOHookError, - #[error("{0}")] - Message(String), #[cfg(all(target_os = "linux"))] #[error("ashpd error: {0}")] AshPdError(#[from] ashpd::Error), diff --git a/src/js.rs b/src/js.rs index 6097c0a..b146e9a 100644 --- a/src/js.rs +++ b/src/js.rs @@ -18,14 +18,14 @@ pub fn start_keybinds(callback: JsFunction) -> Result<()> { thread::spawn(|| { crate::start_keybinds(tx); }); -let thread_function: ThreadsafeFunction<(u32, bool), ErrorStrategy::Fatal> = callback - .create_threadsafe_function(0, |ctx: ThreadSafeCallContext<(u32, bool)>| { - ctx.env.create_uint32(ctx.value.0).and_then(|y| { - ctx.env - .get_boolean(ctx.value.1) - .and_then(|x| (y, x).into_vec(ctx.env.raw())) - }) - })?; + let thread_function: ThreadsafeFunction<(u32, bool), ErrorStrategy::Fatal> = callback + .create_threadsafe_function(0, |ctx: ThreadSafeCallContext<(u32, bool)>| { + ctx.env.create_uint32(ctx.value.0).and_then(|y| { + ctx.env + .get_boolean(ctx.value.1) + .and_then(|x| (y, x).into_vec(ctx.env.raw())) + }) + })?; thread::spawn(move || loop { match rx.recv() { Err(err) => { diff --git a/src/lib.rs b/src/lib.rs index a264cd4..e50283b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ mod tests { thread::spawn(|| { start_keybinds(tx); }); - // thread::sleep(std::time::Duration::from_secs(2)); + thread::sleep(std::time::Duration::from_secs(2)); #[cfg(target_os = "linux")] if crate::is_wayland() || crate::use_xdg_on_x11() { crate::xdg_preregister_keybinds(vec![ diff --git a/src/linux.rs b/src/linux.rs index 78e6fa7..7cf160c 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -112,18 +112,16 @@ pub(crate) fn xdg_preregister_keybinds(actions: Vec) -> Resul .iter() .map(|x| NewShortcut::new(format!("{}", x.id), x.name.clone())) .collect(); - loop { - let lock = XDG_STATE.lock().unwrap(); - if let Some(state) = lock.as_ref() { - futures::executor::block_on(state.portal.bind_shortcuts( - &state.session, - &shortcuts, - None, - ))?; - break; - } else { - continue; - } + let lock = XDG_STATE.lock().unwrap(); + if let Some(state) = lock.as_ref() { + + futures::executor::block_on( + state + .portal + .bind_shortcuts(&state.session, &shortcuts, None), + )?; + } else { + eprintln!("No GlobalShortcuts state was found! skipping preregistery."); } Ok(()) }