Bite Sized Tech is a participant in Unity Affiliate Program, Liquid Web Affiliate Program, Hostinger Affiliate Program, Namecheap Affiliate Program, Envato Elements Affiliate Program, Adobe Affiliate Program and SteelSeries Affiliate Program under which we might earn commission when visitors use our Affiliate Links and makes qualifying purchases.


#5 Tauri Inter-Process Communication – Events & Commands | Minimalist Text Editor in Rust Programming Language & Tauri | Rust & Tauri Development Tutorial


Inter-Process Communication (IPC) in Tauri, is what gives it the backbone

for creating an extremely secure application environment.

In this Article, we will take a closer look at

  • What is Inter-Process Communication (IPC) and How it’s done in Tauri
  • What are Events in Tauri
  • And Finally, What are Commands in Tauri

to get an better and comprehensive view on

How Tauri securely communicates between it’s Core Process and WebView Processes.

So, without further ado, let’s get started!


This Article is part of Minimalist Text Editor Using Rust and Tauri Tutorial Series


Minimalist Text Editor in Rust Programming Language & Tauri - #5 Tauri Inter Process Communication - Events & Commands - Rust & Tauri Tutorial - Featured Image


What is Inter-Process Communication (IPC) and How it’s done in Tauri

Inter-Process Communication (IPC) as the name suggests is the communication that happens between Processes.

In Tauri, we have the Core process that is responsible for all the business logic of the application

and the WebView Processes which are responsible for the GUI (Graphical User Interface) part of the application.

Now, these processes are completely isolated from each other

so we need a way to communicate securely between these isolated processes.

Tauri uses a particular type of Inter-Process Communication known as Asynchronous Message Passing

frequently used in Web Development, for Client-Server communication over the internet.

So, basically a WebView Process which uses Web Technologies like HTML, CSS, JavaScript, Svelte, Vue.js, etc

will not have Direct Access to Functions and Methods in the Rust Backend

instead this WebView Process will have to pass a message to request the Core Process to invoke that function or method

and then the Core Process will receive the request, consider whether it is a malicious request or not

to finally process and give response for the request

or throw it away if the Core Process thinks that it’s a malicious request.

Message Passing is a more secure way of communicating than having Shared Memory or Direct Function Access

as you might be able to understand from the rather vague example above

because the recipient of the request has the authority of accepting or rejecting the request as it sees fit.

In Tauri, we have 2 Inter-Process Communication (IPC) Primitives, namely Events and Commands

So, let’s take a closer look at both of them.


Things I Don’t Understand About Filtering Malicious IPC Requests

I’m still a bit confused on where the malicious requests will be filtered

i.e. Whether it will be done in the Core Process or the Isolation Application or if it can be done from both.

Isolation Application will only be injected if we are using the Isolation Pattern in Tauri,

So, if it can only be done in the Isolation Application,

does it mean that we can’t filter malicious request when using the default Brownfield Pattern?

And isn’t the Isolation Application written in JavaScript and then injected in an sandboxed iframe at runtime?

So, what’s making it secure from the end user just changing the JavaScript Code and the HTML iframe sandbox attribute

once they have been injected at runtime?

Or is it that, because we will be disabling the development console in the final binary,

we take it as the end user won’t be able to do so?

of course with due care in Sanitizing Inputs, XSS and more.

So, for now, because i still don’t know the answers to these questions,

I’ll just take it as the Core Process is where we are filtering malicious requests.


What are Events in Tauri

Tauri Events System - Minimalist Text Editor in Rust Programming Language & Tauri - #5 Tauri Inter Process Communication - Events & Commands - Rust & Tauri Development Tutorial

Events can be used to communicate things from between processes

and are basically a One-Way Messages which you can send and then forget about.

Tauri’s Event System is a Multi-Producer, Multi Consumer communication Primitive

which means that, one Process can emit an Event to one or more than one Processes

and there can be one or more than one Consumers of the said emitted Event.

A Tauri application can emit and listen to Global and Window-Specific Events

where a Global Event will be emitted by a process and listened to by all the processes in the application,

while a Window-Specific Event will be emitted a process and listened to only by another specific process.


What are Commands in Tauri

Tauri Commands System - Minimalist Text Editor in Rust Programming Language & Tauri - #5 Tauri Inter Process Communication - Events & Commands - Rust & Tauri Development Tutorial

Commands are a foreign function interface which can be used to call functions and methods

that you have written in the Backend with Rust Programming Language and are running in the Tauri Core Process.

Commands allow you to

  • Invoke Rust functions and methods
  • Pass Arguments to these functions and methods
  • and Receive a Response from the called function or method

Under the hood, Commands use JSON-RPC like protocol to Serialize Requests and Responses

So, all the passed Arguments and Response Data must be serializable to JSON.

Commands can also return Errors if such a case happens

and can also be ran Asynchronously using the async keyword

which will then run the Command on a Separate Thread using async_runtime::spawn


This Article is part of Minimalist Text Editor Using Rust and Tauri Tutorial Series



Conclusion

Well Folks! That does it for this article.

I hope that you found this information on Tauri’s Inter-Process Communication, Events & Commands useful.

In the next article, we will delve more into understanding the Isolation Pattern in Tauri.

May you have success in your career whatever it may be.

See you again in the upcoming articles!

Share this post on Social Media platforms, if you think our content is great.

If you like the content and would like to follow us, we are present on the platforms below

Follow Us On Social Media

Goodbye For Now,
This is your host VP
Signing Off.