Merge lp:~donadigo/appcenter/gtk-application-inhibit into lp:~elementary-apps/appcenter/appcenter

Proposed by Adam Bieńkowski
Status: Rejected
Rejected by: Danielle Foré
Proposed branch: lp:~donadigo/appcenter/gtk-application-inhibit
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 210 lines (+28/-81)
5 files modified
src/Application.vala (+19/-0)
src/CMakeLists.txt (+0/-1)
src/Core/Client.vala (+4/-4)
src/SuspendControl.vala (+0/-71)
src/Views/AppListView.vala (+5/-5)
To merge this branch: bzr merge lp:~donadigo/appcenter/gtk-application-inhibit
Reviewer Review Type Date Requested Status
David Hewitt Disapprove
Review via email: mp+317793@code.launchpad.net

Commit message

* Use Gtk.Application.inhibit API instead of a custom one

Description of the change

This branch fixes bug #1656441: "Use Gtk.Application.inhibit".

Instead of creating an entire new class for managing inhibition, we just call Gtk.Application.inhibit, which supports different types of inhibiting and also ensures that in the future we can e.g: implement org.freedesktop.portal.Desktop interface for a custom inhibit behaviour.

To post a comment you must log in.
Revision history for this message
David Hewitt (davidmhewitt) wrote :

This is very difficult to test since the inhibit is only active during updates etc.

Considering the same fix was rejected from Audience for not working, has this been tested to ensure it does inhibit? If so, can you provide details on how to test it?

review: Needs Information
Revision history for this message
Adam Bieńkowski (donadigo) wrote :

davidmhewitt: the reason this was rejected from audience is that Audience also calls something like "SimulateUserActivity" and Gtk Application does not. I did check what does the code in Gtk.Application class and it does the same as the unneded SuspendControl class in AppCenter (meaning connecting to the right interface and calling methods in order to inhibit the session, in this case org.gnome.SessionManager).

For testing I guess for the time AppCenter updates the OS, you could look into the gnome's SessionManager interface in d-feet to see if the session is currently inhibited. The other way is to do that in the code using Gtk.Application.is_inhibited to print out the boolean value of it's state.

Revision history for this message
David Hewitt (davidmhewitt) wrote :

Ok, so I've had a bit of a play with this and it seems there's a bit of a problem. Although, not with your code.

The inhibit doesn't work with this branch or with trunk. I tested by letting some updates build up and then tried to suspend mid way through the updates being applied, and the computer happily suspended.

I've done a bit of investigation and it seems as though there's a permissions issue.

For example, if you run:
systemd-inhibit --what="idle:sleep:shutdown" --mode=block sleep 40

and then try to suspend the computer, it suspends instantly.

However, if you run that with sudo on the front and give it your password, and then try to suspend, you get the polkit dialog telling you that suspend is inhibited.

I wrote a little helper to talk to the org.freedesktop.login1 D-BUS server and the same applies, if you run as a normal user, it looks like the inhibit calls succeed, but you can still suspend. If you run the helper as root, it works.

Couldn't test the org.gnome.SessionManager stuff as root as that's running on the session D-BUS, but I imagine the result might have been the same. So I don't think there's any point merging this until we can come up with a fix for why the inhibit doesn't work at all.

review: Disapprove

Unmerged revisions

405. By Adam Bieńkowski

