[glib: 3/5] gpowerprofilemonitorportal: Set property value by default
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 3/5] gpowerprofilemonitorportal: Set property value by default
- Date: Tue, 7 Sep 2021 10:16:41 +0000 (UTC)
commit d051ef16111ccf82d0ffd84f6491ebad688318c5
Author: Philip Withnall <pwithnall endlessos org>
Date: Mon Sep 6 18:56:12 2021 +0100
gpowerprofilemonitorportal: Set property value by default
When first creating the monitor, correctly set its property value to the
value from the portal, rather than waiting for the portal value to
change to set it.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Fixes: #2481
gio/gpowerprofilemonitorportal.c | 7 +++++++
gio/tests/power-profile-monitor-portal.py.in | 12 ++++++++++++
2 files changed, 19 insertions(+)
---
diff --git a/gio/gpowerprofilemonitorportal.c b/gio/gpowerprofilemonitorportal.c
index bb1b4fd15..6bc251fd5 100644
--- a/gio/gpowerprofilemonitorportal.c
+++ b/gio/gpowerprofilemonitorportal.c
@@ -108,6 +108,7 @@ g_power_profile_monitor_portal_initable_init (GInitable *initable,
GPowerProfileMonitorPortal *ppm = G_POWER_PROFILE_MONITOR_PORTAL (initable);
GDBusProxy *proxy;
gchar *name_owner;
+ GVariant *power_saver_enabled_v = NULL;
if (!glib_should_use_portal ())
{
@@ -143,6 +144,12 @@ g_power_profile_monitor_portal_initable_init (GInitable *initable,
ppm->signal_id = g_signal_connect (proxy, "g-properties-changed",
G_CALLBACK (proxy_properties_changed), ppm);
+ power_saver_enabled_v = g_dbus_proxy_get_cached_property (proxy, "power-saver-enabled");
+ if (power_saver_enabled_v != NULL &&
+ g_variant_is_of_type (power_saver_enabled_v, G_VARIANT_TYPE_BOOLEAN))
+ ppm->power_saver_enabled = g_variant_get_boolean (power_saver_enabled_v);
+ g_clear_pointer (&power_saver_enabled_v, g_variant_unref);
+
ppm->proxy = g_steal_pointer (&proxy);
return TRUE;
diff --git a/gio/tests/power-profile-monitor-portal.py.in b/gio/tests/power-profile-monitor-portal.py.in
index 960a62232..8f6232cff 100755
--- a/gio/tests/power-profile-monitor-portal.py.in
+++ b/gio/tests/power-profile-monitor-portal.py.in
@@ -28,6 +28,7 @@ try:
import dbusmock
from gi.repository import GLib
from gi.repository import Gio
+ from gi.repository import GObject
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -116,6 +117,17 @@ try:
self.dbus_props.Set('net.hadess.PowerProfiles', 'ActiveProfile', dbus.String('balanced',
variant_level=1))
self.assertEventually(lambda: self.power_saver_enabled == False, "power-saver didn't become
disabled", 10)
+ def test_power_profile_power_saver_enabled_portal_default(self):
+ '''power-saver-enabled property default value'''
+
+ self.dbus_props.Set('net.hadess.PowerProfiles', 'ActiveProfile', dbus.String('power-saver',
variant_level=1))
+
+ # Create a new power profile monitor and check its property value is
+ # correct by default.
+ new_power_profile_monitor = GObject.new(GObject.type_from_name('GPowerProfileMonitorPortal'))
+ new_power_profile_monitor.init()
+ self.assertTrue(new_power_profile_monitor.get_power_saver_enabled())
+
except ImportError as e:
@unittest.skip("Cannot import %s" % e.name)
class TestPowerProfileMonitorPortal(unittest.TestCase):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]