Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Issue 28 #37

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Accounts.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -67,7 +71,8 @@ public class Olifant.Accounts : Object {
updated (saved_accounts);

if (is_empty ()) {
window.destroy ();
window.destroy ();
window=null;
Dialogs.NewAccount.open ();
}
}
Expand Down
19 changes: 12 additions & 7 deletions src/Dialogs/NewAccount.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ 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;

public NewAccount () {
border_width = 6;
deletable = true;
resizable = false;
second_click=false;
title = _("New Account");
transient_for = window;

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 <a href=\"%s\">link</a>".printf (GLib.Markup.escape_text (generate_auth_url ())));
second_click=true;
}, (status, reason) => {
network.on_show_error (status, reason);
});
Expand Down Expand Up @@ -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);
});
Expand Down
3 changes: 2 additions & 1 deletion src/Network.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down