diff --git a/data/com.github.bleakgrey.tootle.gschema.xml b/data/com.github.bleakgrey.tootle.gschema.xml index 140e5f6..f7f08c4 100644 --- a/data/com.github.bleakgrey.tootle.gschema.xml +++ b/data/com.github.bleakgrey.tootle.gschema.xml @@ -10,8 +10,8 @@ - - 0 + + '' false diff --git a/src/Services/Accounts/AccountStore.vala b/src/Services/Accounts/AccountStore.vala index f1b4759..1004761 100644 --- a/src/Services/Accounts/AccountStore.vala +++ b/src/Services/Accounts/AccountStore.vala @@ -8,19 +8,16 @@ public abstract class Tootle.AccountStore : GLib.Object { // TODO: Make settings.current_account a string public bool ensure_active_account () { var has_active = false; + var account = find_by_handle (settings.active_account); - if (!saved.is_empty) { - if (settings.current_account > saved.size || settings.current_account <= 0) - settings.current_account = 0; - - var last_account = saved[settings.current_account]; - if (active != last_account) { - activate (last_account); - has_active = true; - } + if (account == null && !saved.is_empty) { + account = saved[0]; } - if (!has_active) + has_active = account != null; + if (has_active) + activate (account); + else app.present_window (); return has_active; @@ -59,21 +56,21 @@ public abstract class Tootle.AccountStore : GLib.Object { saved.remove (account); saved.notify_property ("size"); save (); - - var id = settings.current_account - 1; - if (saved.size < 1) - active = null; - else { - if (id > saved.size - 1) - id = saved.size - 1; - else if (id < saved.size - 1) - id = 0; - } - settings.current_account = id; - ensure_active_account (); } + public InstanceAccount? find_by_handle (string handle) { + var iter = saved.filter (acc => { + return acc.handle == handle; + }); + iter.next (); + + if (!iter.valid) + return null; + else + return iter.@get (); + } + public void activate (InstanceAccount account) { message (@"Activating $(account.handle)..."); account.verify_credentials.begin ((obj, res) => { @@ -89,7 +86,7 @@ public abstract class Tootle.AccountStore : GLib.Object { }); accounts.active = account; - settings.current_account = accounts.saved.index_of (account); + settings.active_account = account.handle; } [Signal (detailed = true)] diff --git a/src/Services/Settings.vala b/src/Services/Settings.vala index 63b6238..8f507af 100644 --- a/src/Services/Settings.vala +++ b/src/Services/Settings.vala @@ -2,7 +2,7 @@ using GLib; public class Tootle.Settings : GLib.Settings { - public int current_account { get; set; } + public string active_account { get; set; } public bool dark_theme { get; set; } public bool autostart { get; set; } public bool work_in_background { get; set; } @@ -20,7 +20,7 @@ public class Tootle.Settings : GLib.Settings { public Settings () { Object (schema_id: Build.DOMAIN); - init ("current-account"); + init ("active-account"); init ("dark-theme"); init ("autostart"); init ("work-in-background");