Repository: cordova-android
Updated Branches:
  refs/heads/master 2ac191fbb -> d7e111fb7


CB-10498: Resume event should be sticky if it has a plugin result


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

Branch: refs/heads/master
Commit: d7e111fb710c63c32ff21c15b6cb5c67ed6280cc
Parents: 2ac191f
Author: riknoll <[email protected]>
Authored: Wed Feb 3 13:12:21 2016 -0800
Committer: riknoll <[email protected]>
Committed: Wed Feb 3 13:25:56 2016 -0800

----------------------------------------------------------------------
 bin/templates/project/assets/www/cordova.js | 38 ++++++++++++++++++------
 cordova-js-src/platform.js                  | 20 +++++++++++++
 2 files changed, 49 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/d7e111fb/bin/templates/project/assets/www/cordova.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/assets/www/cordova.js 
b/bin/templates/project/assets/www/cordova.js
index a4d73b3..581970c 100644
--- a/bin/templates/project/assets/www/cordova.js
+++ b/bin/templates/project/assets/www/cordova.js
@@ -1,5 +1,5 @@
 // Platform: android
-// ded62dda172755defaf75378ed007dc05730ec22
+// 533e1bfdbc57d54106ca39a02b21a1909f84fda7
 /*
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
@@ -8,9 +8,9 @@
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
- 
+
      http://www.apache.org/licenses/LICENSE-2.0
- 
+
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -330,7 +330,7 @@ module.exports = cordova;
 
 });
 
-// file: 
/Users/steveng/repo/cordova/cordova-android/cordova-js-src/android/nativeapiprovider.js
+// file: cordova-android/cordova-js-src/android/nativeapiprovider.js
 define("cordova/android/nativeapiprovider", function(require, exports, module) 
{
 
 /**
@@ -353,7 +353,7 @@ module.exports = {
 
 });
 
-// file: 
/Users/steveng/repo/cordova/cordova-android/cordova-js-src/android/promptbasednativeapi.js
+// file: cordova-android/cordova-js-src/android/promptbasednativeapi.js
 define("cordova/android/promptbasednativeapi", function(require, exports, 
module) {
 
 /**
@@ -862,7 +862,7 @@ module.exports = channel;
 
 });
 
-// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/exec.js
+// file: cordova-android/cordova-js-src/exec.js
 define("cordova/exec", function(require, exports, module) {
 
 /**
@@ -1611,9 +1611,12 @@ exports.reset();
 
 });
 
-// file: /Users/steveng/repo/cordova/cordova-android/cordova-js-src/platform.js
+// file: cordova-android/cordova-js-src/platform.js
 define("cordova/platform", function(require, exports, module) {
 
+// The last resume event that was received that had the result of a plugin 
call.
+var lastResumeEvent = null;
+
 module.exports = {
     id: 'android',
     bootstrap: function() {
@@ -1653,6 +1656,19 @@ module.exports = {
         bindButtonChannel('volumeup');
         bindButtonChannel('volumedown');
 
+        // The resume event is not "sticky", but it is possible that the event
+        // will contain the result of a plugin call. We need to ensure that the
+        // plugin result is delivered even after the event is fired (CB-10498)
+        var cordovaAddEventListener = document.addEventListener;
+
+        document.addEventListener = function(evt, handler, capture) {
+            cordovaAddEventListener(evt, handler, capture);
+
+            if (evt === 'resume' && lastResumeEvent) {
+                handler(lastResumeEvent);
+            }
+        };
+
         // Let native code know we are all done on the JS side.
         // Native code will then un-hide the WebView.
         channel.onCordovaReady.subscribe(function() {
@@ -1691,6 +1707,10 @@ function onMessageFromNative(msg) {
                     }
                     msg.pendingResult.result = res;
                 }
+
+                // Save the plugin result so that it can be delivered to the js
+                // even if they miss the initial firing of the event
+                lastResumeEvent = msg;
             }
             cordova.fireDocumentEvent(action, msg);
             break;
@@ -1701,7 +1721,7 @@ function onMessageFromNative(msg) {
 
 });
 
-// file: 
/Users/steveng/repo/cordova/cordova-android/cordova-js-src/plugin/android/app.js
+// file: cordova-android/cordova-js-src/plugin/android/app.js
 define("cordova/plugin/android/app", function(require, exports, module) {
 
 var exec = require('cordova/exec');
@@ -2144,4 +2164,4 @@ window.cordova = require('cordova');
 
 require('cordova/init');
 
-})();
\ No newline at end of file
+})();

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/d7e111fb/cordova-js-src/platform.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/platform.js b/cordova-js-src/platform.js
index 0706a34..2bfd024 100644
--- a/cordova-js-src/platform.js
+++ b/cordova-js-src/platform.js
@@ -19,6 +19,9 @@
  *
 */
 
+// The last resume event that was received that had the result of a plugin 
call.
+var lastResumeEvent = null;
+
 module.exports = {
     id: 'android',
     bootstrap: function() {
@@ -58,6 +61,19 @@ module.exports = {
         bindButtonChannel('volumeup');
         bindButtonChannel('volumedown');
 
+        // The resume event is not "sticky", but it is possible that the event
+        // will contain the result of a plugin call. We need to ensure that the
+        // plugin result is delivered even after the event is fired (CB-10498)
+        var cordovaAddEventListener = document.addEventListener;
+
+        document.addEventListener = function(evt, handler, capture) {
+            cordovaAddEventListener(evt, handler, capture);
+
+            if (evt === 'resume' && lastResumeEvent) {
+                handler(lastResumeEvent);
+            }
+        };
+
         // Let native code know we are all done on the JS side.
         // Native code will then un-hide the WebView.
         channel.onCordovaReady.subscribe(function() {
@@ -96,6 +112,10 @@ function onMessageFromNative(msg) {
                     }
                     msg.pendingResult.result = res;
                 }
+
+                // Save the plugin result so that it can be delivered to the js
+                // even if they miss the initial firing of the event
+                lastResumeEvent = msg;
             }
             cordova.fireDocumentEvent(action, msg);
             break;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to