Merge branch '2481-power-profile-default-value' into 'main'

gpowerprofilemonitorportal: Set property value by default

Closes #2481

See merge request GNOME/glib!2241
This commit is contained in:
Philip Withnall 2021-09-07 10:16:40 +00:00
commit b52de547cb
3 changed files with 26 additions and 1 deletions

View File

@ -116,7 +116,8 @@ ppd_proxy_cb (GObject *source_object,
}
active_profile_variant = g_dbus_proxy_get_cached_property (proxy, "ActiveProfile");
if (g_variant_is_of_type (active_profile_variant, G_VARIANT_TYPE_STRING))
if (active_profile_variant != NULL &&
g_variant_is_of_type (active_profile_variant, G_VARIANT_TYPE_STRING))
{
active_profile = g_variant_get_string (active_profile_variant, NULL);
power_saver_enabled = g_strcmp0 (active_profile, "power-saver") == 0;
@ -126,6 +127,7 @@ ppd_proxy_cb (GObject *source_object,
g_object_notify (G_OBJECT (dbus), "power-saver-enabled");
}
}
g_clear_pointer (&active_profile_variant, g_variant_unref);
dbus->signal_id = g_signal_connect (G_OBJECT (proxy), "g-properties-changed",
G_CALLBACK (ppd_properties_changed_cb), dbus);

View File

@ -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;

View File

@ -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)
@ -65,12 +66,16 @@ try:
try:
self.xdp = subprocess.Popen([XDG_DESKTOP_PORTAL_PATH])
except FileNotFoundError:
self.p_mock.terminate()
self.p_mock.wait()
raise unittest.SkipTest("xdg-desktop-portal not available")
try:
self.wait_for_bus_object('org.freedesktop.portal.Desktop',
'/org/freedesktop/portal/desktop')
except:
self.p_mock.terminate()
self.p_mock.wait()
raise
# subprocess.Popen(['gdbus', 'monitor', '--session', '--dest', 'org.freedesktop.portal.Desktop'])
@ -116,6 +121,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):