Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ surge-ping = "0.8.4"
toml = "1.1.2"
duct = "1.1.1"
sysinfo = "0.38.4"
discord-rich-presence = "1.1.0"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify discord-rich-presence is available on crates.io
curl -s "https://crates.io/api/v1/crates/discord-rich-presence" | jq -r '.crate.max_version'

Repository: Noktomezo/ZapretInteractive

Length of output: 76


Use cargo add discord-rich-presence instead of manually editing Cargo.toml.

Dependencies should be added using the cargo add command rather than manual editing. Add the dependency via cargo add discord-rich-presence and then run cargo check to verify.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src-tauri/Cargo.toml` at line 52, The dependency line "discord-rich-presence
= \"1.1.0\"" was added manually to Cargo.toml; instead remove that manual edit
and add the crate using the Cargo tooling by running `cargo add
discord-rich-presence` in the project root (this will update Cargo.toml and
Cargo.lock correctly), then run `cargo check` to verify the workspace builds and
dependency resolution; confirm the manual line referencing discord-rich-presence
in Cargo.toml is gone or matches the cargo-added entry.


[target.'cfg(windows)'.dependencies]
windows = { version = "0.62.2", features = ["Win32_Foundation", "Win32_Security", "Win32_Security_Authentication_Identity", "Win32_System_Threading", "Win32_System_Services", "Win32_System_Registry", "Win32_System_Diagnostics_ToolHelp", "Win32_NetworkManagement_IpHelper", "Win32_NetworkManagement_Ndis", "Win32_Networking_WinSock"] }
Expand Down
1 change: 1 addition & 0 deletions src-tauri/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"tgWsProxyPort": 1443,
"tgWsProxySecret": "",
"tgWsProxyModuleEnabled": false,
"discordPresenceEnabled": true,
"categories": [
{
"id": "preset-http",
Expand Down
9 changes: 9 additions & 0 deletions src-tauri/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ pub struct AppConfig {
rename = "tgWsProxyModuleEnabled"
)]
pub tg_ws_proxy_module_enabled: bool,
#[serde(
default = "default_discord_presence_enabled",
rename = "discordPresenceEnabled"
)]
pub discord_presence_enabled: bool,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
#[serde(default = "default_minimize_to_tray", rename = "minimizeToTray")]
pub minimize_to_tray: bool,
#[serde(default = "default_launch_to_tray", rename = "launchToTray")]
Expand Down Expand Up @@ -367,6 +372,10 @@ fn default_tg_ws_proxy_module_enabled() -> bool {
false
}

fn default_discord_presence_enabled() -> bool {
true
}

fn is_valid_tg_ws_proxy_secret(secret: &str) -> bool {
secret.len() == 32 && secret.chars().all(|char| char.is_ascii_hexdigit())
}
Expand Down
87 changes: 87 additions & 0 deletions src-tauri/src/commands/discord_presence.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use discord_rich_presence::{DiscordIpc, DiscordIpcClient, activity};
use std::sync::{LazyLock, Mutex};

const DISCORD_CLIENT_ID: &str = "1495773045904769255";

#[derive(Default)]
struct DiscordPresenceState {
client: Option<DiscordIpcClient>,
last_key: Option<String>,
}

static DISCORD_PRESENCE_STATE: LazyLock<Mutex<DiscordPresenceState>> =
LazyLock::new(|| Mutex::new(DiscordPresenceState::default()));

fn discord_error_to_string<E: std::fmt::Display>(error: E) -> String {
error.to_string()
}

fn reconnect_client(state: &mut DiscordPresenceState) -> Result<(), String> {
let mut client = DiscordIpcClient::new(DISCORD_CLIENT_ID);
client.connect().map_err(discord_error_to_string)?;
state.client = Some(client);
Ok(())
}

fn clear_presence(state: &mut DiscordPresenceState) {
state.last_key = None;
if let Some(mut client) = state.client.take() {
let _ = client.clear_activity();
let _ = client.close();
}
}

#[tauri::command]
pub fn sync_discord_presence(enabled: bool, details: String, state: String) -> Result<(), String> {
let mut presence_state = DISCORD_PRESENCE_STATE.lock().map_err(|e| e.to_string())?;

if !enabled {
clear_presence(&mut presence_state);
return Ok(());
}

let next_key = format!("{details}\u{0}{state}");
if presence_state.last_key.as_deref() == Some(next_key.as_str()) {
return Ok(());
}

if presence_state.client.is_none() && reconnect_client(&mut presence_state).is_err() {
return Ok(());
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

let activity = activity::Activity::new()
.details(details.clone())
.state(state.clone());

let update_result = presence_state
.client
.as_mut()
.ok_or_else(|| "Discord client was not initialized".to_string())
.and_then(|client| {
client
.set_activity(activity)
.map_err(discord_error_to_string)
});

match update_result {
Ok(()) => {
presence_state.last_key = Some(next_key);
Ok(())
}
Err(_) => {
clear_presence(&mut presence_state);
if reconnect_client(&mut presence_state).is_err() {
return Ok(());
}

let retry_activity = activity::Activity::new().details(details).state(state);
if let Some(client) = presence_state.client.as_mut()
&& client.set_activity(retry_activity).is_ok()
{
presence_state.last_key = Some(next_key);
}

Ok(())
}
}
}
1 change: 1 addition & 0 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod admin;
pub mod binaries;
pub mod config;
pub mod discord_presence;
pub mod dns;
pub mod process;
pub mod tg_proxy;
3 changes: 2 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod commands;

use commands::{admin, binaries, config, dns, process, tg_proxy};
use commands::{admin, binaries, config, discord_presence, dns, process, tg_proxy};
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{
Emitter, Manager,
Expand Down Expand Up @@ -393,6 +393,7 @@ pub fn run() {
binaries::delete_filter_file,
binaries::open_app_directory,
binaries::open_filters_directory,
discord_presence::sync_discord_presence,
dns::get_dns_proxy_status,
dns::start_dns_proxy,
dns::stop_dns_proxy,
Expand Down
Loading