From d7e111fb710c63c32ff21c15b6cb5c67ed6280cc Mon Sep 17 00:00:00 2001 From: riknoll Date: Wed, 3 Feb 2016 13:12:21 -0800 Subject: [PATCH] CB-10498: Resume event should be sticky if it has a plugin result --- bin/templates/project/assets/www/cordova.js | 38 ++++++++++++++++----- cordova-js-src/platform.js | 20 +++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/bin/templates/project/assets/www/cordova.js b/bin/templates/project/assets/www/cordova.js index a4d73b396..581970c43 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 +})(); diff --git a/cordova-js-src/platform.js b/cordova-js-src/platform.js index 0706a348b..2bfd02471 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;