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
1=== modified file 'src/Application.vala'
2--- src/Application.vala 2017-02-12 16:06:49 +0000
3+++ src/Application.vala 2017-02-20 17:25:58 +0000
4@@ -26,9 +26,11 @@
5 private const int SECONDS_AFTER_NETWORK_UP = 60;
6
7 private static string? link = null;
8+ private static uint inhibit_cookie = 0;
9
10 public static bool show_updates;
11 public static bool silent;
12+
13 MainWindow main_window;
14 construct {
15 application_id = "org.pantheon.appcenter";
16@@ -78,6 +80,23 @@
17 add_accelerator ("<Control>q", "app.quit", null);
18 }
19
20+ public void inhibit_session () {
21+ if (inhibit_cookie != 0) {
22+ return;
23+ }
24+
25+ inhibit_cookie = inhibit (main_window, Gtk.ApplicationInhibitFlags.SUSPEND, "Inhibit suspend during update");
26+ }
27+
28+ public void uninhibit_session () {
29+ if (inhibit_cookie == 0) {
30+ return;
31+ }
32+
33+ uninhibit (inhibit_cookie);
34+ inhibit_cookie = 0;
35+ }
36+
37 public override void open (File[] files, string hint) {
38 var file = files[0];
39 if (file == null) {
40
41=== modified file 'src/CMakeLists.txt'
42--- src/CMakeLists.txt 2017-02-10 20:15:32 +0000
43+++ src/CMakeLists.txt 2017-02-20 17:25:58 +0000
44@@ -7,7 +7,6 @@
45 Application.vala
46 MainWindow.vala
47 Settings.vala
48- SuspendControl.vala
49 AbstractAppContainer.vala
50 AbstractAppList.vala
51 Views/AppInfoView.vala
52
53=== modified file 'src/Core/Client.vala'
54--- src/Core/Client.vala 2017-02-04 17:18:30 +0000
55+++ src/Core/Client.vala 2017-02-20 17:25:58 +0000
56@@ -34,7 +34,6 @@
57 private const int SECONDS_BETWEEN_REFRESHES = 60*60*24;
58
59 private Task client;
60- private SuspendControl sc;
61
62 private Client () {
63 }
64@@ -44,7 +43,6 @@
65 cancellable = new GLib.Cancellable ();
66
67 client = new Task ();
68- sc = new SuspendControl ();
69
70 cancellable = new GLib.Cancellable ();
71 last_cache_update = null;
72@@ -128,8 +126,10 @@
73
74 packages_ids += null;
75
76+ var application = (AppCenter.App)Application.get_default ();
77+
78 try {
79- sc.inhibit ();
80+ application.inhibit_session ();
81
82 var results = yield client.update_packages_async (packages_ids, cancellable, cb);
83 exit_status = results.get_exit_code ();
84@@ -137,7 +137,7 @@
85 task_count--;
86 throw e;
87 } finally {
88- sc.uninhibit ();
89+ application.uninhibit_session ();
90 }
91
92 if (exit_status != Pk.Exit.SUCCESS) {
93
94=== removed file 'src/SuspendControl.vala'
95--- src/SuspendControl.vala 2016-01-30 16:44:48 +0000
96+++ src/SuspendControl.vala 1970-01-01 00:00:00 +0000
97@@ -1,71 +0,0 @@
98-/*
99-* Copyright (c) 2011-2015 elementary LLC (https://elementary.io)
100-*
101-* This program is free software; you can redistribute it and/or
102-* modify it under the terms of the GNU General Public
103-* License as published by the Free Software Foundation; either
104-* version 2 of the License, or (at your option) any later version.
105-*
106-* This program is distributed in the hope that it will be useful,
107-* but WITHOUT ANY WARRANTY; without even the implied warranty of
108-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
109-* General Public License for more details.
110-*
111-* You should have received a copy of the GNU General Public
112-* License along with this program; if not, write to the
113-* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
114-* Boston, MA 02111-1307, USA.
115-*
116-* Authored by: Richard Fairthorne <richard.fairthorne@gmail.com>
117-*/
118-
119-[DBus (name = "org.gnome.SessionManager")]
120-public interface SessionManager : Object {
121- public abstract uint32 inhibit (string app_id, uint32 toplevel_xid, string reason, uint32 flags) throws IOError;
122- public abstract void uninhibit (uint32 inhibit_cookie) throws IOError;
123-}
124-
125-public class SuspendControl {
126-
127- SessionManager sm;
128- bool inhibited = false;
129- uint32 inhibit_cookie = 0;
130- bool supported = true;
131-
132- public SuspendControl () {
133- try {
134- sm = Bus.get_proxy_sync (BusType.SESSION, "org.gnome.SessionManager", "/org/gnome/SessionManager");
135- } catch (IOError e) {
136- supported = false;
137- critical (e.message);
138- }
139- }
140-
141- public bool inhibit () {
142- if (inhibited == false && supported) {
143- try {
144- inhibit_cookie = sm.inhibit ("org.richardfairthorne.SuspendControl", 0, "Inhibit suspend during update", 4);
145- inhibited = true;
146- } catch (IOError e) {
147- critical (e.message);
148- }
149- }
150-
151- return inhibited;
152- }
153-
154- public bool uninhibit () {
155- try {
156- if (inhibited == true && supported) {
157- sm.uninhibit (inhibit_cookie);
158- inhibited = false;
159- }
160- } catch (IOError e) {
161- critical (e.message);
162- }
163-
164- return !inhibited;
165- }
166-
167-}
168-
169
170=== modified file 'src/Views/AppListView.vala'
171--- src/Views/AppListView.vala 2017-02-15 18:02:21 +0000
172+++ src/Views/AppListView.vala 2017-02-20 17:25:58 +0000
173@@ -95,7 +95,6 @@
174 private uint apps_done = 0;
175 private Gee.LinkedList<AppCenterCore.Package> apps_to_update;
176 private AppCenterCore.Package first_package;
177- private SuspendControl sc;
178
179 private bool _updating_cache;
180 public bool updating_cache {
181@@ -129,8 +128,6 @@
182
183 update_mutex = GLib.Mutex ();
184 apps_to_update = new Gee.LinkedList<AppCenterCore.Package> ();
185-
186- sc = new SuspendControl ();
187 }
188
189 public AppListUpdateView () {
190@@ -203,7 +200,8 @@
191 // Update all updateable apps
192 if (apps_to_update.size > 0) {
193 // Prevent computer from sleeping while updating apps
194- sc.inhibit ();
195+ var application = (AppCenter.App)Application.get_default ();
196+ application.inhibit_session ();
197
198 first_package = apps_to_update[0];
199 first_package.info_changed.connect_after (after_first_package_info_changed);
200@@ -254,7 +252,9 @@
201 assert (updating_all_apps && packages_changing == 0);
202
203 updating_all_apps = false;
204- sc.uninhibit ();
205+
206+ var application = (AppCenter.App)Application.get_default ();
207+ application.uninhibit_session ();
208
209 /* Set the action button sensitive and emit "changed" on each row in order to update
210 * the sort order and headers (any change would have been ignored while updating) */

Subscribers

People subscribed via source and target branches