Skip to content

Commit

Permalink
Merge pull request #15 from photovoltex/underscore-problem
Browse files Browse the repository at this point in the history
Resolve the existing underscore problem
  • Loading branch information
photovoltex authored Mar 2, 2024
2 parents a9ace31 + 3fd53d3 commit 3d8fd45
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ fn main() {
```

## Known Issues:
- arguments used in `tauri::command` beginning with `_` aren't supported yet
- due to [tauri internally converting the argument name](https://tauri.app/v1/guides/features/command#passing-arguments),
which results in losing the _ at the beginning
- feature: leptos
- sometimes a closure is accessed after being dropped
- that is probably a race condition where the unlisten function doesn't detach the callback fast enough
16 changes: 10 additions & 6 deletions tauri-interop-macro/src/command/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ pub fn prepare(function: ItemFn) -> InvokeCommand {
false
};

match typed.pat.as_ref() {
Pat::Ident(ident) => Some(FieldArg {
ident: ident.ident.clone(),
argument: fn_arg,
requires_lifetime: req_lf,
}),
match typed.pat.as_mut() {
Pat::Ident(ident) => {
// converting the ident to snake case, so it matches the expected snake case
ident.ident = format_ident!("{}", ident.ident.to_string().to_case(Case::Snake));
Some(FieldArg {
ident: ident.ident.clone(),
argument: fn_arg,
requires_lifetime: req_lf,
})
},
_ => None,
}
})
Expand Down
3 changes: 3 additions & 0 deletions test-project/api/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ tauri_interop::host_usage! {
#[tauri_interop::command]
pub fn empty_invoke() {}

#[tauri_interop::command]
pub fn underscore_invoke(_invoke: u8) {}

#[tauri_interop::command]
pub async fn await_heavy_computing() {
std::thread::sleep(std::time::Duration::from_millis(5000))
Expand Down
1 change: 1 addition & 0 deletions test-project/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn main() {
console_error_panic_hook::set_once();

api::cmd::empty_invoke();
api::cmd::underscore_invoke(69);

wasm_bindgen_futures::spawn_local(async {
log::info!("{}", api::cmd::greet("frontend").await);
Expand Down

0 comments on commit 3d8fd45

Please sign in to comment.