From 7cb1d33b9a067c44163be4abfab409d31805a849 Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Mon, 13 Sep 2021 18:58:11 -0400 Subject: [PATCH 1/2] 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 6995a0ed5413ffc4c2eea70673e346e551d4606f Mon Sep 17 00:00:00 2001 From: Justin Haygood Date: Fri, 17 Sep 2021 12:16:00 -0400 Subject: [PATCH 2/2] Accepting suggestion from @tintou MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Corentin Noël --- lib/DateTime.vala | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/DateTime.vala b/lib/DateTime.vala index 620bf2ecb..c45d68b9b 100644 --- a/lib/DateTime.vala +++ b/lib/DateTime.vala @@ -102,14 +102,21 @@ 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 (); + string format; + try { + var 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 (); + format = clock_format_variant.get_string (); + } catch (GLib.Error e) { + debug ("Unable to connect to desktop portal (%s), using GSettings", e.message); + var h24_settings = new GLib.Settings ("org.gnome.desktop.interface"); + format = h24_settings.get_string ("clock-format"); + } return (format.contains ("12h"));