Merge lp:~philip.scott/capnet-assist/capnet-app-uniqueness into lp:~elementary-apps/capnet-assist/trunk

Proposed by Felipe Escoto
Status: Merged
Approved by: Danielle Foré
Approved revision: 95
Merged at revision: 95
Proposed branch: lp:~philip.scott/capnet-assist/capnet-app-uniqueness
Merge into: lp:~elementary-apps/capnet-assist/trunk
Diff against target: 206 lines (+69/-31)
5 files modified
src/Application.vala (+49/-0)
src/CMakeLists.txt (+1/-0)
src/CaptiveLogin.vala (+16/-30)
src/config.vala (+2/-1)
src/config.vala.cmake (+1/-0)
To merge this branch: bzr merge lp:~philip.scott/capnet-assist/capnet-app-uniqueness
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+305257@code.launchpad.net

This proposal supersedes a proposal from 2016-09-08.

Commit message

Add Application Uniqueness

Description of the change

Prevent the capnet assist from launching twice

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote : Posted in a previous version of this proposal

I can confirm that this branch functions and ensures uniqueness. Some comments inline.

94. By Felipe Escoto

Add Application.vala

Revision history for this message
Danielle Foré (danrabbit) wrote :

One little bitesize typo :)

review: Needs Fixing
Revision history for this message
Leonardo Lemos (leonardolemos) wrote :

You missed the letter 'e' in the string 'elementary Developers' localed at Application.vala.

95. By Felipe Escoto

corrected typo on license

Revision history for this message
Danielle Foré (danrabbit) :
review: Approve
Revision history for this message
Danielle Foré (danrabbit) wrote :

