-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d77382c
commit 95bbf5a
Showing
14 changed files
with
254 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::collections::HashSet; | ||
|
||
use proc_macro2::{Ident, TokenStream}; | ||
use quote::{format_ident, quote}; | ||
use syn::punctuated::Punctuated; | ||
use syn::token::Comma; | ||
use syn::{parse_quote, ExprPath}; | ||
|
||
pub fn commands_with_mod_name(mod_name: &str, commands: &HashSet<String>) -> HashSet<String> { | ||
commands | ||
.iter() | ||
.map(|cmd| format!("{mod_name}::{cmd}")) | ||
.collect() | ||
} | ||
|
||
pub fn commands_to_punctuated(commands: &HashSet<String>) -> Punctuated<ExprPath, Comma> { | ||
commands.iter().map(command_to_expr_path).collect() | ||
} | ||
|
||
pub fn command_to_expr_path(command: &String) -> ExprPath { | ||
match get_separated_command(command) { | ||
None => { | ||
let ident = format_ident!("{command}"); | ||
parse_quote!(#ident) | ||
} | ||
Some((mod_name, cmd_name)) => parse_quote!(#mod_name::#cmd_name), | ||
} | ||
} | ||
|
||
pub fn get_separated_command(input: &str) -> Option<(Ident, Ident)> { | ||
let mut split_cmd = input.split("::"); | ||
let mod_name = format_ident!("{}", split_cmd.next()?); | ||
// order matters | ||
let cmd_name = format_ident!("{}", split_cmd.next()?); | ||
|
||
Some((mod_name, cmd_name)) | ||
} | ||
|
||
pub fn get_handler_function( | ||
fn_name: Ident, | ||
commands: &HashSet<String>, | ||
handlers: Punctuated<ExprPath, Comma>, | ||
include_mods: Vec<ExprPath>, | ||
) -> TokenStream { | ||
let commands = commands.iter().collect::<Vec<_>>(); | ||
quote! { | ||
#[cfg(not(target_family = "wasm"))] | ||
#[doc = "auto generated function to register all configured commands"] | ||
pub fn #fn_name() -> impl Fn(tauri::Invoke) { | ||
#( use #include_mods; )* | ||
|
||
let handlers = vec! [ #( #commands ),* ]; | ||
log::debug!("Registering following commands to tauri: {handlers:#?}"); | ||
|
||
::tauri::generate_handler![ #handlers ] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,3 +86,5 @@ pub mod broken { | |
Ok(()) | ||
} | ||
} | ||
|
||
tauri_interop::collect_commands!(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
#![allow(clippy::disallowed_names)] | ||
#![feature(iter_intersperse)] | ||
#![feature(proc_macro_hygiene)] | ||
|
||
#[tauri_interop::commands] | ||
pub mod cmd; | ||
|
||
pub mod command; | ||
pub mod model; | ||
|
||
#[cfg(target_family = "wasm")] | ||
pub use tauri_interop::*; | ||
|
||
tauri_interop::combine_handlers!( cmd, model::other_cmd ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tauri_interop::host_usage! { | ||
use tauri_interop::command::TauriAppHandle; | ||
} | ||
|
||
#[tauri_interop::command] | ||
pub fn stop_application(handle: TauriAppHandle) { | ||
handle.exit(0) | ||
} | ||
|
||
tauri_interop::collect_commands!(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.