{"id":24698489,"url":"https://github.com/smokingplaya/tauri-plugin-drpc","last_synced_at":"2025-03-22T03:41:52.849Z","repository":{"id":274330409,"uuid":"922588148","full_name":"smokingplaya/tauri-plugin-drpc","owner":"smokingplaya","description":"A plugin for Tauri that allows you to control Discord Rich Presence.","archived":false,"fork":false,"pushed_at":"2025-02-19T17:11:36.000Z","size":28,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-09T12:47:42.511Z","etag":null,"topics":["discord","ipc","rpc","rust","tauri","typescript"],"latest_commit_sha":null,"homepage":"https://smokingplaya.ru/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smokingplaya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-01-26T16:02:28.000Z","updated_at":"2025-02-19T17:11:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"8141f115-9e35-4940-9776-2f22e2cf445f","html_url":"https://github.com/smokingplaya/tauri-plugin-drpc","commit_stats":null,"previous_names":["smokingplaya/tauri-plugin-drpc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smokingplaya%2Ftauri-plugin-drpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smokingplaya%2Ftauri-plugin-drpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smokingplaya%2Ftauri-plugin-drpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smokingplaya%2Ftauri-plugin-drpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smokingplaya","download_url":"https://codeload.github.com/smokingplaya/tauri-plugin-drpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244902931,"owners_count":20529114,"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":["discord","ipc","rpc","rust","tauri","typescript"],"created_at":"2025-01-27T04:29:05.662Z","updated_at":"2025-03-22T03:41:52.843Z","avatar_url":"https://github.com/smokingplaya.png","language":"TypeScript","funding_links":[],"categories":["Development"],"sub_categories":["Plugins"],"readme":"# Tauri Plugin DRPC\n\nA plugin for [Tauri](https://tauri.app/) that allows you to control Discord Rich Presence.\n\n\u003e [!NOTE]\n\u003e This plugin is designed to be used on Desktop only.\n\n# Table of contents\n* [Concept (how it works)](#concept)\n* [Installation](#installation)\n* [Usage](#usage)\n  * [Thread managment](#thread-managment)\n  * [Activity managment](#activity-managment)\n  * [Activity components](#activity-components)\n    * [Assets](#assets)\n    * [Buttons](#buttons)\n    * [Party](#party)\n    * [Timestamps](#timestamps)\n\n# Concept\nThe plugin implements an interface *([as a JavaScript plugin](./guest-js/README.md))* between JavaScript and crate for Rust [discord-rich-presence](https://github.com/vionya/discord-rich-presence) (we have our own fork of it - [rpcdiscord](https://github.com/smokingplaya/rpcdiscord)).\n\nRight now the plugin works as follows:\nA 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](#usage)\n\n\u003e [!NOTE]\n\u003e We are now looking at an option without using the creation of separate threads, since Tauri allows you to do asynchronous commands.\n\n# Installation\n[![version](https://img.shields.io/crates/v/tauri-plugin-drpc)](https://crates.io/crates/tauri-plugin-drpc)\n\nOpen a terminal, and in the root folder of your project, type these commands:\n```bash\ncd src-tauri\ncargo add tauri-plugin-drpc\n```\nor just type this line into ``src-tauri/Cargo.toml``.\n```toml\ntauri-plugin-drpc = \"*\"\n```\n\nThen install the package for JavaScript (in root folder of your project):\n```bash\nnpm i tauri-plugin-drpc\n```\n\n# Usage\n## Thread managment\nAs I said earlier [(here)](#concepts), to use Discord Rich Presence you need to spawn a thread, which is what will run Rich Presence.\n\nThis can be done through the ``start`` function:\n```js\nimport { start } from \"tauri-plugin-drpc\";\n\n// start(APPLICATION_ID)\nawait start(\"700000000000000000\");\n```\n\nThe ``start`` function checks that the drpc thread is not running, if it is running it stops it and then starts a new one.\n\nThis means that the ``start`` function cannot throw an error, and it is safe to use.\n\nIf you need to start a thread without checks, you can use the ``spawn`` function.\n\n```js\nimport { spawn } from \"tauri-plugin-drpc\";\n\ntry {\n  // spawn(APPLICATION_ID)\n  await spawn(\"700000000000000000\");\n} catch (err) {\n  console.error(err);\n}\n```\n\nIf you need to, you can stop the thread yourself via the ``stop`` function.\n\nThe ``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.\n\n```js\nimport { stop } from \"tauri-plugin-drpc\";\n\nawait stop();\n```\n\nAnd there is a function ``destroy`` which stops the thread without checks and may throw an error, so it should be wrapped in ``try {} catch (...)``.\n\n```js\nimport { destroy } from \"tauri-plugin-drpc\";\n\ntry {\n  await destroy();\n} catch (err) {\n  console.error(err);\n}\n```\n\n# Activity managment\n\u003e [!NOTE]\n\u003e You can get the Application ID in the [settings of your Discord application](https://discord.com/developers/applications), in the `General Information` tab.\n\nYou 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](#activity-managment).\n\nYou can also clear the activity via ``clearActivity``.\n\nExample:\n```js\nimport { setActivity, clearActivity, destroy } from \"tauri-plugin-drpc\";\nimport { Activity } from \"tauri-plugin-drpc\";\n\nconst activity = new Activity()\n  .setState(\"example string\")\n  .setState(\"hello\")\n  .setTimestamps(new Timestamps(Date.now())\n\nawait setActivity(activity);\n\nsetTimeout(async () =\u003e {\n  console.log(\"Clearing activity\");\n\n  // clear drpc's activity\n  await clearActivity();\n  // destroy drpc's thread\n  await destroy();\n}, 3000)\n```\n\n# Activity components\n## Assets\nAssets is responsible for the large and small icons on the left side of the activity.\n\n```js\nimport { Assets, Activity } from \"tauri-plugin-drpc/activity\";\n\nconst assets = new Assets()\n  .setLargeImage(\"IMAGE_ID\")\n  .setLargeText(\"Large image hovered!\")\n  .setSmallImage(\"IMAGE_ID\")\n  .setSmallText(\"Small image hovered!\")\n\nconst activity = new Activity()\n  .setAssets(assets);\n```\n\n## Buttons\n``Button`` add buttons to your activity, when clicked, the user will have the link given to each button open in the browser.\n\n```js\nimport { Button } from \"tauri-plugin-drpc/activity\";\n\nconst activity = new Activity()\n  .setButtons([\n    new Button(\"Button text #1\", \"https://example.com\"),\n    new Button(\"Button text #2\", \"https://example.com\"),\n  ]);\n```\n\n## Party\nThere is no documentation for the ``Party`` component, so you, dear friend, will have to check the [discord-rich-presence crate documentation](https://docs.rs/discord-rich-presence/) to understand how this component works.\n\n## Timestamps\n```js\nimport { Timestamps, Activity } from \"tauri-plugin-drpc/activity\";\n\nconst timestamp = new Timestamps(Date.now() - 1000000); // 1000 seconds ago\n\nconst activity = new Activity()\n  .setTimestamps(timestamp);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmokingplaya%2Ftauri-plugin-drpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmokingplaya%2Ftauri-plugin-drpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmokingplaya%2Ftauri-plugin-drpc/lists"}