Skip to content
Prev Previous commit
Next Next commit
Improve setInterval hack
Replace setInterval show hack with setInterval exec hack. This will solve problems for other plugins as well.
  • Loading branch information
jperl committed Jun 20, 2014
commit 5dcacdde29a7deec3facce91f1632e0ec933007a
30 changes: 13 additions & 17 deletions patch_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// http://docs.phonegap.com/en/3.3.0/cordova_inappbrowser_inappbrowser.md.html
// https://github.com/zeroasterisk/MeteorRider
window.patchWindow = function () {

// Prevent the window from being patched twice.
if (window.IAB) return;

Expand All @@ -17,11 +16,20 @@ window.patchWindow = function () {
} catch (e) {
return false;
}


// Plugin messages are not called immediately.
// Call exec on an interval to force process messages.
// http://stackoverflow.com/q/23352940/230462 and
// http://stackoverflow.com/a/24319063/230462
if (device.platform === 'Android') {
setInterval(function () {
cordova.exec(null, null, '', '', [])
}, 200);
}

// Keep a reference to the in app browser's window.open.
var __open = window.open,
oauthWin,
timer;
oauthWin;

// Create an object to return from a monkeypatched window.open call. Handles
// open/closed state of popup to keep Meteor happy. Allows one to save window
Expand All @@ -40,16 +48,7 @@ window.patchWindow = function () {
// user goes back when there are not pages in the history.
oauthWin.addEventListener('exit', close);

// window.open event listeners do not fire in android
// as a work around use hidden=yes and constantly call show
// http://stackoverflow.com/q/23352940/230462
//
// XXX find a better way to do this
if (device.platform === 'Android') {
timer = setInterval(oauthWin.show, 200);
} else {
oauthWin.show();
}
oauthWin.show();

function close() {
// close the window
Expand Down Expand Up @@ -91,9 +90,6 @@ window.patchWindow = function () {

oauthWin.close();

// Clear the timer in IAB.close to prevent the window from reopening.
clearInterval(timer);

this.closed = true;
}
};
Expand Down