cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject android commit: CB-6761 Fix native->JS bridge ceasing to fire when page changes and online is set to false and the JS loads quickly
Date Thu, 03 Jul 2014 17:29:18 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master 6f21a9623 -> 445ddd89f


CB-6761 Fix native->JS bridge ceasing to fire when page changes and online is set to false
and the JS loads quickly


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/445ddd89
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/445ddd89
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/445ddd89

Branch: refs/heads/master
Commit: 445ddd89fb3269a772978a9860247065e5886249
Parents: 6f21a96
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Jul 3 13:27:30 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Jul 3 13:27:30 2014 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/NativeToJsMessageQueue.java | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/445ddd89/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
index 5d0c061..9f6f96e 100755
--- a/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
+++ b/framework/src/org/apache/cordova/NativeToJsMessageQueue.java
@@ -308,23 +308,28 @@ public class NativeToJsMessageQueue {
     /** Uses online/offline events to tell the JS when to poll for messages. */
     private class OnlineEventsBridgeMode extends BridgeMode {
         private boolean online;
-        final Runnable runnable = new Runnable() {
+        private boolean ignoreNextFlush;
+
+        final Runnable toggleNetworkRunnable = new Runnable() {
             public void run() {
                 if (!queue.isEmpty()) {
+                    ignoreNextFlush = false;
                     webView.setNetworkAvailable(online);
                 }
-            }                
+            }
         };
         @Override void reset() {
             online = false;
+            // If the following call triggers a notifyOfFlush, then ignore it.
+            ignoreNextFlush = true;
             webView.setNetworkAvailable(true);
         }
         @Override void onNativeToJsMessageAvailable() {
-            cordova.getActivity().runOnUiThread(runnable);
+            cordova.getActivity().runOnUiThread(toggleNetworkRunnable);
         }
         // Track when online/offline events are fired so that we don't fire excess events.
         @Override void notifyOfFlush(boolean fromOnlineEvent) {
-            if (fromOnlineEvent) {
+            if (fromOnlineEvent && !ignoreNextFlush) {
                 online = !online;
             }
         }


Mime
View raw message