vionya / discord-rich-presence

A cross-platform Discord Rich Presence library written in Rust
MIT License
94 stars 20 forks source link

Don't panic if Discord is not running #34

Closed d4rckh closed 2 months ago

d4rckh commented 3 months ago

When Discord is not running the crate panics:

thread 'main' panicked at C:\Users\andrei\.cargo\registry\src\index.crates.io-6f17d22bba15001f\discord-rich-presence-0.2.4\src\ipc_windows.rs:60:43:  
Client not connected

my code is just this:

    let mut client = DiscordIpcClient::new("1258151270234198096").unwrap();

    let _ = client.connect();

    let _ = client.set_activity(activity::Activity::new()
        .state("with the money machine")
        .details("Making money")
    );     

Allow us to completly ignore the fact that discord is not running and handle the error by us.

Bowarc commented 3 months ago

The panic is due to a call of self.send_handshake()?; which calls self.send which calls self.write In that write method, on windows and unix, the 'socket' is .expected.

There is error handling, just missing that case :p

I'll see if i can push a quick patch