Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Settings): per account #680

Merged
merged 4 commits into from
Dec 12, 2023
Merged
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
29 changes: 12 additions & 17 deletions data/dev.geopjr.Tuba.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>

<enum id="dev.geopjr.Tuba.ColorScheme">
<value value="0" nick="system"/>
<value value="1" nick="light"/>
<value value="2" nick="dark"/>
</enum>

<schema id="dev.geopjr.Tuba.Account">
<key name="default-post-visibility" type="s">
<default>'public'</default>
</key>
<key name="default-content-type" type="s">
<default>'text/plain'</default>
</key>
<key name="muted-notification-types" type="as">
<default>[]</default>
</key>
</schema>

<schema path="/dev/geopjr/Tuba/" id="dev.geopjr.Tuba" gettext-domain="dev.geopjr.Tuba">

<key name="active-account" type="s">
<default>''</default>
</key>
<key name="color-scheme" enum="dev.geopjr.Tuba.ColorScheme">
<default>'system'</default>
</key>
<key name="default-post-visibility" type="s">
<default>'public'</default>
</key>
<key name="work-in-background" type="b">
<default>false</default>
</key>
Expand Down Expand Up @@ -60,9 +67,6 @@
<key name="enlarge-custom-emojis" type="b">
<default>false</default>
</key>
<key name="default-content-type" type="s">
<default>'text/plain'</default>
</key>
<key name="use-blurhash" type="b">
<default>true</default>
</key>
Expand All @@ -79,12 +83,6 @@
<default>true</default>
</key>

<key name="window-x" type="i">
<default>-1</default>
</key>
<key name="window-y" type="i">
<default>-1</default>
</key>
<key name="window-w" type="i">
<default>600</default>
</key>
Expand All @@ -94,8 +92,5 @@
<key name="window-maximized" type="b">
<default>false</default>
</key>
<key name="muted-notification-types" type="as">
<default>[]</default>
</key>
</schema>
</schemalist>
2 changes: 1 addition & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ namespace Tuba {

protected override void shutdown () {
#if !DEV_MODE
settings.apply ();
settings.apply_all ();
#endif
network.flush_cache ();

Expand Down
2 changes: 1 addition & 1 deletion src/Services/Accounts/SecretAccountStore.vala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class Tuba.SecretAccountStore : AccountStore {
account.added ();

// TODO: remove uuid fallback
if (force_save) save ();
if (force_save) safe_save ();
}
});
changed (saved);
Expand Down
94 changes: 86 additions & 8 deletions src/Services/Settings.vala
Original file line number Diff line number Diff line change
@@ -1,8 +1,85 @@
public class Tuba.Settings : GLib.Settings {
public string active_account { get; set; }
public string default_language { get; set; default = "en"; }
class Account : GLib.Settings {
public string default_language { get; set; default = "en"; }
public string default_post_visibility { get; set; default = "public"; }
public string default_content_type { get; set; default = "text/plain"; }
public string[] muted_notification_types { get; set; default = {}; }

private static string[] keys_to_init = {
"default-post-visibility",
"muted-notification-types",
"default-content-type"
};

public Account (string id) {
Object (schema_id: @"$(Build.DOMAIN).Account", path: @"/$(Build.DOMAIN.replace (".", "/"))/accounts/$id/");
this.delay ();

foreach (var key in keys_to_init) {
init (key);
}
}

void init (string key) {
bind (key, this, key, SettingsBindFlags.DEFAULT);
}
}

private Account active_account_settings { get; set; }
private string _active_account = "";
public string active_account {
get {
return _active_account;
}

set {
_active_account = value;
if (active_account_settings != null) active_account_settings.apply ();
active_account_settings = new Account (value);
}
}

public string default_language {
get {
return active_account_settings.default_language;
}

set {
active_account_settings.default_language = value;
}
}

public string default_post_visibility {
get {
return active_account_settings.default_post_visibility;
}

set {
active_account_settings.default_post_visibility = value;
}
}

public string default_content_type {
get {
return active_account_settings.default_content_type;
}

set {
active_account_settings.default_content_type = value;
}
}

public string[] muted_notification_types {
get {
return active_account_settings.muted_notification_types;
}

set {
active_account_settings.muted_notification_types = value;
}
}

public ColorScheme color_scheme { get; set; }
public string default_post_visibility { get; set; default = "public"; }
public bool work_in_background { get; set; }
public int timeline_page_size { get; set; }
public bool live_updates { get; set; }
Expand All @@ -17,18 +94,15 @@ public class Tuba.Settings : GLib.Settings {
public bool letterbox_media { get; set; }
public bool media_viewer_expand_pictures { get; set; }
public bool enlarge_custom_emojis { get; set; }
public string default_content_type { get; set; default = "text/plain"; }
public bool use_blurhash { get; set; }
public bool group_push_notifications { get; set; }
public bool advanced_boost_dialog { get; set; }
public bool reply_to_old_post_reminder { get; set; }
public bool spellchecker_enabled { get; set; }

public string[] muted_notification_types { get; set; default = {}; }
private static string[] keys_to_init = {
"active-account",
"color-scheme",
"default-post-visibility",
"timeline-page-size",
"live-updates",
"public-live-updates",
Expand All @@ -42,8 +116,6 @@ public class Tuba.Settings : GLib.Settings {
"letterbox-media",
"media-viewer-expand-pictures",
"enlarge-custom-emojis",
"muted-notification-types",
"default-content-type",
"use-blurhash",
"group-push-notifications",
"advanced-boost-dialog",
Expand Down Expand Up @@ -74,6 +146,12 @@ public class Tuba.Settings : GLib.Settings {
if (key in apply_instantly_keys) apply ();
#endif
}

public void apply_all () {
if (active_account_settings != null) active_account_settings.apply ();

this.apply ();
}
}

public enum Tuba.ColorScheme {
Expand Down