{"id":13800853,"url":"https://github.com/ahkohd/tauri-awesome-rpc","last_synced_at":"2025-07-20T17:33:56.232Z","repository":{"id":37036053,"uuid":"494189866","full_name":"ahkohd/tauri-awesome-rpc","owner":"ahkohd","description":"Custom invoke system for Tauri that leverages WebSocket","archived":false,"fork":false,"pushed_at":"2025-02-06T22:03:22.000Z","size":562,"stargazers_count":76,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2025-07-19T08:58:57.417Z","etag":null,"topics":["gui","rust","tauri","wry"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahkohd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.spdx","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-19T18:38:55.000Z","updated_at":"2025-07-02T12:04:33.000Z","dependencies_parsed_at":"2024-01-05T21:22:59.423Z","dependency_job_id":"d07d77e6-cec9-4c1d-96fc-f5b01b2f0cd8","html_url":"https://github.com/ahkohd/tauri-awesome-rpc","commit_stats":{"total_commits":37,"total_committers":4,"mean_commits":9.25,"dds":0.2702702702702703,"last_synced_commit":"275bb77568e8709ae41cc94c2e720d211fccd9df"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahkohd/tauri-awesome-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkohd%2Ftauri-awesome-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkohd%2Ftauri-awesome-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkohd%2Ftauri-awesome-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkohd%2Ftauri-awesome-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahkohd","download_url":"https://codeload.github.com/ahkohd/tauri-awesome-rpc/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahkohd%2Ftauri-awesome-rpc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266166048,"owners_count":23886727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gui","rust","tauri","wry"],"created_at":"2024-08-04T00:01:16.969Z","updated_at":"2025-07-20T17:33:56.193Z","avatar_url":"https://github.com/ahkohd.png","language":"Rust","funding_links":[],"categories":["Rust","tauri","Development"],"sub_categories":["Plugins"],"readme":"# 😎 tauri-awesome-rpc\n\nThis is a crate provides a custom invoke system for Tauri using a localhost JSON RPC WebSocket.\nEach message is delivered through Websocket using JSON RPC 2.0 [specification](https://www.jsonrpc.org/specification).\n\nWith the advantage of using websocket, `tauri-awesome-rpc` also provides an event API. With `AwesomeEmit` you can emit event from the Rust backend and `AwesomeEvent` to listen to the event on the frontend.\n\n## Usage\n\nFirst, add the dependency to your `src-tauri/Cargo.toml` file:\n\n```\n[dependencies]\ntauri-awesome-rpc = { git = \"https://github.com/ahkohd/tauri-awesome-rpc\", branch = \"dev\" }\n```\n\nThen, setup the Websocket JSON RPC invoke system on the `main.rs` file:\n\n```rust\nuse tauri::{Manager, Window, Wry};\nuse tauri_awesome_rpc::{AwesomeEmit, AwesomeRpc};\nuse serde_json::json;\n\nfn main() {\n  #[cfg(dev)]\n  let allowed_domain = {\n    let config: tauri_utils::config::Config = serde_json::from_value(\n      tauri_utils::config::parse::read_from(std::env::current_dir().unwrap()).unwrap(),\n    )\n    .unwrap();\n    config.build.dev_path.to_string()\n  };\n\n  #[cfg(not(dev))]\n  let allowed_domain = \"tauri://localhost\".to_string();\n\n  let awesome_rpc = AwesomeRpc::new(vec![\u0026allowed_domain]);\n\n  tauri::Builder::default()\n    .invoke_system(awesome_rpc.initialization_script(), AwesomeRpc::responder())\n    .setup(move |app| {\n      awesome_rpc.start(app.handle());\n      Ok(())\n    })\n    .invoke_handler(tauri::generate_handler![test_command, report_time_elapsed])\n    .run(tauri::generate_context!())\n    .expect(\"error while running tauri application\")\n}\n\n#[tauri::command]\nfn test_command(args: u64) -\u003e Result\u003cString, ()\u003e {\n  println!(\"executed command with args {:?}\", args);\n  Ok(\"executed\".into())\n}\n\n#[tauri::command]\nfn report_time_elapsed(window: Window\u003cWry\u003e) {\n  tauri::async_runtime::spawn(async move {\n    let mut interval = tokio::time::interval(tokio::time::Duration::from_millis(250));\n    let start_time = std::time::Instant::now();\n\n    loop {\n      interval.tick().await;\n\n      // emit an awesome event to the main window\n      window\n        .state::\u003cAwesomeEmit\u003e()\n        .emit(\"main\", \"time_elapsed\", json!(start_time.elapsed()));\n    }\n  });\n}\n```\n\nThen, on the frontend:\n\n```html\n\u003chtml\u003e\n  \u003cbody\u003e\n    \u003cdiv\u003e\n      \u003ch1\u003etauri-awesome-rpc\u003c/h1\u003e\n\n      \u003ch5\u003einvoke test\u003c/h5\u003e\n      \u003cdiv id=\"response\"\u003e\u003c/div\u003e\n\n      \u003ch5\u003eAwesomeEvent.listen test\u003c/h5\u003e\n      \u003cdiv id=\"time_elapsed\"\u003e\u003c/div\u003e\n    \u003c/div\u003e\n    \u003cscript type=\"module\" src=\"/src/main.ts\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n- Use your Tauri `invoke` method as usual.\n- Use `window.AwesomeEvent` to listen to the events emitted using `AwesomeEmit` from the Rust backend.\n\n```ts\nimport { invoke } from \"@tauri-apps/api/tauri\";\n\nconst response = document.getElementById(\"response\") as HTMLDivElement;\nconst timeElapsed = document.getElementById(\"time_elapsed\") as HTMLDivElement;\n\ninvoke(\"test_command\", { args: 5 })\n  .then((data) =\u003e {\n    response.innerText = data as string;\n  })\n  .catch(console.error);\n\ninvoke(\"report_time_elapsed\");\n\nconst _unsubscribe = window.AwesomeEvent.listen(\"time_elapsed\", (data) =\u003e {\n  timeElapsed.innerText = JSON.stringify(data);\n});\n```\n\nAdd the following type definition to your project's `global.d.ts` file:\n\n```typescript\ninterface Window {\n  AwesomeEvent: {\n    listen(eventName: string, callback: (data) =\u003e void): () =\u003e void;\n  };\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahkohd%2Ftauri-awesome-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahkohd%2Ftauri-awesome-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahkohd%2Ftauri-awesome-rpc/lists"}