Use inhibit in Gtk.Application instead of using SuspendControl

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Application.vala'
--- src/Application.vala 2017-02-12 16:06:49 +0000
+++ src/Application.vala 2017-02-20 17:25:58 +0000
@@ -26,9 +26,11 @@
26 private const int SECONDS_AFTER_NETWORK_UP = 60;26 private const int SECONDS_AFTER_NETWORK_UP = 60;
2727
28 private static string? link = null;28 private static string? link = null;
29 private static uint inhibit_cookie = 0;
2930
30 public static bool show_updates;31 public static bool show_updates;
31 public static bool silent;32 public static bool silent;
33
32 MainWindow main_window;34 MainWindow main_window;
33 construct {35 construct {
34 application_id = "org.pantheon.appcenter";36 application_id = "org.pantheon.appcenter";
@@ -78,6 +80,23 @@
78 add_accelerator ("<Control>q", "app.quit", null);80 add_accelerator ("<Control>q", "app.quit", null);
79 }81 }
8082
83 public void inhibit_session () {
84 if (inhibit_cookie != 0) {
85 return;
86 }
87
88 inhibit_cookie = inhibit (main_window, Gtk.ApplicationInhibitFlags.SUSPEND, "Inhibit suspend during update");
89 }
90
91 public void uninhibit_session () {
92 if (inhibit_cookie == 0) {
93 return;
94 }
95
96 uninhibit (inhibit_cookie);
97 inhibit_cookie = 0;
98 }
99
81 public override void open (File[] files, string hint) {100 public override void open (File[] files, string hint) {
82 var file = files[0];101 var file = files[0];
83 if (file == null) {102 if (file == null) {
84103
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2017-02-10 20:15:32 +0000
+++ src/CMakeLists.txt 2017-02-20 17:25:58 +0000
@@ -7,7 +7,6 @@
7 Application.vala7 Application.vala
8 MainWindow.vala8 MainWindow.vala
9 Settings.vala9 Settings.vala
10 SuspendControl.vala
11 AbstractAppContainer.vala10 AbstractAppContainer.vala
12 AbstractAppList.vala11 AbstractAppList.vala
13 Views/AppInfoView.vala12 Views/AppInfoView.vala
1413
=== modified file 'src/Core/Client.vala'
--- src/Core/Client.vala 2017-02-04 17:18:30 +0000
+++ src/Core/Client.vala 2017-02-20 17:25:58 +0000
@@ -34,7 +34,6 @@
34 private const int SECONDS_BETWEEN_REFRESHES = 60*60*24;34 private const int SECONDS_BETWEEN_REFRESHES = 60*60*24;
3535
36 private Task client;36 private Task client;
37 private SuspendControl sc;
3837
39 private Client () {38 private Client () {
40 }39 }
@@ -44,7 +43,6 @@
44 cancellable = new GLib.Cancellable ();43 cancellable = new GLib.Cancellable ();
4544
46 client = new Task ();45 client = new Task ();
47 sc = new SuspendControl ();
4846
49 cancellable = new GLib.Cancellable ();47 cancellable = new GLib.Cancellable ();
50 last_cache_update = null;48 last_cache_update = null;
@@ -128,8 +126,10 @@
128 126
129 packages_ids += null;127 packages_ids += null;
130128
129 var application = (AppCenter.App)Application.get_default ();
130
131 try {131 try {
132 sc.inhibit ();132 application.inhibit_session ();
133133
134 var results = yield client.update_packages_async (packages_ids, cancellable, cb);134 var results = yield client.update_packages_async (packages_ids, cancellable, cb);
135 exit_status = results.get_exit_code ();135 exit_status = results.get_exit_code ();
@@ -137,7 +137,7 @@
137 task_count--;137 task_count--;
138 throw e;138 throw e;
139 } finally {139 } finally {
140 sc.uninhibit ();140 application.uninhibit_session ();
141 }141 }
142142
143 if (exit_status != Pk.Exit.SUCCESS) {143 if (exit_status != Pk.Exit.SUCCESS) {
144144
=== removed file 'src/SuspendControl.vala'
--- src/SuspendControl.vala 2016-01-30 16:44:48 +0000
+++ src/SuspendControl.vala 1970-01-01 00:00:00 +0000
@@ -1,71 +0,0 @@
1/*
2* Copyright (c) 2011-2015 elementary LLC (https://elementary.io)
3*
4* This program is free software; you can redistribute it and/or
5* modify it under the terms of the GNU General Public
6* License as published by the Free Software Foundation; either
7* version 2 of the License, or (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12* General Public License for more details.
13*
14* You should have received a copy of the GNU General Public
15* License along with this program; if not, write to the
16* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17* Boston, MA 02111-1307, USA.
18*
19* Authored by: Richard Fairthorne <richard.fairthorne@gmail.com>
20*/
21
22[DBus (name = "org.gnome.SessionManager")]
23public interface SessionManager : Object {
24 public abstract uint32 inhibit (string app_id, uint32 toplevel_xid, string reason, uint32 flags) throws IOError;
25 public abstract void uninhibit (uint32 inhibit_cookie) throws IOError;
26}
27
28public class SuspendControl {
29
30 SessionManager sm;
31 bool inhibited = false;
32 uint32 inhibit_cookie = 0;
33 bool supported = true;
34
35 public SuspendControl () {
36 try {
37 sm = Bus.get_proxy_sync (BusType.SESSION, "org.gnome.SessionManager", "/org/gnome/SessionManager");
38 } catch (IOError e) {
39 supported = false;
40 critical (e.message);
41 }
42 }
43
44 public bool inhibit () {
45 if (inhibited == false && supported) {
46 try {
47 inhibit_cookie = sm.inhibit ("org.richardfairthorne.SuspendControl", 0, "Inhibit suspend during update", 4);
48 inhibited = true;
49 } catch (IOError e) {
50 critical (e.message);
51 }
52 }
53
54 return inhibited;
55 }
56
57 public bool uninhibit () {
58 try {
59 if (inhibited == true && supported) {
60 sm.uninhibit (inhibit_cookie);
61 inhibited = false;
62 }
63 } catch (IOError e) {
64 critical (e.message);
65 }
66
67 return !inhibited;
68 }
69
70}
71
720
=== modified file 'src/Views/AppListView.vala'
--- src/Views/AppListView.vala 2017-02-15 18:02:21 +0000
+++ src/Views/AppListView.vala 2017-02-20 17:25:58 +0000
@@ -95,7 +95,6 @@
95 private uint apps_done = 0;95 private uint apps_done = 0;
96 private Gee.LinkedList<AppCenterCore.Package> apps_to_update;96 private Gee.LinkedList<AppCenterCore.Package> apps_to_update;
97 private AppCenterCore.Package first_package;97 private AppCenterCore.Package first_package;
98 private SuspendControl sc;
9998
100 private bool _updating_cache;99 private bool _updating_cache;
101 public bool updating_cache {100 public bool updating_cache {
@@ -129,8 +128,6 @@
129128
130 update_mutex = GLib.Mutex ();129 update_mutex = GLib.Mutex ();
131 apps_to_update = new Gee.LinkedList<AppCenterCore.Package> ();130 apps_to_update = new Gee.LinkedList<AppCenterCore.Package> ();
132
133 sc = new SuspendControl ();
134 }131 }
135132
136 public AppListUpdateView () {133 public AppListUpdateView () {
@@ -203,7 +200,8 @@
203 // Update all updateable apps200 // Update all updateable apps
204 if (apps_to_update.size > 0) {201 if (apps_to_update.size > 0) {
205 // Prevent computer from sleeping while updating apps202 // Prevent computer from sleeping while updating apps
206 sc.inhibit ();203 var application = (AppCenter.App)Application.get_default ();
204 application.inhibit_session ();
207205
208 first_package = apps_to_update[0];206 first_package = apps_to_update[0];
209 first_package.info_changed.connect_after (after_first_package_info_changed);207 first_package.info_changed.connect_after (after_first_package_info_changed);
@@ -254,7 +252,9 @@
254 assert (updating_all_apps && packages_changing == 0);252 assert (updating_all_apps && packages_changing == 0);
255253
256 updating_all_apps = false;254 updating_all_apps = false;
257 sc.uninhibit ();255
256 var application = (AppCenter.App)Application.get_default ();
257 application.uninhibit_session ();
258258
259 /* Set the action button sensitive and emit "changed" on each row in order to update259 /* Set the action button sensitive and emit "changed" on each row in order to update
260 * the sort order and headers (any change would have been ignored while updating) */ 260 * the sort order and headers (any change would have been ignored while updating) */

Subscribers

People subscribed via source and target branches