From 7cb1d33b9a067c44163be4abfab409d31805a849 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Mon, 13 Sep 2021 18:58:11 -0400 Subject: [PATCH 01/10] Use Portal For clock-format Use portal instead of GSettings for clock-format --- lib/DateTime.vala | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/DateTime.vala b/lib/DateTime.vala index 498423031..620bf2ecb 100644 --- a/lib/DateTime.vala +++ b/lib/DateTime.vala @@ -8,6 +8,12 @@ * getting the default translated format for either date and time. */ namespace Granite.DateTime { + + [DBus (name = "org.freedesktop.portal.Settings")] + private interface FDO.Portal.Settings : Object { + public abstract Variant read (string @namespace, string key); + } + /** * Gets a default translated time format. * The function constructs a new string interpreting the //is_12h// and //with_second// parameters @@ -96,8 +102,16 @@ namespace Granite.DateTime { * @return true if the clock format is 12h based, false otherwise. */ private static bool is_clock_format_12h () { - var h24_settings = new GLib.Settings ("org.gnome.desktop.interface"); - var format = h24_settings.get_string ("clock-format"); + FDO.Portal.Settings settings_bus = GLib.Bus.get_proxy_sync ( + GLib.BusType.SESSION, + "org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop" + ); + + var clock_format_variant = settings_bus.read ("org.gnome.desktop.interface", "clock-format").get_variant (); + var format = clock_format_variant.get_string (); + + return (format.contains ("12h")); } From 68a4c1eda336eae5265a316ec0c20e1db2347db3 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Thu, 16 Sep 2021 22:22:23 -0400 Subject: [PATCH 02/10] Exposes clock format as Granite Setting Also, updates time picker to dynamically re-render using that setting --- lib/DateTime.vala | 18 +-------- lib/Widgets/Settings.vala | 76 +++++++++++++++++++++++++++++++++++++ lib/Widgets/TimePicker.vala | 23 ++++++++--- 3 files changed, 96 insertions(+), 21 deletions(-) diff --git a/lib/DateTime.vala b/lib/DateTime.vala index 620bf2ecb..b4ec684f0 100644 --- a/lib/DateTime.vala +++ b/lib/DateTime.vala @@ -9,11 +9,6 @@ */ namespace Granite.DateTime { - [DBus (name = "org.freedesktop.portal.Settings")] - private interface FDO.Portal.Settings : Object { - public abstract Variant read (string @namespace, string key); - } - /** * Gets a default translated time format. * The function constructs a new string interpreting the //is_12h// and //with_second// parameters @@ -102,17 +97,8 @@ namespace Granite.DateTime { * @return true if the clock format is 12h based, false otherwise. */ private static bool is_clock_format_12h () { - FDO.Portal.Settings settings_bus = GLib.Bus.get_proxy_sync ( - GLib.BusType.SESSION, - "org.freedesktop.portal.Desktop", - "/org/freedesktop/portal/desktop" - ); - - var clock_format_variant = settings_bus.read ("org.gnome.desktop.interface", "clock-format").get_variant (); - var format = clock_format_variant.get_string (); - - - return (format.contains ("12h")); + var settings = Granite.Settings.get_default (); + return settings.clock_format == Granite.Settings.ClockFormat.12H; } /** diff --git a/lib/Widgets/Settings.vala b/lib/Widgets/Settings.vala index d81ef148b..292ac7699 100644 --- a/lib/Widgets/Settings.vala +++ b/lib/Widgets/Settings.vala @@ -13,11 +13,21 @@ namespace Granite { interface FDO.Accounts : Object { public abstract string find_user_by_name (string username) throws GLib.Error; } + + [DBus (name = "org.freedesktop.portal.Settings")] + private interface FDO.Portal.Settings : Object { + public abstract Variant read (string @namespace, string key); + public abstract signal void setting_changed (string @namespace, string key, Variant @value); + } /** * Granite.Settings provides a way to share Pantheon desktop settings with applications. */ public class Settings : Object { + + private const string GNOME_DESKTOP_INTERFACE = "org.gnome.desktop.interface"; + private const string CLOCK_FORMAT_KEY = "clock-format"; + /** * Possible color scheme preferences expressed by the user */ @@ -68,6 +78,36 @@ namespace Granite { _user_path = value; } } + + /** + * Possible clock format preferences expressed by the user + */ + public enum ClockFormat { + /** + * The user prefers a 12 hour clock + */ + 12H, + /** + * The user prefers a 24 hour clock + */ + 24H + } + + private ClockFormat? _clock_format = null; + /** + * Whether the user would prefer a 12 hour or 24 hour clock + */ + public ClockFormat clock_format { + get { + if (_clock_format == null) { + setup_clock_format (); + } + return _clock_format; + } + private set { + _clock_format = value; + } + } private static GLib.Once instance; public static unowned Granite.Settings get_default () { @@ -78,6 +118,7 @@ namespace Granite { private FDO.Accounts? accounts_service = null; private Pantheon.AccountsService? pantheon_act = null; + private FDO.Portal.Settings? settings_service = null; private Settings () {} @@ -116,5 +157,40 @@ namespace Granite { critical (e.message); } } + + private void setup_clock_format () { + try { + settings_service = GLib.Bus.get_proxy_sync ( + GLib.BusType.SESSION, + "org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop" + ); + + var clock_format_variant = settings_service.read (GNOME_DESKTOP_INTERFACE, CLOCK_FORMAT_KEY).get_variant (); + var format = clock_format_variant.get_string (); + + set_clock_format_from_nick (format); + + settings_service.setting_changed.connect((@namespace,key,@value) => { + if(@namespace == GNOME_DESKTOP_INTERFACE && key == CLOCK_FORMAT_KEY) { + var updated_format = @value.get_string (); + set_clock_format_from_nick (updated_format); + } + }); + } catch (Error e) { + critical (e.message); + } + } + + private void set_clock_format_from_nick(string format) { + EnumClass clock_format_enum_class = (EnumClass) typeof (ClockFormat).class_ref (); + unowned EnumValue? eval = clock_format_enum_class.get_value_by_nick (format); + + if(eval == null) { + _clock_format = null; + } else { + clock_format = (ClockFormat) eval.value; + } + } } } diff --git a/lib/Widgets/TimePicker.vala b/lib/Widgets/TimePicker.vala index 8f3110c83..a0d96dc5d 100644 --- a/lib/Widgets/TimePicker.vala +++ b/lib/Widgets/TimePicker.vala @@ -185,6 +185,13 @@ namespace Granite.Widgets { activate.connect (is_unfocused); update_text (); + + var granite_settings = Granite.Settings.get_default (); + + granite_settings.notify["clock-format"].connect (() => { + update_text (); + set_popover_clock_format (); + }); } private void update_time (bool is_hour) { @@ -222,6 +229,14 @@ namespace Granite.Widgets { private void on_icon_press (Gtk.EntryIconPosition position, Gdk.Event event) { // If the mode is changed from 12h to 24h or visa versa, the entry updates on icon press update_text (); + + set_popover_clock_format (); + + popover.pointing_to = get_icon_area (Gtk.EntryIconPosition.SECONDARY); + popover.show_all (); + } + + private void set_popover_clock_format () { changing_time = true; if (Granite.DateTime.is_clock_format_12h () && time.get_hour () > 12) { @@ -245,18 +260,16 @@ namespace Granite.Widgets { // Make sure that bounds are set correctly hours_spinbutton.set_range (1, 12); } else { + + hours_spinbutton.set_range (0, 23); + am_pm_modebutton.no_show_all = true; am_pm_modebutton.hide (); hours_spinbutton.set_value (time.get_hour ()); - - hours_spinbutton.set_range (0, 23); } minutes_spinbutton.set_value (time.get_minute ()); changing_time = false; - - popover.pointing_to = get_icon_area (Gtk.EntryIconPosition.SECONDARY); - popover.show_all (); } [Version (deprecated = true, deprecated_since = "5.2.0")] From e3b27f296ef7ccf625fa46a9e0aefd66a459d170 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Thu, 16 Sep 2021 22:35:39 -0400 Subject: [PATCH 03/10] Adds API to format a GLib.DateTime Adds API to format a GLib.DateTime using system settings so that end user applications don't have to all carry the same code. --- demo/Views/DateTimePickerView.vala | 10 +++++++--- lib/DateTime.vala | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/demo/Views/DateTimePickerView.vala b/demo/Views/DateTimePickerView.vala index ba026409b..633ca3289 100644 --- a/demo/Views/DateTimePickerView.vala +++ b/demo/Views/DateTimePickerView.vala @@ -32,13 +32,17 @@ public class DateTimePickerView : Gtk.Grid { current_time_label.halign = Gtk.Align.END; var now = new DateTime.now_local (); - var settings = new Settings ("org.gnome.desktop.interface"); - var time_format = Granite.DateTime.get_default_time_format (settings.get_enum ("clock-format") == 1, false); + var settings = Granite.Settings.get_default (); + var time_format = Granite.DateTime.get_default_time_format (settings.clock_format == Granite.Settings.ClockFormat.12H, false); - var current_time = new Gtk.Label (now.format (time_format)); + var current_time = new Gtk.Label (Granite.DateTime.format_time(now, false)); current_time.tooltip_text = time_format; current_time.xalign = 0; + settings.notify["clock-format"].connect(() => { + current_time.label = Granite.DateTime.format_time(now, false); + }); + var current_date_label = new Gtk.Label ("Localized date:"); current_date_label.halign = Gtk.Align.END; diff --git a/lib/DateTime.vala b/lib/DateTime.vala index b4ec684f0..0e8483a39 100644 --- a/lib/DateTime.vala +++ b/lib/DateTime.vala @@ -14,13 +14,13 @@ namespace Granite.DateTime { * The function constructs a new string interpreting the //is_12h// and //with_second// parameters * so that it can be used with formatting functions like {@link GLib.DateTime.format}. * - * The returned string is formatted and translated. This function is mostly used to display + * The returned format string is formatted and translated. This function is mostly used to display * the time in various user interfaces like the time displayed in the top panel. * * @param is_12h if the returned string should be formatted in 12h format * @param with_second if the returned string should include seconds * - * @return the formatted and located time string. + * @return the formatted and located time format string. */ public static string get_default_time_format (bool is_12h = false, bool with_second = false) { if (is_12h == true) { @@ -41,6 +41,22 @@ namespace Granite.DateTime { } } } + + /** + * Formats a {@link GLib.DateTime} using defaults from desktop settings + * + * The returned string is formatted and translated. This function is mostly used to display + * the time in various user interfaces like the time displayed in the top panel. + * + * @param date_time a {@link GLib.DateTime} to format using the desktop settings + * @param with_second if the returned string should include seconds + * @return the formatted and located time string. + */ + public static string format_time (GLib.DateTime date_time, bool with_second = false) { + var is_12h = is_clock_format_12h (); + var time_format = get_default_time_format (is_12h, with_second); + return date_time.format (time_format); + } /** * Compares a {@link GLib.DateTime} to {@link GLib.DateTime.now_local} and returns a location, relative date and From 2583b9a995d85912eb84dcdd098f06f981444e06 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Thu, 16 Sep 2021 22:46:09 -0400 Subject: [PATCH 04/10] Fix linting --- demo/Views/DateTimePickerView.vala | 6 +++--- lib/DateTime.vala | 2 +- lib/Widgets/Settings.vala | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/demo/Views/DateTimePickerView.vala b/demo/Views/DateTimePickerView.vala index 633ca3289..21d785630 100644 --- a/demo/Views/DateTimePickerView.vala +++ b/demo/Views/DateTimePickerView.vala @@ -35,12 +35,12 @@ public class DateTimePickerView : Gtk.Grid { var settings = Granite.Settings.get_default (); var time_format = Granite.DateTime.get_default_time_format (settings.clock_format == Granite.Settings.ClockFormat.12H, false); - var current_time = new Gtk.Label (Granite.DateTime.format_time(now, false)); + var current_time = new Gtk.Label (Granite.DateTime.format_time (now, false)); current_time.tooltip_text = time_format; current_time.xalign = 0; - settings.notify["clock-format"].connect(() => { - current_time.label = Granite.DateTime.format_time(now, false); + settings.notify["clock-format"].connect (() => { + current_time.label = Granite.DateTime.format_time (now, false); }); var current_date_label = new Gtk.Label ("Localized date:"); diff --git a/lib/DateTime.vala b/lib/DateTime.vala index 0e8483a39..eecfbd9bb 100644 --- a/lib/DateTime.vala +++ b/lib/DateTime.vala @@ -41,7 +41,7 @@ namespace Granite.DateTime { } } } - + /** * Formats a {@link GLib.DateTime} using defaults from desktop settings * diff --git a/lib/Widgets/Settings.vala b/lib/Widgets/Settings.vala index 292ac7699..7b8133552 100644 --- a/lib/Widgets/Settings.vala +++ b/lib/Widgets/Settings.vala @@ -13,7 +13,7 @@ namespace Granite { interface FDO.Accounts : Object { public abstract string find_user_by_name (string username) throws GLib.Error; } - + [DBus (name = "org.freedesktop.portal.Settings")] private interface FDO.Portal.Settings : Object { public abstract Variant read (string @namespace, string key); @@ -24,10 +24,10 @@ namespace Granite { * Granite.Settings provides a way to share Pantheon desktop settings with applications. */ public class Settings : Object { - + private const string GNOME_DESKTOP_INTERFACE = "org.gnome.desktop.interface"; private const string CLOCK_FORMAT_KEY = "clock-format"; - + /** * Possible color scheme preferences expressed by the user */ @@ -78,7 +78,7 @@ namespace Granite { _user_path = value; } } - + /** * Possible clock format preferences expressed by the user */ @@ -90,9 +90,9 @@ namespace Granite { /** * The user prefers a 24 hour clock */ - 24H + 24H } - + private ClockFormat? _clock_format = null; /** * Whether the user would prefer a 12 hour or 24 hour clock @@ -157,7 +157,7 @@ namespace Granite { critical (e.message); } } - + private void setup_clock_format () { try { settings_service = GLib.Bus.get_proxy_sync ( @@ -165,12 +165,12 @@ namespace Granite { "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop" ); - + var clock_format_variant = settings_service.read (GNOME_DESKTOP_INTERFACE, CLOCK_FORMAT_KEY).get_variant (); var format = clock_format_variant.get_string (); - + set_clock_format_from_nick (format); - + settings_service.setting_changed.connect((@namespace,key,@value) => { if(@namespace == GNOME_DESKTOP_INTERFACE && key == CLOCK_FORMAT_KEY) { var updated_format = @value.get_string (); @@ -181,11 +181,11 @@ namespace Granite { critical (e.message); } } - + private void set_clock_format_from_nick(string format) { EnumClass clock_format_enum_class = (EnumClass) typeof (ClockFormat).class_ref (); unowned EnumValue? eval = clock_format_enum_class.get_value_by_nick (format); - + if(eval == null) { _clock_format = null; } else { From 074d6d03c8982571431f3466c249e1acddeda723 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Thu, 16 Sep 2021 22:48:43 -0400 Subject: [PATCH 05/10] More linting --- lib/Widgets/Settings.vala | 8 ++++---- lib/Widgets/TimePicker.vala | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Widgets/Settings.vala b/lib/Widgets/Settings.vala index 7b8133552..243fbbe58 100644 --- a/lib/Widgets/Settings.vala +++ b/lib/Widgets/Settings.vala @@ -171,8 +171,8 @@ namespace Granite { set_clock_format_from_nick (format); - settings_service.setting_changed.connect((@namespace,key,@value) => { - if(@namespace == GNOME_DESKTOP_INTERFACE && key == CLOCK_FORMAT_KEY) { + settings_service.setting_changed.connect ((@namespace, key, @value) => { + if (@namespace == GNOME_DESKTOP_INTERFACE && key == CLOCK_FORMAT_KEY) { var updated_format = @value.get_string (); set_clock_format_from_nick (updated_format); } @@ -182,11 +182,11 @@ namespace Granite { } } - private void set_clock_format_from_nick(string format) { + private void set_clock_format_from_nick (string format) { EnumClass clock_format_enum_class = (EnumClass) typeof (ClockFormat).class_ref (); unowned EnumValue? eval = clock_format_enum_class.get_value_by_nick (format); - if(eval == null) { + if (eval == null) { _clock_format = null; } else { clock_format = (ClockFormat) eval.value; diff --git a/lib/Widgets/TimePicker.vala b/lib/Widgets/TimePicker.vala index a0d96dc5d..ed2cacd1c 100644 --- a/lib/Widgets/TimePicker.vala +++ b/lib/Widgets/TimePicker.vala @@ -185,9 +185,9 @@ namespace Granite.Widgets { activate.connect (is_unfocused); update_text (); - + var granite_settings = Granite.Settings.get_default (); - + granite_settings.notify["clock-format"].connect (() => { update_text (); set_popover_clock_format (); @@ -235,7 +235,7 @@ namespace Granite.Widgets { popover.pointing_to = get_icon_area (Gtk.EntryIconPosition.SECONDARY); popover.show_all (); } - + private void set_popover_clock_format () { changing_time = true; @@ -260,9 +260,9 @@ namespace Granite.Widgets { // Make sure that bounds are set correctly hours_spinbutton.set_range (1, 12); } else { - + hours_spinbutton.set_range (0, 23); - + am_pm_modebutton.no_show_all = true; am_pm_modebutton.hide (); hours_spinbutton.set_value (time.get_hour ()); From 12bec727850aec1204b7d9abf2d3b9d82511f152 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Fri, 17 Sep 2021 12:26:18 -0400 Subject: [PATCH 06/10] Updates 1. Use new format_time method in get_relative_datetime 2. Fall back to GLib.Settings if we can't connect to desktop portal --- lib/DateTime.vala | 2 +- lib/Widgets/Settings.vala | 32 +++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/DateTime.vala b/lib/DateTime.vala index eecfbd9bb..5c69b314f 100644 --- a/lib/DateTime.vala +++ b/lib/DateTime.vala @@ -92,7 +92,7 @@ namespace Granite.DateTime { } } - return date_time.format (get_default_time_format (is_clock_format_12h (), false)); + return format_time (date_time, false); } else if (is_same_day (date_time.add_days (1), now)) { return _("Yesterday"); } else if (is_same_day (date_time.add_days (-1), now)) { diff --git a/lib/Widgets/Settings.vala b/lib/Widgets/Settings.vala index 243fbbe58..24e304d81 100644 --- a/lib/Widgets/Settings.vala +++ b/lib/Widgets/Settings.vala @@ -16,7 +16,7 @@ namespace Granite { [DBus (name = "org.freedesktop.portal.Settings")] private interface FDO.Portal.Settings : Object { - public abstract Variant read (string @namespace, string key); + public abstract Variant read (string @namespace, string key) throws GLib.Error; public abstract signal void setting_changed (string @namespace, string key, Variant @value); } @@ -157,14 +157,21 @@ namespace Granite { critical (e.message); } } - - private void setup_clock_format () { - try { + + private void setup_settings_service () throws Error { + if (settings_service == null) { settings_service = GLib.Bus.get_proxy_sync ( GLib.BusType.SESSION, - "org.freedesktop.portal.Desktop", - "/org/freedesktop/portal/desktop" + "org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop" ); + } + } + + private void setup_clock_format () { + try { + + setup_settings_service (); var clock_format_variant = settings_service.read (GNOME_DESKTOP_INTERFACE, CLOCK_FORMAT_KEY).get_variant (); var format = clock_format_variant.get_string (); @@ -178,7 +185,18 @@ namespace Granite { } }); } catch (Error e) { - critical (e.message); + debug ("Unable to connect to desktop portal (%s), using GSettings", e.message); + + var interface_settings = new GLib.Settings (GNOME_DESKTOP_INTERFACE); + var format = interface_settings.get_string (CLOCK_FORMAT_KEY); + set_clock_format_from_nick (format); + + interface_settings.changed.connect((key) => { + if (key == CLOCK_FORMAT_KEY) { + var updated_format = interface_settings.get_string (CLOCK_FORMAT_KEY); + set_clock_format_from_nick (updated_format); + } + }); } } From 637f95fb631a16d23c4277461a32a0538dda62d6 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Fri, 17 Sep 2021 12:29:46 -0400 Subject: [PATCH 07/10] linting --- lib/Widgets/Settings.vala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Widgets/Settings.vala b/lib/Widgets/Settings.vala index 24e304d81..b265ad7e2 100644 --- a/lib/Widgets/Settings.vala +++ b/lib/Widgets/Settings.vala @@ -157,7 +157,7 @@ namespace Granite { critical (e.message); } } - + private void setup_settings_service () throws Error { if (settings_service == null) { settings_service = GLib.Bus.get_proxy_sync ( @@ -170,7 +170,7 @@ namespace Granite { private void setup_clock_format () { try { - + setup_settings_service (); var clock_format_variant = settings_service.read (GNOME_DESKTOP_INTERFACE, CLOCK_FORMAT_KEY).get_variant (); @@ -186,16 +186,16 @@ namespace Granite { }); } catch (Error e) { debug ("Unable to connect to desktop portal (%s), using GSettings", e.message); - + var interface_settings = new GLib.Settings (GNOME_DESKTOP_INTERFACE); var format = interface_settings.get_string (CLOCK_FORMAT_KEY); set_clock_format_from_nick (format); - - interface_settings.changed.connect((key) => { + + interface_settings.changed.connect ((key) => { if (key == CLOCK_FORMAT_KEY) { var updated_format = interface_settings.get_string (CLOCK_FORMAT_KEY); set_clock_format_from_nick (updated_format); - } + } }); } } From ee3266e1fed43da31310777133db906bba10aeba Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Sat, 23 Oct 2021 21:58:48 -0400 Subject: [PATCH 08/10] Switch to Granite.Portal.Settings --- lib/Widgets/Settings.vala | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/lib/Widgets/Settings.vala b/lib/Widgets/Settings.vala index 1a3b6e452..9daca62b7 100644 --- a/lib/Widgets/Settings.vala +++ b/lib/Widgets/Settings.vala @@ -14,12 +14,6 @@ namespace Granite { public abstract string find_user_by_name (string username) throws GLib.Error; } - [DBus (name = "org.freedesktop.portal.Settings")] - private interface FDO.Portal.Settings : Object { - public abstract Variant read (string @namespace, string key) throws GLib.Error; - public abstract signal void setting_changed (string @namespace, string key, Variant @value); - } - /** * Granite.Settings provides a way to share Pantheon desktop settings with applications. */ @@ -176,27 +170,16 @@ namespace Granite { } } - private void setup_settings_service () throws Error { - if (settings_service == null) { - settings_service = GLib.Bus.get_proxy_sync ( - GLib.BusType.SESSION, - "org.freedesktop.portal.Desktop", - "/org/freedesktop/portal/desktop" - ); - } - } - private void setup_clock_format () { try { + portal = Portal.Settings.get (); - setup_settings_service (); - - var clock_format_variant = settings_service.read (GNOME_DESKTOP_INTERFACE, CLOCK_FORMAT_KEY).get_variant (); + var clock_format_variant = portal.read (GNOME_DESKTOP_INTERFACE, CLOCK_FORMAT_KEY).get_variant (); var format = clock_format_variant.get_string (); set_clock_format_from_nick (format); - settings_service.setting_changed.connect ((@namespace, key, @value) => { + portal.setting_changed.connect ((@namespace, key, @value) => { if (@namespace == GNOME_DESKTOP_INTERFACE && key == CLOCK_FORMAT_KEY) { var updated_format = @value.get_string (); set_clock_format_from_nick (updated_format); From 3ae15a23a4a3b7491c51ce5e52934938b0b5392b Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Sat, 23 Oct 2021 22:03:08 -0400 Subject: [PATCH 09/10] Only create portal once --- lib/Widgets/Settings.vala | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Widgets/Settings.vala b/lib/Widgets/Settings.vala index 9daca62b7..918a7e6e0 100644 --- a/lib/Widgets/Settings.vala +++ b/lib/Widgets/Settings.vala @@ -130,9 +130,15 @@ namespace Granite { } } + private void setup_portal () { + if (portal == null) { + portal = Portal.Settings.get (); + } + } + private void setup_prefers_color_scheme () { try { - portal = Portal.Settings.get (); + setup_portal (); prefers_color_scheme = (ColorScheme) portal.read ( "org.freedesktop.appearance", @@ -172,7 +178,7 @@ namespace Granite { private void setup_clock_format () { try { - portal = Portal.Settings.get (); + setup_portal (); var clock_format_variant = portal.read (GNOME_DESKTOP_INTERFACE, CLOCK_FORMAT_KEY).get_variant (); var format = clock_format_variant.get_string (); From 1522581e6c92a9bb9c2357178e66e4b3a4ff1d56 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Thu, 9 Dec 2021 09:18:07 -0500 Subject: [PATCH 10/10] Update Settings.vala Reverse order of enum so that 24H is the default --- lib/Widgets/Settings.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Widgets/Settings.vala b/lib/Widgets/Settings.vala index 1b5682bbd..007eb97bf 100644 --- a/lib/Widgets/Settings.vala +++ b/lib/Widgets/Settings.vala @@ -78,13 +78,13 @@ namespace Granite { */ public enum ClockFormat { /** - * The user prefers a 12 hour clock + * The user prefers a 24 hour clock */ - 12H, + 24H, /** - * The user prefers a 24 hour clock + * The user prefers a 12 hour clock */ - 24H + 12H } private ClockFormat? _clock_format = null;