Use default SocketConnection for current platform
This commit is contained in:
parent
b89fddcac4
commit
60c7f4762f
|
@ -4,16 +4,12 @@ extern crate discord_rpc_client;
|
|||
use simplelog::*;
|
||||
use std::{thread, time};
|
||||
use discord_rpc_client::Client as DiscordRPC;
|
||||
#[cfg(unix)]
|
||||
use discord_rpc_client::UnixConnection as Connection;
|
||||
#[cfg(windows)]
|
||||
use discord_rpc_client::WindowsConnection as Connection;
|
||||
|
||||
fn main() {
|
||||
TermLogger::init(LevelFilter::Debug, Config::default()).unwrap();
|
||||
|
||||
let mut drpc =
|
||||
DiscordRPC::<Connection>::new(425407036495495169)
|
||||
DiscordRPC::new(425407036495495169)
|
||||
.and_then(|rpc| rpc.start())
|
||||
.expect("Failed to start client");
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
use connection::Connection;
|
||||
use connection::{Connection, SocketConnection};
|
||||
use models::{Handshake, OpCode};
|
||||
#[cfg(feature = "rich_presence")]
|
||||
use rich_presence::{SetActivityArgs, SetActivity};
|
||||
use error::Result;
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Client<T>
|
||||
where T: Connection
|
||||
{
|
||||
|
@ -17,9 +16,8 @@ pub struct Client<T>
|
|||
impl<T> Client<T>
|
||||
where T: Connection
|
||||
{
|
||||
pub fn new(client_id: u64) -> Result<Self> {
|
||||
let socket = T::connect()?;
|
||||
Ok(Self { version: 1, client_id, socket})
|
||||
pub fn with_connection(client_id: u64, socket: T) -> Result<Self> {
|
||||
Ok(Self { version: 1, client_id, socket })
|
||||
}
|
||||
|
||||
pub fn start(mut self) -> Result<Self> {
|
||||
|
@ -45,3 +43,10 @@ impl<T> Client<T>
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Client<SocketConnection> {
|
||||
pub fn new(client_id: u64) -> Result<Self> {
|
||||
let socket = Connection::connect()?;
|
||||
Self::with_connection(client_id, socket)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ mod unix;
|
|||
#[cfg(windows)]
|
||||
mod windows;
|
||||
|
||||
pub use self::base::Connection;
|
||||
pub use self::base::Connection as Connection;
|
||||
#[cfg(unix)]
|
||||
pub use self::unix::UnixConnection;
|
||||
pub use self::unix::UnixConnection as SocketConnection;
|
||||
#[cfg(windows)]
|
||||
pub use self::windows::WindowsConnection;
|
||||
pub use self::windows::WindowsConnection as SocketConnection;
|
||||
|
|
|
@ -23,7 +23,4 @@ pub mod client;
|
|||
pub use client::Client;
|
||||
#[cfg(feature = "rich_presence")]
|
||||
pub use rich_presence::*;
|
||||
#[cfg(unix)]
|
||||
pub use connection::UnixConnection;
|
||||
#[cfg(windows)]
|
||||
pub use connection::WindowsConnection;
|
||||
pub use connection::{Connection, SocketConnection};
|
||||
|
|
Loading…
Reference in New Issue