added rustapp with dsrpc + api, updated frontend

This commit is contained in:
AmokDev 2025-03-18 14:23:43 +03:00
parent 91eb74a05c
commit 263c0bc065
11 changed files with 176 additions and 8 deletions

11
app/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "DiscordRPC-HDRezcord-APP"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-web = "4"
rust-discord-activity = { git = "https://github.com/AmokDev/rust-discord-activity", version = "0.3.1" }
serde = { version = "1.0", features = ["derive"] }
tokio = "1.44.1"

1
app/src/discord/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod rpc;

40
app/src/discord/rpc.rs Normal file
View file

@ -0,0 +1,40 @@
use rust_discord_activity::{
DiscordClient,
Asset,
Timestamp,
Activity,
ActivityType,
Payload,
EventName,
EventData,
};
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::time::Duration;
pub async fn start_presence() {
let mut client = DiscordClient::new("1351391108088987748");
let _ = client.connect();
let limg = Some(String::from("https://i.ibb.co/SDDCLdHN/discord-logo-discord-icon-transparent-free-png.png"));
let asset = Asset::new(limg.clone(), Some(String::from("#noWar")), limg, None);
let now_in_millis = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis();
let timestamps = Timestamp::new(Some(now_in_millis - 10000), Some(now_in_millis + 100000));
let mut activity = Activity::new();
activity
.set_state(Some("Сезон 1 Серия 5".into()))
.set_activity_type(Some(ActivityType::WATCHING))
.set_details(Some("Элементарно".parse().unwrap()))
.set_timestamps(Some(timestamps))
.set_assets(Some(asset))
.set_instance(Some(true));
let payload = Payload::new(EventName::Activity, EventData::Activity(activity));
let _ = client.send_payload(payload);
println!(":: Rich Presence started!");
loop {
tokio::time::sleep(Duration::from_secs(5)).await;
}
}

12
app/src/main.rs Normal file
View file

@ -0,0 +1,12 @@
mod network;
mod discord;
use network::api::start_api;
use discord::rpc::start_presence;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
tokio::spawn(start_presence());
start_api().await?;
Ok(())
}

23
app/src/network/api.rs Normal file
View file

@ -0,0 +1,23 @@
use actix_web::{get, App, HttpResponse, HttpServer, Responder};
use serde::Serialize;
#[derive(Serialize)]
struct MyResponse {
message: String,
}
#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().json(MyResponse { message: "Hello, world!".to_string() })
}
pub async fn start_api() -> std::io::Result<()> {
println!(":: API Started!");
HttpServer::new(|| {
App::new()
.service(hello)
})
.bind("127.0.0.1:2006")?
.run()
.await
}

1
app/src/network/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod api;

View file

@ -12,8 +12,16 @@
"action": { "action": {
"default_popup":"popup.html" "default_popup":"popup.html"
}, },
"permissions": [], "permissions": [
"storage"
],
"background": { "background": {
"service_worker": "service-worker.js" "service_worker": "service-worker.js"
} },
"web_accessible_resources": [
{
"resources": ["rpc.js"],
"matches": ["<all_urls>"]
}
]
} }

View file

@ -12,17 +12,16 @@
<h1 class="title has-text-centered"> <h1 class="title has-text-centered">
HDRezcord HDRezcord
</h1> </h1>
<div class="field"> <p id="status" class="subtitle has-text-centered"></p>
<div class="field has-addons is-flex is-justify-content-center">
<div class="control"> <div class="control">
<input class="input is-rounded has-text-centered" type="text" placeholder="Input rezka domen here" /> <button id="on" class="button is-link is-1 is-rounded">On</button>
</div> </div>
</div>
<div class="field is-grouped has-text-centered">
<div class="control"> <div class="control">
<button class="button is-link is-1 is-rounded">Save</button> <button id="off" class="button is-link is-1 is-rounded">Off</button>
</div> </div>
</div>
</div> </div>
</section> </section>
<script src="popup.js"></script>
</body> </body>
</html> </html>

52
popup.js Normal file
View file

@ -0,0 +1,52 @@
const on = document.getElementById("on");
const off = document.getElementById("off");
const plugin_status = document.getElementById("status");
function edit_status() {
chrome.storage.local.get(['pluginEnabled'], function(result) {
if (result.pluginEnabled === true) {
chrome.storage.local.set({ pluginEnabled: false });
plugin_status.innerHTML = "Plugin is disabled";
} else if (result.pluginEnabled === false) {
chrome.storage.local.set({ pluginEnabled: true });
plugin_status.innerHTML = "Plugin is enabled";
}
console.log(result.pluginEnabled);
});
}
function toggle_status() {
on.classList.toggle("is-outlined");
off.classList.toggle("is-outlined");
edit_status();
}
function get_status() {
chrome.storage.local.get(['pluginEnabled'], function(result) {
if (result.pluginEnabled === true) {
plugin_status.innerHTML = "Plugin is disabled";
} else if (result.pluginEnabled === false) {
plugin_status.innerHTML = "Plugin is enabled";
}
console.log(result.pluginEnabled);
});
}
document.addEventListener("DOMContentLoaded", function() {
chrome.storage.local.get(['pluginEnabled'], function(result) {
if (result.pluginEnabled === undefined) {
chrome.storage.local.set({ pluginEnabled: false });
} else if (result.pluginEnabled === true) {
on.classList.toggle("is-outlined");
} else if (result.pluginEnabled === false) {
off.classList.toggle("is-outlined");
}
});
on.addEventListener("click", function() {
toggle_status();
});
off.addEventListener("click", function() {
toggle_status();
});
get_status();
});

20
rpc.js Normal file
View file

@ -0,0 +1,20 @@
const rpc = require('discord-rpc');
const clientId = '1351391108088987748';
rpc.register(clientId);
const client = new rpc.Client({ transport: 'ipc' });
client.on('ready', () => {
console.log('RPC запущен!');
client.setActivity({
details: 'Играю в вашу игру',
state: 'Нахожусь на уровне 1',
startTimestamp: new Date(),
// largeImageKey: 'image_key', // замените на ключ изображения
// largeImageText: 'Дополнительный текст',
instance: false,
});
});
client.login({ clientId }).catch(console.error);

View file

@ -0,0 +1 @@
importScripts("rpc.js")