Merge lp:~matzipan/capnet-assist/no-internet-fix into lp:~elementary-apps/capnet-assist/trunk

Proposed by Zisu Andrei
Status: Merged
Approved by: Cody Garver
Approved revision: 76
Merged at revision: 78
Proposed branch: lp:~matzipan/capnet-assist/no-internet-fix
Merge into: lp:~elementary-apps/capnet-assist/trunk
Diff against target: 61 lines (+17/-8)
1 file modified
src/CaptiveLogin.vala (+17/-8)
To merge this branch: bzr merge lp:~matzipan/capnet-assist/no-internet-fix
Reviewer Review Type Date Requested Status
Zisu Andrei (community) test Approve
Review via email: mp+300306@code.launchpad.net

Commit message

Fix assistant triggering on connections without internet

Description of the change

Before, if the network connection had no internet, soup would try and fetch the URL and it would timeout after about 10-15 seconds, returning a status code of 2. Because if the comparison in the isLoggedIn method, this returned false, so the captive portal would trigger even if there was no internet connection.

This MR also prevents the captive portal from closing when connection is acquired, as sometimes there is valuable information displayed there (including download links)

To post a comment you must log in.
77. By Zisu Andrei

Change the assistant to use epiphany cookie store

Revision history for this message
Zisu Andrei (matzipan) wrote :

To test, unplug the internet connection from your router, and toggle the connection off and back on, the unpatched captive portal should kick-in after about 15 seconds. The patch version should not do that.

Revision history for this message
Cody Garver (codygarver) wrote :

When I join a captive network that is already known, the window appears then closes instantly. Because it has nothing to do?

Revision history for this message
Zisu Andrei (matzipan) wrote :

That's odd, since my branch actually removes the "Gtk.main_quit ();" on line 41, which was causing flickers.

Are you sure you installed correctly?

Revision history for this message
Cody Garver (codygarver) wrote :

Maybe it's because you are not performing the login check anymore before starting the browser? It's launching for any captive network you join, regardless of your previous history with the network.

Revision history for this message
Zisu Andrei (matzipan) wrote :

I am failing to see how the previous code took into account "history" either.

The check is still performed on line 52:
  if (browser.is_captive_portal ()) {

When you join a network, it will check if it can connect to the android URL.

If it is in a captive network and the captive portal triggers, then it will get redirected to the captive portal and soup will return the 200 status code, which means is_captive_portal will return true.

If it is in a captive network and the captive portal does not trigger (which I assume is the previously known network you're reffering to), then it means it will connect to the android connectivity checker URL, so soup will return the 204 status code, in which case is_captive_portal will return false - so the window won't even open in the first place.

It you are in a network without internet connection, before, soup would've returned status code 2, which meant that the assistant's window launched, but there was no website to display, since status code 2 means something along the lines of "connection timeout". After my changes, soup returning status 2 is ignored and is_captive_portal returns false.

Revision history for this message
Zisu Andrei (matzipan) wrote :

Hey Cody,

So it seems, on my end, that it happens when the web_view.load_failed gets fired, which in turn seems to call Gtk.main_quit ();

Please advise if this is the case, if yes then this is not an issue with my branch. I will come with another merge request with improvements for network failures.

78. By Zisu Andrei

Implement retries to increase the chance of success

Revision history for this message
Zisu Andrei (matzipan) wrote :

Felipe said that this merge request does not introduce any regressions.

review: Approve (test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CaptiveLogin.vala'
2--- src/CaptiveLogin.vala 2016-02-18 01:19:52 +0000
3+++ src/CaptiveLogin.vala 2016-07-18 10:54:04 +0000
4@@ -102,7 +102,7 @@
5 add (web_view);
6 }
7
8- public bool isLoggedIn () {
9+ public bool is_captive_portal () {
10 var network_monitor = NetworkMonitor.get_default ();
11
12 // No connection is available at the moment, don't bother trying the
13@@ -120,7 +120,17 @@
14 session.send_message (message);
15
16 debug ("Return code: %u", message.status_code);
17- return message.status_code == 204;
18+
19+ /*
20+ * If there is an active connection to the internet, this will
21+ * successfully connect to the connectivity checker and return 204.
22+ * If there is no internet connection (including no captive portal), this
23+ * request will fail and libsoup will return a transport failure status
24+ * code (<100).
25+ * Otherwise, libsoup will resolve the redirect to the captive portal,
26+ * which will return status code 200.
27+ */
28+ return message.status_code == 200;
29 }
30
31 private void update_tls_info () {
32@@ -279,11 +289,10 @@
33 web_view.load_changed.connect ((view, event) => {
34 switch (event) {
35 case WebKit.LoadEvent.FINISHED:
36- if (isLoggedIn ()) {
37+ if (is_captive_portal ()) {
38+ debug ("Still not logged in.");
39+ } else {
40 debug ("Logged in!");
41- Gtk.main_quit ();
42- } else {
43- debug ("Still not logged in.");
44 }
45 break;
46
47@@ -325,12 +334,12 @@
48
49 var browser = new ValaBrowser ();
50
51- if (!browser.isLoggedIn ()) {
52+ if (browser.is_captive_portal ()) {
53 debug ("Opening browser to login");
54 browser.start ();
55 Gtk.main ();
56 } else {
57- debug ("Already logged in and connected, shutting down.");
58+ debug ("Already logged in and connected, or no internet connection. Shutting down.");
59 }
60
61 return 0;

Subscribers

People subscribed via source and target branches

to all changes: