6 changed files with 669 additions and 522 deletions
@ -1,18 +1,57 @@
|
||||
use std; |
||||
use std::error::Error; |
||||
|
||||
use futures::{self, Future, Stream}; |
||||
use gtk; |
||||
use ruma_client::Client as RumaClient; |
||||
use std::sync::mpsc::Sender; |
||||
use tokio_core::reactor::{Core, Handle}; |
||||
use url::Url; |
||||
|
||||
fn bg_main( |
||||
homeserver: Url, |
||||
core_handle: Handle, |
||||
homeserver_chan_rx: futures::sync::mpsc::Receiver<Url>, |
||||
dispatch_chan_tx: std::sync::mpsc::Sender<Box<Fn(>k::Builder) + Send>>, |
||||
) -> impl Future<Item = (), Error = Box<Error>> { |
||||
let client = RumaClient::https(&core_handle, homeserver, None).unwrap(); |
||||
|
||||
futures::future::ok(()) |
||||
|
||||
pub fn run(dispatch_tx: Sender<Box<Fn(>k::Builder) + Send>>) { |
||||
let client = RumaClient::new().unwrap(); |
||||
// TODO: background main loop
|
||||
// TODO: use loop_fn instead of manually recursing?
|
||||
|
||||
// TODO: Register as guest, only when successful do this stuff
|
||||
dispatch_tx.send(box move |builder| { |
||||
builder.get_object::<gtk::Stack>("user_button_stack") |
||||
/*dispatch_chan_tx.send(box move |builder| {
|
||||
builder |
||||
.get_object::<gtk::Stack>("user_button_stack") |
||||
.expect("Can't find user_button_stack in ui file.") |
||||
.set_visible_child_name("user_connected_page"); |
||||
|
||||
builder.get_object::<gtk::Label>("display_name_label") |
||||
builder |
||||
.get_object::<gtk::Label>("display_name_label") |
||||
.expect("Can't find display_name_label in ui file.") |
||||
.set_text("Guest"); |
||||
}); |
||||
});*/ |
||||
} |
||||
|
||||
pub fn run( |
||||
homeserver_chan_rx: futures::sync::mpsc::Receiver<Url>, |
||||
dispatch_chan_tx: std::sync::mpsc::Sender<Box<Fn(>k::Builder) + Send>>, |
||||
) { |
||||
let mut core = Core::new().unwrap(); |
||||
let handle = core.handle(); |
||||
|
||||
core.run( |
||||
homeserver_chan_rx |
||||
.into_future() |
||||
.map_err(|_| std::sync::mpsc::RecvError.into()) |
||||
.and_then( |
||||
move |(opt_url, homeserver_chan_rx)| -> Box<Future<Item = (), Error = Box<Error>>> { |
||||
if let Some(url) = opt_url { |
||||
box bg_main(url, handle, homeserver_chan_rx, dispatch_chan_tx) |
||||
} else { |
||||
box futures::future::ok(()) |
||||
} |
||||
}, |
||||
), |
||||
).unwrap(); |
||||
} |
||||
|
||||
@ -0,0 +1,18 @@
|
||||
// from https://stackoverflow.com/a/43992218/1592377
|
||||
#[macro_export] |
||||
macro_rules! clone { |
||||
(@param _) => ( _ ); |
||||
(@param $x:ident) => ( $x ); |
||||
($($n:ident),+ => move || $body:expr) => ( |
||||
{ |
||||
$( let $n = $n.clone(); )+ |
||||
move || $body |
||||
} |
||||
); |
||||
($($n:ident),+ => move |$($p:tt),+| $body:expr) => ( |
||||
{ |
||||
$( let $n = $n.clone(); )+ |
||||
move |$(clone!(@param $p),)+| $body |
||||
} |
||||
); |
||||
} |
||||
Loading…
Reference in new issue