MatsDK / TauRPC

Typesafe IPC layer for Tauri applications
https://docs.rs/taurpc/
Apache License 2.0
75 stars 5 forks source link

Procedures without root and procedures paths without root will not execute functions even though compilation and codegen doesn't produce error. #22

Closed mnpqraven closed 5 months ago

mnpqraven commented 5 months ago

The title might be a bit hard to understand. Let me explain this further, i'll start with what i've experience with the procedure path

Given these 2 procedures

#[taurpc::procedures(path = "actions.file", export_to = "../src/bindings/taurpc.ts")]
pub trait FileAction {
    async fn copy() -> Result<(), AppErrorIpc>;
}

#[taurpc::procedures(path = "actions.ui", export_to = "../src/bindings/taurpc.ts")]
pub trait UiAction {
    async fn toggleExpand() -> Result<(), AppErrorIpc>;
}

This will compile with no errors and the TS codegen will also generate the correct path for me (taurpc.actions.file.copy() and taurpc.actions.ui.toggleExpand()), but the functions will not get called in rust side if there's no root path (actions), both .file and .ui routes now can't be called. If I change either of them to the root (either actions.file or actions.ui to `actions) then both routers work.

This behavior is also present when using the router.merge(). Here's what i have to do in my code base to have routing working by having a hello world root:

// Root procedures
// NOTE: we need exactly 1 root else the whole router breaks
#[taurpc::procedures]
pub trait Api {
    async fn hello_world();
}

#[derive(Clone)]
pub struct ApiImpl;

#[taurpc::resolvers]
impl Api for ApiImpl {
    async fn hello_world(self) {
        println!("Hello world");
    }
}

pub async fn create_router() -> Result<Router, String> {
    let initial_state = AppStateArc::new().await?;
    Ok(Router::new()
        .merge(ApiImpl.into_handler())
        // data
        .merge(Data::into_handler(initial_state.clone()))
        // actions.ui
        .merge(UIAction::into_handler(initial_state.clone()))
        // actions.file
        .merge(FileAction::into_handler(initial_state)))
}

none of the above route would work if i don't have ApiImpl

MatsDK commented 5 months ago

I fixed your issues in the latest release, you should update these versions in your Cargo.toml

taurpc = "0.2.6"

specta = { version = "=2.0.0-rc.9", features = ["export"] }

And on the frontend you should also upgrade taurpc

pnpm install taurpc@1.4.4

21 should also be fixed now, let me know if everything works.

mnpqraven commented 5 months ago

both this and #21 seems to be working now. I appreciate a lot the quick replies !