From 2c3e269690ae0112bb5b28074e82665e444d87b4 Mon Sep 17 00:00:00 2001 From: Jonas Kruckenberg Date: Sun, 10 Sep 2023 19:23:08 +0200 Subject: [PATCH] wip --- Cargo.toml | 1 + crates/gen-host/src/lib.rs | 6 +- crates/gen-host/tests/chars.rs | 8 +- crates/gen-host/tests/conventions.rs | 28 ++-- crates/gen-host/tests/empty.rs | 4 +- crates/gen-host/tests/flegs.rs | 18 +-- crates/gen-host/tests/floats.rs | 12 +- crates/gen-host/tests/integers.rs | 48 +++---- crates/gen-host/tests/lists.rs | 70 ++++----- crates/gen-host/tests/many-arguments.rs | 8 +- crates/gen-host/tests/multi-return.rs | 14 +- crates/gen-host/tests/records.rs | 26 ++-- crates/gen-host/tests/resources.rs | 8 +- crates/gen-host/tests/simple-functions.rs | 16 +-- crates/gen-host/tests/simple-lists.rs | 12 +- crates/gen-host/tests/small-anonymous.rs | 6 +- crates/gen-host/tests/strings.rs | 10 +- crates/gen-host/tests/unions.rs | 24 ++-- crates/gen-host/tests/variants.rs | 52 +++---- crates/host/Cargo.toml | 2 +- crates/ipc-router-wip/Cargo.toml | 4 +- crates/ipc-router-wip/src/lib.rs | 166 +++++++++++++--------- examples/greet/src-tauri/Cargo.toml | 2 +- examples/greet/src-tauri/tauri.conf.json | 6 - 24 files changed, 291 insertions(+), 260 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8db5e25..ca9cb1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ serde = "1.0.188" quote = "1.0.33" proc-macro2 = "1.0.66" syn = "2.0.31" +tauri = { git = "https://github.com/tauri-apps/tauri" } [dependencies] clap.workspace = true diff --git a/crates/gen-host/src/lib.rs b/crates/gen-host/src/lib.rs index ee9a441..a0c8a06 100644 --- a/crates/gen-host/src/lib.rs +++ b/crates/gen-host/src/lib.rs @@ -334,7 +334,7 @@ impl Host { router.func_wrap( #mod_name, #func_name, - move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, #params| -> ::tauri_bindgen_host::anyhow::Result<#result> { + move |ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, #params| -> ::tauri_bindgen_host::anyhow::Result<#result> { let ctx = get_cx(ctx.data()); Ok(ctx.#func_ident(#(#param_idents),*)) @@ -344,8 +344,8 @@ impl Host { }); quote! { - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where diff --git a/crates/gen-host/tests/chars.rs b/crates/gen-host/tests/chars.rs index 5ba05e8..5f9a0d3 100644 --- a/crates/gen-host/tests/chars.rs +++ b/crates/gen-host/tests/chars.rs @@ -9,8 +9,8 @@ pub mod chars { ///A function that returns a character fn return_char(&self) -> char; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -23,7 +23,7 @@ pub mod chars { "chars", "take_char", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: char, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -36,7 +36,7 @@ pub mod chars { "chars", "return_char", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.return_char()) diff --git a/crates/gen-host/tests/conventions.rs b/crates/gen-host/tests/conventions.rs index 93df9f7..da1f2e7 100644 --- a/crates/gen-host/tests/conventions.rs +++ b/crates/gen-host/tests/conventions.rs @@ -23,8 +23,8 @@ pub mod conventions { fn explicit_snake(&self); fn bool(&self); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -37,7 +37,7 @@ pub mod conventions { "conventions", "kebab_case", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.kebab_case()) @@ -49,7 +49,7 @@ pub mod conventions { "conventions", "foo", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: LudicrousSpeed, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -62,7 +62,7 @@ pub mod conventions { "conventions", "function_with_underscores", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.function_with_underscores()) @@ -74,7 +74,7 @@ pub mod conventions { "conventions", "function_with_no_weird_characters", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.function_with_no_weird_characters()) @@ -86,7 +86,7 @@ pub mod conventions { "conventions", "apple", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.apple()) @@ -98,7 +98,7 @@ pub mod conventions { "conventions", "apple_pear", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.apple_pear()) @@ -110,7 +110,7 @@ pub mod conventions { "conventions", "apple_pear_grape", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.apple_pear_grape()) @@ -122,7 +122,7 @@ pub mod conventions { "conventions", "a0", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.a0()) @@ -134,7 +134,7 @@ pub mod conventions { "conventions", "is_xml", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.is_xml()) @@ -146,7 +146,7 @@ pub mod conventions { "conventions", "explicit", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.explicit()) @@ -158,7 +158,7 @@ pub mod conventions { "conventions", "explicit_snake", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.explicit_snake()) @@ -170,7 +170,7 @@ pub mod conventions { "conventions", "bool", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.bool()) diff --git a/crates/gen-host/tests/empty.rs b/crates/gen-host/tests/empty.rs index f21f546..d144751 100644 --- a/crates/gen-host/tests/empty.rs +++ b/crates/gen-host/tests/empty.rs @@ -4,8 +4,8 @@ pub mod empty { use ::tauri_bindgen_host::serde; use ::tauri_bindgen_host::bitflags; pub trait Empty: Sized {} - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where diff --git a/crates/gen-host/tests/flegs.rs b/crates/gen-host/tests/flegs.rs index 3a1d37d..510eab8 100644 --- a/crates/gen-host/tests/flegs.rs +++ b/crates/gen-host/tests/flegs.rs @@ -67,8 +67,8 @@ pub mod flegs { fn roundtrip_flag32(&self, x: Flag32) -> Flag32; fn roundtrip_flag64(&self, x: Flag64) -> Flag64; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -81,7 +81,7 @@ pub mod flegs { "flegs", "roundtrip_flag1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag1, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -94,7 +94,7 @@ pub mod flegs { "flegs", "roundtrip_flag2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag2, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -107,7 +107,7 @@ pub mod flegs { "flegs", "roundtrip_flag4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag4, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -120,7 +120,7 @@ pub mod flegs { "flegs", "roundtrip_flag8", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag8, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -133,7 +133,7 @@ pub mod flegs { "flegs", "roundtrip_flag16", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag16, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -146,7 +146,7 @@ pub mod flegs { "flegs", "roundtrip_flag32", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag32, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -159,7 +159,7 @@ pub mod flegs { "flegs", "roundtrip_flag64", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Flag64, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/floats.rs b/crates/gen-host/tests/floats.rs index b64c552..2434a02 100644 --- a/crates/gen-host/tests/floats.rs +++ b/crates/gen-host/tests/floats.rs @@ -9,8 +9,8 @@ pub mod floats { fn float32_result(&self) -> f32; fn float64_result(&self) -> f64; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -23,7 +23,7 @@ pub mod floats { "floats", "float32_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: f32, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -36,7 +36,7 @@ pub mod floats { "floats", "float64_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: f64, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -49,7 +49,7 @@ pub mod floats { "floats", "float32_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.float32_result()) @@ -61,7 +61,7 @@ pub mod floats { "floats", "float64_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.float64_result()) diff --git a/crates/gen-host/tests/integers.rs b/crates/gen-host/tests/integers.rs index 1e2104d..07c6d59 100644 --- a/crates/gen-host/tests/integers.rs +++ b/crates/gen-host/tests/integers.rs @@ -39,8 +39,8 @@ pub mod integers { fn r10(&self) -> i128; fn pair_ret(&self) -> (i64, u8); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -53,7 +53,7 @@ pub mod integers { "integers", "a1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u8, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -66,7 +66,7 @@ pub mod integers { "integers", "a2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i8, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -79,7 +79,7 @@ pub mod integers { "integers", "a3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u16, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -92,7 +92,7 @@ pub mod integers { "integers", "a4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i16, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -105,7 +105,7 @@ pub mod integers { "integers", "a5", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u32, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -118,7 +118,7 @@ pub mod integers { "integers", "a6", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i32, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -131,7 +131,7 @@ pub mod integers { "integers", "a7", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u64, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -144,7 +144,7 @@ pub mod integers { "integers", "a8", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i64, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -157,7 +157,7 @@ pub mod integers { "integers", "a9", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: u128, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -170,7 +170,7 @@ pub mod integers { "integers", "a10", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: i128, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -183,7 +183,7 @@ pub mod integers { "integers", "a11", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, p1: u8, p2: i8, p3: u16, @@ -205,7 +205,7 @@ pub mod integers { "integers", "r1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r1()) @@ -217,7 +217,7 @@ pub mod integers { "integers", "r2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r2()) @@ -229,7 +229,7 @@ pub mod integers { "integers", "r3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r3()) @@ -241,7 +241,7 @@ pub mod integers { "integers", "r4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r4()) @@ -253,7 +253,7 @@ pub mod integers { "integers", "r5", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r5()) @@ -265,7 +265,7 @@ pub mod integers { "integers", "r6", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r6()) @@ -277,7 +277,7 @@ pub mod integers { "integers", "r7", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r7()) @@ -289,7 +289,7 @@ pub mod integers { "integers", "r8", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r8()) @@ -301,7 +301,7 @@ pub mod integers { "integers", "r9", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r9()) @@ -313,7 +313,7 @@ pub mod integers { "integers", "r10", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.r10()) @@ -325,7 +325,7 @@ pub mod integers { "integers", "pair_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<(i64, u8)> { let ctx = get_cx(ctx.data()); Ok(ctx.pair_ret()) diff --git a/crates/gen-host/tests/lists.rs b/crates/gen-host/tests/lists.rs index 6530779..3efc079 100644 --- a/crates/gen-host/tests/lists.rs +++ b/crates/gen-host/tests/lists.rs @@ -77,8 +77,8 @@ pub mod lists { fn variant_list(&self, x: Vec) -> Vec; fn load_store_everything(&self, a: LoadStoreAllSizes) -> LoadStoreAllSizes; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -91,7 +91,7 @@ pub mod lists { "lists", "list_u8_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -104,7 +104,7 @@ pub mod lists { "lists", "list_u16_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -117,7 +117,7 @@ pub mod lists { "lists", "list_u32_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -130,7 +130,7 @@ pub mod lists { "lists", "list_u64_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -143,7 +143,7 @@ pub mod lists { "lists", "list_u128_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -156,7 +156,7 @@ pub mod lists { "lists", "list_s8_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -169,7 +169,7 @@ pub mod lists { "lists", "list_s16_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -182,7 +182,7 @@ pub mod lists { "lists", "list_s32_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -195,7 +195,7 @@ pub mod lists { "lists", "list_s64_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -208,7 +208,7 @@ pub mod lists { "lists", "list_s128_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -221,7 +221,7 @@ pub mod lists { "lists", "list_float32_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -234,7 +234,7 @@ pub mod lists { "lists", "list_float64_param", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -247,7 +247,7 @@ pub mod lists { "lists", "list_u8_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u8_ret()) @@ -259,7 +259,7 @@ pub mod lists { "lists", "list_u16_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u16_ret()) @@ -271,7 +271,7 @@ pub mod lists { "lists", "list_u32_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u32_ret()) @@ -283,7 +283,7 @@ pub mod lists { "lists", "list_u64_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u64_ret()) @@ -295,7 +295,7 @@ pub mod lists { "lists", "list_u128_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_u128_ret()) @@ -307,7 +307,7 @@ pub mod lists { "lists", "list_s8_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s8_ret()) @@ -319,7 +319,7 @@ pub mod lists { "lists", "list_s16_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s16_ret()) @@ -331,7 +331,7 @@ pub mod lists { "lists", "list_s32_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s32_ret()) @@ -343,7 +343,7 @@ pub mod lists { "lists", "list_s64_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s64_ret()) @@ -355,7 +355,7 @@ pub mod lists { "lists", "list_s128_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_s128_ret()) @@ -367,7 +367,7 @@ pub mod lists { "lists", "list_float32_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_float32_ret()) @@ -379,7 +379,7 @@ pub mod lists { "lists", "list_float64_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.list_float64_ret()) @@ -391,7 +391,7 @@ pub mod lists { "lists", "tuple_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec<(u8, i8)>, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -404,7 +404,7 @@ pub mod lists { "lists", "string_list_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -417,7 +417,7 @@ pub mod lists { "lists", "string_list_ret", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.string_list_ret()) @@ -429,7 +429,7 @@ pub mod lists { "lists", "tuple_string_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec<(u8, String)>, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -442,7 +442,7 @@ pub mod lists { "lists", "string_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -455,7 +455,7 @@ pub mod lists { "lists", "record_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -468,7 +468,7 @@ pub mod lists { "lists", "record_list_reverse", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -481,7 +481,7 @@ pub mod lists { "lists", "variant_list", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Vec, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); @@ -494,7 +494,7 @@ pub mod lists { "lists", "load_store_everything", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: LoadStoreAllSizes, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/many-arguments.rs b/crates/gen-host/tests/many-arguments.rs index 13873ff..6077eb7 100644 --- a/crates/gen-host/tests/many-arguments.rs +++ b/crates/gen-host/tests/many-arguments.rs @@ -49,8 +49,8 @@ pub mod many_arguments { ); fn big_argument(&self, x: BigStruct); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -63,7 +63,7 @@ pub mod many_arguments { "many_arguments", "many_args", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a1: u64, a2: u64, a3: u64, @@ -111,7 +111,7 @@ pub mod many_arguments { "many_arguments", "big_argument", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: BigStruct, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/multi-return.rs b/crates/gen-host/tests/multi-return.rs index 1eceb2c..37ae0a5 100644 --- a/crates/gen-host/tests/multi-return.rs +++ b/crates/gen-host/tests/multi-return.rs @@ -10,8 +10,8 @@ pub mod multi_return { fn mrd(&self) -> u32; fn mre(&self) -> (u32, f32); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -24,7 +24,7 @@ pub mod multi_return { "multi_return", "mra", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.mra()) @@ -36,7 +36,7 @@ pub mod multi_return { "multi_return", "mrb", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.mrb()) @@ -48,7 +48,7 @@ pub mod multi_return { "multi_return", "mrc", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.mrc()) @@ -60,7 +60,7 @@ pub mod multi_return { "multi_return", "mrd", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.mrd()) @@ -72,7 +72,7 @@ pub mod multi_return { "multi_return", "mre", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<(u32, f32)> { let ctx = get_cx(ctx.data()); Ok(ctx.mre()) diff --git a/crates/gen-host/tests/records.rs b/crates/gen-host/tests/records.rs index 9de4a9a..b04eb93 100644 --- a/crates/gen-host/tests/records.rs +++ b/crates/gen-host/tests/records.rs @@ -55,8 +55,8 @@ All of the fields are bool*/ fn aggregate_result(&self) -> Aggregates; fn typedef_inout(&self, e: TupleTypedef2) -> i32; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -69,7 +69,7 @@ All of the fields are bool*/ "records", "tuple_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: (char, u32), | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -82,7 +82,7 @@ All of the fields are bool*/ "records", "tuple_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<(char, u32)> { let ctx = get_cx(ctx.data()); Ok(ctx.tuple_result()) @@ -94,7 +94,7 @@ All of the fields are bool*/ "records", "empty_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Empty, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -107,7 +107,7 @@ All of the fields are bool*/ "records", "empty_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.empty_result()) @@ -119,7 +119,7 @@ All of the fields are bool*/ "records", "scalar_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Scalars, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -132,7 +132,7 @@ All of the fields are bool*/ "records", "scalar_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.scalar_result()) @@ -144,7 +144,7 @@ All of the fields are bool*/ "records", "flags_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: ReallyFlags, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -157,7 +157,7 @@ All of the fields are bool*/ "records", "flags_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.flags_result()) @@ -169,7 +169,7 @@ All of the fields are bool*/ "records", "aggregate_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: Aggregates, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -182,7 +182,7 @@ All of the fields are bool*/ "records", "aggregate_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.aggregate_result()) @@ -194,7 +194,7 @@ All of the fields are bool*/ "records", "typedef_inout", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, e: TupleTypedef2, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/resources.rs b/crates/gen-host/tests/resources.rs index 394be6d..d443caa 100644 --- a/crates/gen-host/tests/resources.rs +++ b/crates/gen-host/tests/resources.rs @@ -25,8 +25,8 @@ pub mod resources { fn constructor_a(&self) -> ::tauri_bindgen_host::ResourceId; fn constructor_b(&self) -> ::tauri_bindgen_host::ResourceId; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -39,7 +39,7 @@ pub mod resources { "resources", "constructor_a", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result< ::tauri_bindgen_host::ResourceId, > { @@ -53,7 +53,7 @@ pub mod resources { "resources", "constructor_b", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result< ::tauri_bindgen_host::ResourceId, > { diff --git a/crates/gen-host/tests/simple-functions.rs b/crates/gen-host/tests/simple-functions.rs index 39b5e20..d3683d6 100644 --- a/crates/gen-host/tests/simple-functions.rs +++ b/crates/gen-host/tests/simple-functions.rs @@ -11,8 +11,8 @@ pub mod simple_functions { fn f5(&self) -> (u32, u32); fn f6(&self, a: u32, b: u32, c: u32) -> (u32, u32, u32); } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -25,7 +25,7 @@ pub mod simple_functions { "simple_functions", "f1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); Ok(ctx.f1()) @@ -37,7 +37,7 @@ pub mod simple_functions { "simple_functions", "f2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: u32, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -50,7 +50,7 @@ pub mod simple_functions { "simple_functions", "f3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: u32, b: u32, | -> ::tauri_bindgen_host::anyhow::Result<()> { @@ -64,7 +64,7 @@ pub mod simple_functions { "simple_functions", "f4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.f4()) @@ -76,7 +76,7 @@ pub mod simple_functions { "simple_functions", "f5", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result<(u32, u32)> { let ctx = get_cx(ctx.data()); Ok(ctx.f5()) @@ -88,7 +88,7 @@ pub mod simple_functions { "simple_functions", "f6", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: u32, b: u32, c: u32, diff --git a/crates/gen-host/tests/simple-lists.rs b/crates/gen-host/tests/simple-lists.rs index 85dd425..9bbc7c4 100644 --- a/crates/gen-host/tests/simple-lists.rs +++ b/crates/gen-host/tests/simple-lists.rs @@ -9,8 +9,8 @@ pub mod simple_lists { fn simple_list3(&self, a: Vec, b: Vec) -> (Vec, Vec); fn simple_list4(&self, l: Vec>) -> Vec>; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -23,7 +23,7 @@ pub mod simple_lists { "simple_lists", "simple_list1", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, l: Vec, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -36,7 +36,7 @@ pub mod simple_lists { "simple_lists", "simple_list2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.simple_list2()) @@ -48,7 +48,7 @@ pub mod simple_lists { "simple_lists", "simple_list3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Vec, b: Vec, | -> ::tauri_bindgen_host::anyhow::Result<(Vec, Vec)> { @@ -62,7 +62,7 @@ pub mod simple_lists { "simple_lists", "simple_list4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, l: Vec>, | -> ::tauri_bindgen_host::anyhow::Result>> { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/small-anonymous.rs b/crates/gen-host/tests/small-anonymous.rs index a3e1953..e8a9452 100644 --- a/crates/gen-host/tests/small-anonymous.rs +++ b/crates/gen-host/tests/small-anonymous.rs @@ -12,8 +12,8 @@ pub mod small_anonymous { pub trait SmallAnonymous: Sized { fn option_test(&self) -> Result, Error>; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -26,7 +26,7 @@ pub mod small_anonymous { "small_anonymous", "option_test", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result, Error>> { let ctx = get_cx(ctx.data()); Ok(ctx.option_test()) diff --git a/crates/gen-host/tests/strings.rs b/crates/gen-host/tests/strings.rs index 2801adb..347eda3 100644 --- a/crates/gen-host/tests/strings.rs +++ b/crates/gen-host/tests/strings.rs @@ -8,8 +8,8 @@ pub mod strings { fn b(&self) -> String; fn c(&self, a: String, b: String) -> String; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -22,7 +22,7 @@ pub mod strings { "strings", "a", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: String, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -35,7 +35,7 @@ pub mod strings { "strings", "b", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.b()) @@ -47,7 +47,7 @@ pub mod strings { "strings", "c", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: String, b: String, | -> ::tauri_bindgen_host::anyhow::Result { diff --git a/crates/gen-host/tests/unions.rs b/crates/gen-host/tests/unions.rs index efca91c..f040f0b 100644 --- a/crates/gen-host/tests/unions.rs +++ b/crates/gen-host/tests/unions.rs @@ -65,8 +65,8 @@ and is treated that way in some languages*/ ) -> DistinguishableNum; fn identify_distinguishable_num(&self, num: DistinguishableNum) -> u8; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -79,7 +79,7 @@ and is treated that way in some languages*/ "unions", "add_one_integer", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: AllIntegers, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -92,7 +92,7 @@ and is treated that way in some languages*/ "unions", "add_one_float", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: AllFloats, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -105,7 +105,7 @@ and is treated that way in some languages*/ "unions", "replace_first_char", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, text: AllText, letter: char, | -> ::tauri_bindgen_host::anyhow::Result { @@ -119,7 +119,7 @@ and is treated that way in some languages*/ "unions", "identify_integer", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: AllIntegers, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -132,7 +132,7 @@ and is treated that way in some languages*/ "unions", "identify_float", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: AllFloats, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -145,7 +145,7 @@ and is treated that way in some languages*/ "unions", "identify_text", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, text: AllText, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -158,7 +158,7 @@ and is treated that way in some languages*/ "unions", "add_one_duplicated", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: DuplicatedS32, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -171,7 +171,7 @@ and is treated that way in some languages*/ "unions", "identify_duplicated", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: DuplicatedS32, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -184,7 +184,7 @@ and is treated that way in some languages*/ "unions", "add_one_distinguishable_num", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: DistinguishableNum, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); @@ -197,7 +197,7 @@ and is treated that way in some languages*/ "unions", "identify_distinguishable_num", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, num: DistinguishableNum, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); diff --git a/crates/gen-host/tests/variants.rs b/crates/gen-host/tests/variants.rs index 8781692..e1d4a34 100644 --- a/crates/gen-host/tests/variants.rs +++ b/crates/gen-host/tests/variants.rs @@ -145,8 +145,8 @@ pub mod variants { fn return_named_option(&self) -> Option; fn return_named_result(&self) -> Result; } - pub fn add_to_router( - router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, + pub fn add_to_router( + router: &mut ::tauri_bindgen_host::ipc_router_wip::Router, get_cx: impl Fn(&T) -> &U + Send + Sync + 'static, ) -> Result<(), ::tauri_bindgen_host::ipc_router_wip::Error> where @@ -159,7 +159,7 @@ pub mod variants { "variants", "e1_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: E1, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -172,7 +172,7 @@ pub mod variants { "variants", "e1_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.e1_result()) @@ -184,7 +184,7 @@ pub mod variants { "variants", "u1_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: U1, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -197,7 +197,7 @@ pub mod variants { "variants", "u1_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.u1_result()) @@ -209,7 +209,7 @@ pub mod variants { "variants", "v1_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: V1, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -222,7 +222,7 @@ pub mod variants { "variants", "v1_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.v1_result()) @@ -234,7 +234,7 @@ pub mod variants { "variants", "bool_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, x: bool, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -247,7 +247,7 @@ pub mod variants { "variants", "bool_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.bool_result()) @@ -259,7 +259,7 @@ pub mod variants { "variants", "option_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Option, b: Option<()>, c: Option, @@ -278,7 +278,7 @@ pub mod variants { "variants", "option_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result< ( Option, @@ -300,7 +300,7 @@ pub mod variants { "variants", "casts", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Casts1, b: Casts2, c: Casts3, @@ -320,7 +320,7 @@ pub mod variants { "variants", "result_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: Result<(), ()>, b: Result<(), E1>, c: Result, @@ -338,7 +338,7 @@ pub mod variants { "variants", "result_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result< ( Result<(), ()>, @@ -359,7 +359,7 @@ pub mod variants { "variants", "return_result_sugar", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar()) @@ -371,7 +371,7 @@ pub mod variants { "variants", "return_result_sugar2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar2()) @@ -383,7 +383,7 @@ pub mod variants { "variants", "return_result_sugar3", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar3()) @@ -395,7 +395,7 @@ pub mod variants { "variants", "return_result_sugar4", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_result_sugar4()) @@ -407,7 +407,7 @@ pub mod variants { "variants", "return_option_sugar", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_option_sugar()) @@ -419,7 +419,7 @@ pub mod variants { "variants", "return_option_sugar2", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_option_sugar2()) @@ -431,7 +431,7 @@ pub mod variants { "variants", "result_simple", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.result_simple()) @@ -443,7 +443,7 @@ pub mod variants { "variants", "is_clone_arg", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, a: IsClone, | -> ::tauri_bindgen_host::anyhow::Result<()> { let ctx = get_cx(ctx.data()); @@ -456,7 +456,7 @@ pub mod variants { "variants", "is_clone_return", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result { let ctx = get_cx(ctx.data()); Ok(ctx.is_clone_return()) @@ -468,7 +468,7 @@ pub mod variants { "variants", "return_named_option", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_named_option()) @@ -480,7 +480,7 @@ pub mod variants { "variants", "return_named_result", move | - ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, + ctx: ::tauri_bindgen_host::ipc_router_wip::Caller, | -> ::tauri_bindgen_host::anyhow::Result> { let ctx = get_cx(ctx.data()); Ok(ctx.return_named_result()) diff --git a/crates/host/Cargo.toml b/crates/host/Cargo.toml index 59b2984..6a1dd31 100644 --- a/crates/host/Cargo.toml +++ b/crates/host/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true bitflags.workspace = true tauri-bindgen-host-macro = { path = "../host-macro" } async-trait = "0.1.73" -tauri = "1.4.1" +tauri.workspace = true tracing = { version = "0.1.37", features = ["log", "log-always"] } anyhow = "1.0.75" serde.workspace = true diff --git a/crates/ipc-router-wip/Cargo.toml b/crates/ipc-router-wip/Cargo.toml index 99a79fd..ccf580b 100644 --- a/crates/ipc-router-wip/Cargo.toml +++ b/crates/ipc-router-wip/Cargo.toml @@ -12,5 +12,5 @@ anyhow = "1.0.75" serde.workspace = true log.workspace = true postcard = { version = "1.0.7", features = ["alloc"] } -tauri = "1.4.1" -url = "2.4.1" +tauri.workspace = true +tokio = { version = "1.32.0", features = ["sync", "macros"] } diff --git a/crates/ipc-router-wip/src/lib.rs b/crates/ipc-router-wip/src/lib.rs index 014a0d9..1325360 100644 --- a/crates/ipc-router-wip/src/lib.rs +++ b/crates/ipc-router-wip/src/lib.rs @@ -4,31 +4,42 @@ pub use anyhow::Error; use anyhow::{bail, Result}; use std::{ collections::{hash_map::Entry, HashMap}, - sync::{mpsc::Sender, Arc, Mutex}, + sync::Arc, +}; +use tauri::{ + http::{header::CONTENT_TYPE, Request, Response, StatusCode}, + AppHandle, Runtime, +}; +use tokio::sync::{ + mpsc, + oneshot::{self, Sender}, }; -use tauri::{AppHandle, Manager, Runtime}; -use url::Url; #[derive(Default)] -pub struct Router { +pub struct Router { data: Arc, string2idx: HashMap, usize>, strings: Vec>, - map: HashMap>, + map: HashMap>, } -pub type Definition = - Box, &[u8], Sender>) -> anyhow::Result<()> + Send + Sync>; +pub type Definition = + Box, &[u8], Sender>) -> anyhow::Result<()> + Send + Sync>; -pub struct Caller<'a, T> { +pub struct Caller<'a, T, R: Runtime> { data: &'a T, + app_handle: AppHandle, } -impl<'a, T> Caller<'a, T> { +impl<'a, T, R: Runtime> Caller<'a, T, R> { #[must_use] pub fn data(&self) -> &T { self.data } + #[must_use] + pub fn app_handle(&self) -> &AppHandle { + &self.app_handle + } } #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] @@ -37,7 +48,7 @@ struct ImportKey { name: usize, } -impl Router { +impl Router { #[must_use] pub fn new(data: U) -> Self { Self { @@ -52,7 +63,7 @@ impl Router { &mut self, module: &str, name: &str, - func: impl IntoFunc, + func: impl IntoFunc, ) -> Result<&mut Self> { let func = func.into_func(); @@ -67,7 +78,8 @@ impl Router { module: Option>, name: impl AsRef, params: &[u8], - res_tx: Sender>, + app_handle: AppHandle, + tx: Sender>, ) -> anyhow::Result<()> { let key = self.import_key(module, name.as_ref()); @@ -76,14 +88,17 @@ impl Router { .get(&key) .ok_or(anyhow::anyhow!("method not found"))?; - let caller = Caller { data: &*self.data }; + let caller = Caller { + data: &*self.data, + app_handle, + }; - handler(caller, params, res_tx)?; + handler(caller, params, tx)?; Ok(()) } - fn insert(&mut self, key: ImportKey, item: Definition) -> Result<()> { + fn insert(&mut self, key: ImportKey, item: Definition) -> Result<()> { match self.map.entry(key) { Entry::Occupied(_) => { let module = &self.strings[key.module]; @@ -119,9 +134,9 @@ impl Router { } } -pub trait IntoFunc: Send + Sync { +pub trait IntoFunc: Send + Sync { #[doc(hidden)] - fn into_func(self) -> Definition; + fn into_func(self) -> Definition; } macro_rules! impl_into_func { @@ -130,14 +145,14 @@ macro_rules! impl_into_func { // delegating to the implementation below which does have the leading // `Caller` parameter. #[allow(non_snake_case)] - impl IntoFunc for F + impl IntoFunc for F where F: Fn($($params),*) -> anyhow::Result + Send + Sync + 'static, $($params: serde::de::DeserializeOwned,)* - R: serde::Serialize + R: serde::Serialize, { - fn into_func(self) -> Definition { - let f = move |_: Caller, $($params:$params),*| { + fn into_func(self) -> Definition { + let f = move |_: Caller, $($params:$params),*| { self($($params),*) }; @@ -146,13 +161,13 @@ macro_rules! impl_into_func { } #[allow(non_snake_case)] - impl IntoFunc, $($params,)*), R> for F + impl IntoFunc, $($params,)*), R, Rt> for F where - F: Fn(Caller, $($params),*) -> anyhow::Result + Send + Sync + 'static, + F: Fn(Caller, $($params),*) -> anyhow::Result + Send + Sync + 'static, $($params: serde::de::DeserializeOwned,)* - R: serde::Serialize + R: serde::Serialize, { - fn into_func(self) -> Definition { + fn into_func(self) -> Definition { Box::new(move |caller, params, tx| { log::debug!("Deserializing parameters..."); let ($($params,)*) = postcard::from_bytes(params)?; @@ -163,7 +178,7 @@ macro_rules! impl_into_func { log::debug!("Serializing response..."); let out = postcard::to_allocvec(&out)?; - tx.send(out)?; + tx.send(out).unwrap(); Ok(()) }) @@ -196,66 +211,87 @@ macro_rules! for_each_function_signature { for_each_function_signature!(impl_into_func); -pub trait BuilderExt { +pub trait BuilderExt { #[must_use] - fn ipc_router(self, router: Router) -> Self; + fn ipc_router(self, router: Router) -> Self; } -impl BuilderExt for tauri::Builder { - fn ipc_router(self, router: Router) -> Self { - self.manage(Mutex::new(router)) - .register_uri_scheme_protocol("ipc", |app, req| { - let res = uri_scheme_handler_inner::(app, req); +impl BuilderExt for tauri::Builder { + fn ipc_router(self, mut router: Router) -> Self { + let (tx, mut rx) = mpsc::channel::<(AppHandle, Request>, _)>(250); + + let this = + self.register_asynchronous_uri_scheme_protocol("ipc", move |app, req, responder| { + tx.try_send((app.clone(), req, responder)).unwrap(); + }); + + tauri::async_runtime::handle().spawn(async move { + while let Some((app, req, responder)) = rx.recv().await { + let path = req.uri().path().strip_prefix('/').unwrap(); + + let (module, method) = path + .split_once('/') + .map_or((None, path), |(module, method)| (Some(module), method)); + + log::debug!("ipc request for {:?}::{}", module, method); + + let (tx, rx) = oneshot::channel(); + router + .handle_request(module, method, req.body(), app, tx) + .unwrap(); + let res = rx.await; log::debug!("call result {:?}", res); - let mut resp = match res { + let mut response = match res { Ok(val) => { - let mut resp = tauri::http::Response::new(val); - resp.set_status(tauri::http::status::StatusCode::OK); - resp.set_mimetype(Some("application/octet-stream".to_string())); - resp - } - Err(err) => { - let mut resp = tauri::http::Response::new(err.to_string().into_bytes()); - resp.set_status(tauri::http::status::StatusCode::BAD_REQUEST); - resp + let mut resp = Response::builder().status(StatusCode::OK); + resp.headers_mut().unwrap().insert( + CONTENT_TYPE, + tauri::http::header::HeaderValue::from_static( + "application/octet-stream", + ), + ); + resp.body(val).unwrap() } + Err(err) => Response::builder() + .status(StatusCode::BAD_REQUEST) + .body(err.to_string().into_bytes()) + .unwrap(), }; - resp.headers_mut().insert( + response.headers_mut().insert( tauri::http::header::ACCESS_CONTROL_ALLOW_ORIGIN, tauri::http::header::HeaderValue::from_static("*"), ); - log::trace!("sending response {:?}", resp); + responder.respond(response); + } + }); - Ok(resp) - }) + this } } -fn uri_scheme_handler_inner( - app: &AppHandle, - req: &tauri::http::Request, -) -> anyhow::Result> { - let url = Url::parse(req.uri())?; +// async fn uri_scheme_handler_inner( +// app: &AppHandle, +// req: &tauri::http::Request>, +// ) -> anyhow::Result> { +// let path = req.uri().path().strip_prefix('/').unwrap(); - let path = url.path().strip_prefix('/').unwrap(); +// let (module, method) = path +// .split_once('/') +// .map_or((None, path), |(module, method)| (Some(module), method)); - let (module, method) = path - .split_once('/') - .map_or((None, path), |(module, method)| (Some(module), method)); +// log::debug!("ipc request for {:?}::{}", module, method); - log::debug!("ipc request for {:?}::{}", module, method); +// let (res_tx, res_rx) = oneshot::channel(); - let (res_tx, res_rx) = std::sync::mpsc::channel(); +// let router = app.state::>>(); +// let mut router = router.lock().unwrap(); - let router = app.state::>>(); - let mut router = router.lock().unwrap(); +// // this is terrible we should not clone here +// router.handle_request(module, method, req.body(), res_tx)?; - // this is terrible we should not clone here - router.handle_request(module, method, req.body(), res_tx)?; - - Ok(res_rx.recv()?) -} +// Ok(res_rx.await?) +// } diff --git a/examples/greet/src-tauri/Cargo.toml b/examples/greet/src-tauri/Cargo.toml index eea277e..c995120 100644 --- a/examples/greet/src-tauri/Cargo.toml +++ b/examples/greet/src-tauri/Cargo.toml @@ -16,7 +16,7 @@ tauri-build = { version = "1.1", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.2.4", features = ["api-all"] } +tauri = { git = "https://github.com/tauri-apps/tauri" } tauri-bindgen-host = { path = "../../../crates/host" } tracing-subscriber = "0.3.16" tracing = "0.1.37" diff --git a/examples/greet/src-tauri/tauri.conf.json b/examples/greet/src-tauri/tauri.conf.json index 15e818e..828dc27 100644 --- a/examples/greet/src-tauri/tauri.conf.json +++ b/examples/greet/src-tauri/tauri.conf.json @@ -11,9 +11,6 @@ "version": "0.0.0" }, "tauri": { - "allowlist": { - "all": true - }, "bundle": { "active": true, "category": "DeveloperTool", @@ -50,9 +47,6 @@ "security": { "csp": null }, - "updater": { - "active": false - }, "windows": [ { "fullscreen": false,