我正在开发 Tauri 应用程序,遇到以下问题:我需要通过 Discord RPC 显示应用程序中的当前状态,我决定使用 Discord_rich_presence 库
use discord_rich_presence::{activity, DiscordIpc, DiscordIpcClient};
fn main() {
let mut client = DiscordIpcClient::new("1222240908393844876").unwrap();
match client.connect() {
Ok(t) => t,
Err(err) => return ()
}
client.set_activity(activity::Activity::new()
.details("Находится в лаунчере")
.assets(discord_rich_presence::activity::Assets::new()
.large_image("logo")
)
).expect("Cannot set activity message!");
std::thread::park();
}
货物.toml:
[package]
name = "rust_learn"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
discord-rich-presence = "0.2.3"
该代码可以工作,但是当嵌入到 tauri 代码中时,该行std::thread::park()
会阻止应用程序本身启动:
fn main() {
let mut client = DiscordIpcClient::new("1222240908393844876").unwrap();
match client.connect() {
Ok(t) => t,
Err(err) => return ()
}
client.set_activity(activity::Activity::new()
.details("Находится в лаунчере")
.assets(discord_rich_presence::activity::Assets::new()
.large_image("logo")
)
).expect("Cannot set activity message!");
std::thread::park();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![check_version, download_version])
.run(tauri::generate_context!())
.expect("failed to run app");
}
如何运行 Discord RPC 作为后台应用程序,或以其他方式运行 Tauri 应用程序?
添加:我尝试添加它
client.close()
而不是停车 - 15 秒后活动消失。