Skip to content

Commit

Permalink
just enough error handling to make it not crash on wayland without Gl…
Browse files Browse the repository at this point in the history
…obalShortcuts

bump version
  • Loading branch information
tuxinal committed Feb 6, 2025
1 parent b8116e6 commit c6c0bd4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "venbind"
version = "0.0.2"
version = "0.0.3"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "venbind",
"version": "0.0.2",
"version": "0.0.3",
"description": "",
"types": "./lib/venbind.d.ts",
"scripts": {},
Expand Down
2 changes: 0 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ pub type Result<T> = std::result::Result<T, VenbindError>;
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),
Expand Down
16 changes: 8 additions & 8 deletions src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
22 changes: 10 additions & 12 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,16 @@ pub(crate) fn xdg_preregister_keybinds(actions: Vec<PreRegisterAction>) -> 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(())
}
Expand Down

0 comments on commit c6c0bd4

Please sign in to comment.