Works for me :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/Application.vala'
2--- src/Application.vala 1970-01-01 00:00:00 +0000
3+++ src/Application.vala 2016-09-08 18:44:19 +0000
4@@ -0,0 +1,49 @@
5+/*
6+* Copyright (c) 2016 elementary LLC (https://launchpad.net/capnet-assist)
7+*
8+* This program is free software; you can redistribute it and/or
9+* modify it under the terms of the GNU General Public
10+* License as published by the Free Software Foundation; either
11+* version 2 of the License, or (at your option) any later version.
12+*
13+* This program is distributed in the hope that it will be useful,
14+* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+* General Public License for more details.
17+*
18+* You should have received a copy of the GNU General Public
19+* License along with this program; if not, write to the
20+* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21+* Boston, MA 02111-1307, USA.
22+*/
23+
24+public class Captive.Application : Gtk.Application {
25+
26+ public Application () {
27+ Object (application_id: "org.pantheon.captive-login");
28+ }
29+
30+ public override void activate () {
31+ if (!is_busy) {
32+ mark_busy ();
33+
34+ var browser = new ValaBrowser (this);
35+ if (browser.is_captive_portal ()) {
36+ debug ("Opening browser to login");
37+ browser.start ();
38+ } else {
39+ debug ("Already logged in and connected, or no internet connection. Shutting down.");
40+ quit ();
41+ }
42+ }
43+ }
44+
45+ public static int main (string[] args) {
46+ Environment.set_application_name (Constants.APP_NAME);
47+ Environment.set_prgname (Constants.APP_NAME);
48+
49+ var application = new Captive.Application ();
50+
51+ return application.run (args);
52+ }
53+}
54
55=== modified file 'src/CMakeLists.txt'
56--- src/CMakeLists.txt 2016-08-28 16:08:41 +0000
57+++ src/CMakeLists.txt 2016-09-08 18:44:19 +0000
58@@ -37,6 +37,7 @@
59 vala_precompile(VALA_C
60 config.vala
61 CaptiveLogin.vala
62+ Application.vala
63 PACKAGES
64 ${CAPTIVE_LOGIN_PACKAGES}
65 OPTIONS
66
67=== modified file 'src/CaptiveLogin.vala'
68--- src/CaptiveLogin.vala 2016-09-08 17:56:23 +0000
69+++ src/CaptiveLogin.vala 2016-09-08 18:44:19 +0000
70@@ -17,7 +17,7 @@
71 END LICENSE
72 ***/
73
74-public class ValaBrowser : Gtk.Window {
75+public class ValaBrowser : Gtk.ApplicationWindow {
76
77 private enum ViewSecurity {
78 NONE,
79@@ -28,14 +28,16 @@
80
81 private const string TITLE = _("Log in");
82 private const string DUMMY_URL = "http://elementary.io/capnet-assist";
83-
84+
85 private WebKit.WebView web_view;
86 private Gtk.ToggleButton tls_button;
87 private Gtk.Label title_label;
88
89 private ViewSecurity view_security = ViewSecurity.NONE;
90-
91- public ValaBrowser () {
92+
93+ public ValaBrowser (Gtk.Application app) {
94+ Object (application: app);
95+
96 set_default_size (1000, 680);
97 set_keep_above (true);
98 set_skip_taskbar_hint (true);
99@@ -48,7 +50,7 @@
100
101 bool is_privacy_mode_enabled () {
102 var privacy_settings = new GLib.Settings ("org.gnome.desktop.privacy");
103- bool privacy_mode = !privacy_settings.get_boolean ("remember-recent-files") ||
104+ bool privacy_mode = !privacy_settings.get_boolean ("remember-recent-files") ||
105 !privacy_settings.get_boolean ("remember-app-usage");
106 return privacy_mode;
107 }
108@@ -101,7 +103,7 @@
109
110 add (web_view);
111 }
112-
113+
114 public bool is_captive_portal () {
115 var network_monitor = NetworkMonitor.get_default ();
116
117@@ -120,14 +122,14 @@
118 session.send_message (message);
119
120 debug ("Return code: %u", message.status_code);
121-
122+
123 /*
124- * If there is an active connection to the internet, this will
125- * successfully connect to the connectivity checker and return 204.
126+ * If there is an active connection to the internet, this will
127+ * successfully connect to the connectivity checker and return 204.
128 * If there is no internet connection (including no captive portal), this
129- * request will fail and libsoup will return a transport failure status
130+ * request will fail and libsoup will return a transport failure status
131 * code (<100).
132- * Otherwise, libsoup will resolve the redirect to the captive portal,
133+ * Otherwise, libsoup will resolve the redirect to the captive portal,
134 * which will return status code 200.
135 */
136 return message.status_code == 200;
137@@ -245,7 +247,7 @@
138 grid.attach (primary_text, 1, 0, 1, 1);
139 grid.attach (secondary_text, 1, 1, 1, 1);
140 grid.attach (cert_details, 1, 2, 1, 1);
141-
142+
143 popover.add (grid);
144
145 // This hack has been borrowed from midori, the widget provided by the
146@@ -284,7 +286,7 @@
147 }
148
149 private void connect_signals () {
150- this.destroy.connect (Gtk.main_quit);
151+ this.destroy.connect (application.quit);
152 tls_button.toggled.connect (on_tls_button_click);
153 //should title change?
154 web_view.notify["title"].connect ((view, param_spec) => {
155@@ -324,7 +326,7 @@
156 return true;
157 }
158
159- Gtk.main_quit ();
160+ application.quit ();
161 return true;
162 });
163 }
164@@ -333,20 +335,4 @@
165 show_all ();
166 web_view.load_uri (ValaBrowser.DUMMY_URL);
167 }
168-
169- public static int main (string[] args) {
170- Gtk.init (ref args);
171-
172- var browser = new ValaBrowser ();
173-
174- if (browser.is_captive_portal ()) {
175- debug ("Opening browser to login");
176- browser.start ();
177- Gtk.main ();
178- } else {
179- debug ("Already logged in and connected, or no internet connection. Shutting down.");
180- }
181-
182- return 0;
183- }
184 }
185
186=== modified file 'src/config.vala'
187--- src/config.vala 2015-10-21 12:51:28 +0000
188+++ src/config.vala 2016-09-08 18:44:19 +0000
189@@ -15,5 +15,6 @@
190 */
191
192 namespace Constants {
193- public const string VERSION = "0.1.1";
194+ public const string VERSION = "0.2";
195+ public const string APP_NAME = "captive-login";
196 }
197
198=== modified file 'src/config.vala.cmake'
199--- src/config.vala.cmake 2013-08-22 15:09:15 +0000
200+++ src/config.vala.cmake 2016-09-08 18:44:19 +0000
201@@ -16,4 +16,5 @@
202
203 namespace Constants {
204 public const string VERSION = "@VERSION@";
205+ public const string APP_NAME = "@CMAKE_PROJECT_NAME@";
206 }

Subscribers

People subscribed via source and target branches

to all changes: