diff --git a/lib/DateTime.vala b/lib/DateTime.vala index 498423031..c45d68b9b 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,23 @@ 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"); + 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")); }