Deprecate settings.current_account property
This commit is contained in:
parent
1b08b37b9f
commit
7454ece650
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
<schema path="/com/github/bleakgrey/tootle/" id="com.github.bleakgrey.tootle" gettext-domain="com.github.bleakgrey.tootle">
|
<schema path="/com/github/bleakgrey/tootle/" id="com.github.bleakgrey.tootle" gettext-domain="com.github.bleakgrey.tootle">
|
||||||
|
|
||||||
<key name="current-account" type="i">
|
<key name="active-account" type="s">
|
||||||
<default>0</default>
|
<default>''</default>
|
||||||
</key>
|
</key>
|
||||||
<key name="dark-theme" type="b">
|
<key name="dark-theme" type="b">
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
|
|
|
@ -8,19 +8,16 @@ public abstract class Tootle.AccountStore : GLib.Object {
|
||||||
// TODO: Make settings.current_account a string
|
// TODO: Make settings.current_account a string
|
||||||
public bool ensure_active_account () {
|
public bool ensure_active_account () {
|
||||||
var has_active = false;
|
var has_active = false;
|
||||||
|
var account = find_by_handle (settings.active_account);
|
||||||
|
|
||||||
if (!saved.is_empty) {
|
if (account == null && !saved.is_empty) {
|
||||||
if (settings.current_account > saved.size || settings.current_account <= 0)
|
account = saved[0];
|
||||||
settings.current_account = 0;
|
|
||||||
|
|
||||||
var last_account = saved[settings.current_account];
|
|
||||||
if (active != last_account) {
|
|
||||||
activate (last_account);
|
|
||||||
has_active = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!has_active)
|
has_active = account != null;
|
||||||
|
if (has_active)
|
||||||
|
activate (account);
|
||||||
|
else
|
||||||
app.present_window ();
|
app.present_window ();
|
||||||
|
|
||||||
return has_active;
|
return has_active;
|
||||||
|
@ -59,21 +56,21 @@ public abstract class Tootle.AccountStore : GLib.Object {
|
||||||
saved.remove (account);
|
saved.remove (account);
|
||||||
saved.notify_property ("size");
|
saved.notify_property ("size");
|
||||||
save ();
|
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 ();
|
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) {
|
public void activate (InstanceAccount account) {
|
||||||
message (@"Activating $(account.handle)...");
|
message (@"Activating $(account.handle)...");
|
||||||
account.verify_credentials.begin ((obj, res) => {
|
account.verify_credentials.begin ((obj, res) => {
|
||||||
|
@ -89,7 +86,7 @@ public abstract class Tootle.AccountStore : GLib.Object {
|
||||||
});
|
});
|
||||||
|
|
||||||
accounts.active = account;
|
accounts.active = account;
|
||||||
settings.current_account = accounts.saved.index_of (account);
|
settings.active_account = account.handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Signal (detailed = true)]
|
[Signal (detailed = true)]
|
||||||
|
|
|
@ -2,7 +2,7 @@ using GLib;
|
||||||
|
|
||||||
public class Tootle.Settings : GLib.Settings {
|
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 dark_theme { get; set; }
|
||||||
public bool autostart { get; set; }
|
public bool autostart { get; set; }
|
||||||
public bool work_in_background { get; set; }
|
public bool work_in_background { get; set; }
|
||||||
|
@ -20,7 +20,7 @@ public class Tootle.Settings : GLib.Settings {
|
||||||
|
|
||||||
public Settings () {
|
public Settings () {
|
||||||
Object (schema_id: Build.DOMAIN);
|
Object (schema_id: Build.DOMAIN);
|
||||||
init ("current-account");
|
init ("active-account");
|
||||||
init ("dark-theme");
|
init ("dark-theme");
|
||||||
init ("autostart");
|
init ("autostart");
|
||||||
init ("work-in-background");
|
init ("work-in-background");
|
||||||
|
|
Loading…
Reference in New Issue