diff --git a/src/Accounts.vala b/src/Accounts.vala index 8a940fb9..8e68f2ca 100644 --- a/src/Accounts.vala +++ b/src/Accounts.vala @@ -52,8 +52,12 @@ public class Olifant.Accounts : Object { account.close_notificator (); saved_accounts.remove_index (i); - if (saved_accounts.length < 1) + if (saved_accounts.length < 1){ + formal=null; + current=null; + //currentInstance=null; switched (null); + } else { var id = settings.current_account - 1; if (id > saved_accounts.length - 1) @@ -67,7 +71,8 @@ public class Olifant.Accounts : Object { updated (saved_accounts); if (is_empty ()) { - window.destroy (); + window.destroy (); + window=null; Dialogs.NewAccount.open (); } } diff --git a/src/Dialogs/NewAccount.vala b/src/Dialogs/NewAccount.vala index 25308ef3..a94e5724 100644 --- a/src/Dialogs/NewAccount.vala +++ b/src/Dialogs/NewAccount.vala @@ -20,6 +20,7 @@ public class Olifant.Dialogs.NewAccount : Dialog { private string? token; private string? username; private int64? instance_status_char_limit; + private bool second_click; private const int64 DEFAULT_INSTANCE_STATUS_CHAR_LIMIT = 500; @@ -27,6 +28,7 @@ public class Olifant.Dialogs.NewAccount : Dialog { border_width = 6; deletable = true; resizable = false; + second_click=false; title = _("New Account"); transient_for = window; @@ -104,15 +106,15 @@ public class Olifant.Dialogs.NewAccount : Dialog { request_instance_status_charlimit(); - if (client_id == null || client_secret == null) { + if (!second_click){ request_client_tokens (); - return; } - - if (code == "") - app.error (_("Error"), _("Please paste valid instance authorization code")); - else - try_auth (code); + else{ + if (code == "") + app.error (_("Error"), _("Please paste valid instance authorization code")); + else + try_auth (code); + } } private void request_instance_status_charlimit () { @@ -155,6 +157,7 @@ public class Olifant.Dialogs.NewAccount : Dialog { code_entry.show (); url_hint.show (); url_hint.set_markup ("Browser did not open? Try link".printf (GLib.Markup.escape_text (generate_auth_url ()))); + second_click=true; }, (status, reason) => { network.on_show_error (status, reason); }); @@ -187,8 +190,10 @@ public class Olifant.Dialogs.NewAccount : Dialog { var root = network.parse (msg); token = root.get_string_member ("access_token"); + info ("Got access token for %s".printf (instance)); get_username (); + second_click=false; }, (status, reason) => { network.on_show_error (status, reason); }); diff --git a/src/Network.vala b/src/Network.vala index 7e747105..0f59ea79 100644 --- a/src/Network.vala +++ b/src/Network.vala @@ -61,7 +61,8 @@ public class Olifant.Network : GLib.Object { if (headers.get_one (INJECT_TOKEN) != null) { headers.remove (INJECT_TOKEN); } - if (formal != null) { + if (formal != null && headers.get_one("Authorization")==null) { + info ("Got access token "+formal.token); headers.append ("Authorization", "Bearer " + formal.token); } }