Commit 710e84b6 authored by Christopher Davis's avatar Christopher Davis

app: Re-arrange "open" signal handler into callback

Will make it easier to handle completion of registration.
parent c65ffa22
Pipeline #49290 passed with stage
in 8 minutes and 15 seconds
......@@ -56,8 +56,8 @@ pub enum Actions {
ShowRegisterPage,
}
#[allow(unused)]
pub struct App {
#[allow(dead_code)]
instance: gtk::Application,
window: gtk::ApplicationWindow,
main_stack: gtk::Stack,
......@@ -103,23 +103,6 @@ impl App {
});
});
let weak_stack = main_stack.downgrade();
application.connect_open(move |application, files, _| {
application.activate();
weak_stack.upgrade().map(|main_stack| {
if main_stack.get_visible_child_name().unwrap() == "register_page" && files[0].has_uri_scheme("oauth2redirect") {
if let Some(mut uri) = files[0].get_uri() {
uri = uri.trim_end_matches("&state=").to_string();
let _uri = uri.trim_start_matches(&format!("oauth2redirect://{}/",
globals::APP_ID))
.to_string();
// Find some way to get registration from register_page
}
}
});
});
let instance = application.clone();
let app = Self {
instance,
......@@ -133,11 +116,32 @@ impl App {
Rc::new(app)
}
#[allow(unused)]
pub fn action_open_callback(application: &gtk::Application,
files: &[gio::File],
weak_stack: &glib::WeakRef<gtk::Stack>,
registration: &Registered<HttpSender>) {
application.activate();
let main_stack = weak_stack.upgrade().unwrap();
if main_stack.get_visible_child_name().unwrap() == "register_page" && files[0].has_uri_scheme("oauth2redirect") {
if let Some(mut uri) = files[0].get_uri() {
uri = uri.trim_end_matches("&state=").to_string();
let _uri = uri.trim_start_matches(&format!("oauth2redirect://{}/?code=",
globals::APP_ID)).to_string();
// FIXME: use registration here to complete() uri
}
}
}
pub fn init(app: &Rc<Self>) {
gtk::timeout_add(25, clone!(app => move || app.setup_channel()));
}
pub fn setup_channel(&self) -> glib::Continue {
let weak_stack = self.main_stack.downgrade();
if let Ok(action) = self.receiver.try_recv() {
match action {
Actions::ShowError(s) => {
......@@ -147,6 +151,11 @@ impl App {
self.main_stack.set_visible_child_name("register_page");
self.header_stack.container.set_visible_child_name("register_header");
},
Actions::Registered(reg) => {
self.instance.connect_open(move |application, files, _|
App::action_open_callback(application, files, &weak_stack, &reg)
);
},
_ => ()
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment