Tauri Plugin DRPC
A plugin for Tauri that allows you to control Discord Rich Presence.
[!NOTE] This plugin is designed to be used on Desktop only.
Table of contents
Concept
The plugin implements an interface (as a JavaScript plugin) between JavaScript and crate for Rust discord-rich-presence (we have our own fork of it - rpcdiscord).
Right now the plugin works as follows:
A developer has to call a function (spawn) in the code that sparks a thread, and that thread keeps Discord Rich Presence running, constantly updating the activity in it. See Usage
[!NOTE] We are now looking at an option without using the creation of separate threads, since Tauri allows you to do asynchronous commands.
Installation
Open a terminal, and in the root folder of your project, type these commands:
or just type this line into src-tauri/Cargo.toml.
= "*"
Then install the package for JavaScript (in root folder of your project):
Usage
Thread managment
As I said earlier (here), to use Discord Rich Presence you need to spawn a thread, which is what will run Rich Presence.
This can be done through the start function:
import from "tauri-plugin-drpc";
// start(APPLICATION_ID)
await ;
The start function checks that the drpc thread is not running, if it is running it stops it and then starts a new one.
This means that the start function cannot throw an error, and it is safe to use.
If you need to start a thread without checks, you can use the spawn function.
import from "tauri-plugin-drpc";
try catch
If you need to, you can stop the thread yourself via the stop function.
The stop function is as safe as the spawn function, it stops the thread only if it is running, so it does not throw an error.
import from "tauri-plugin-drpc";
await ;
And there is a function destroy which stops the thread without checks and may throw an error, so it should be wrapped in try {} catch (...).
import from "tauri-plugin-drpc";
try catch
Activity managment
[!NOTE] You can get the Application ID in the settings of your Discord application, in the
General Informationtab.
You can now customize your Discord Rich Presence activity. This can be done through the setActivity function. But before that, you need to create an activity object. I have written about this below.
You can also clear the activity via clearActivity.
Example:
import from "tauri-plugin-drpc";
import from "tauri-plugin-drpc";
const activity =
.
.
.
Activity components
Assets
Assets is responsible for the large and small icons on the left side of the activity.
import from "tauri-plugin-drpc/activity";
const assets =
.
.
.
.
const activity =
.;
Buttons
Button add buttons to your activity, when clicked, the user will have the link given to each button open in the browser.
import from "tauri-plugin-drpc/activity";
const activity =
.;
Party
There is no documentation for the Party component, so you, dear friend, will have to check the discord-rich-presence crate documentation to understand how this component works.
Timestamps
import from "tauri-plugin-drpc/activity";
const timestamp = ; // 1000 seconds ago
const activity =
.;