From 0f581e5e0f29a2cffbf72e52bb815d1380498110 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Wed, 21 Oct 2015 16:46:04 +0200 Subject: [PATCH] Fix plugin Game Center and Google Play Games plugin conflict --- src/inapps/cocoon-inapps/runtime.js | 2 +- src/share/cocoon-share/runtime.js | 3 +++ src/social/cocoon-gc/runtime.js | 11 +++++------ src/social/cocoon-gpg/runtime.js | 10 ++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/inapps/cocoon-inapps/runtime.js b/src/inapps/cocoon-inapps/runtime.js index 7f1a262..de0ede6 100755 --- a/src/inapps/cocoon-inapps/runtime.js +++ b/src/inapps/cocoon-inapps/runtime.js @@ -39,7 +39,7 @@ cr.plugins_.ATPInApps = function(runtime) { if (!(this.runtime.isAndroid || this.runtime.isiOS)) return; - if (typeof Cocoon == 'undefined') + if (!window.Cocoon) return; this.storeService = Cocoon.InApp; diff --git a/src/share/cocoon-share/runtime.js b/src/share/cocoon-share/runtime.js index 982ad85..b62820b 100755 --- a/src/share/cocoon-share/runtime.js +++ b/src/share/cocoon-share/runtime.js @@ -56,6 +56,9 @@ cr.plugins_.ATPShare = function(runtime) { // banner actions Acts.prototype.Share = function(text, img) { + if (!window.Cocoon || !window.Cocoon.Share) { + return; + } Cocoon.Share.share({ message: text, image: img diff --git a/src/social/cocoon-gc/runtime.js b/src/social/cocoon-gc/runtime.js index ca3fc58..48a1dad 100755 --- a/src/social/cocoon-gc/runtime.js +++ b/src/social/cocoon-gc/runtime.js @@ -30,7 +30,7 @@ cr.plugins_.ATPGameCenter = function(runtime) { instanceProto.onCreate = function() { - if (!(this.runtime.isAndroid || this.runtime.isiOS)) + if (!this.runtime.isiOS) return; if (typeof Cocoon == 'undefined') return; @@ -42,12 +42,11 @@ cr.plugins_.ATPGameCenter = function(runtime) { self = this; this.startGameCenter = function() { - this.GC = Cocoon.Social.GameCenter; + this.GC = window.Cocoon && window.Cocoon.Social ? Cocoon.Social.GameCenter : null; if (this.GC) { var config = {}; - if (!!this.GC.nativeAvailable) { - this.GCInterface = this.GC.getSocialInterface(); - } + this.GCInterface = this.GC.getSocialInterface(); + } else { throw new Error("Cannot find Game Center service, are you using the latest ATP for Game Center?"); } @@ -63,7 +62,7 @@ cr.plugins_.ATPGameCenter = function(runtime) { * Conditions */ Cnds.prototype.isLoggedIn = function() { - return this.GCInterface.isLoggedIn(); + return this.GCInterface ? this.GCInterface.isLoggedIn() : false; }; Cnds.prototype.onGCLoginSuccess = function() { return true; diff --git a/src/social/cocoon-gpg/runtime.js b/src/social/cocoon-gpg/runtime.js index 16a7300..d7f6cda 100755 --- a/src/social/cocoon-gpg/runtime.js +++ b/src/social/cocoon-gpg/runtime.js @@ -35,7 +35,7 @@ cr.plugins_.ATPGooglePlayGames = function(runtime) { instanceProto.onCreate = function() { - if (!(this.runtime.isAndroid || this.runtime.isiOS)) + if (!this.runtime.isAndroid) return; if (typeof Cocoon == 'undefined') return; @@ -47,14 +47,12 @@ cr.plugins_.ATPGooglePlayGames = function(runtime) { self = this; this.startGooglePlay = function() { - this.GPG = Cocoon.Social.GooglePlayGames; + this.GPG = window.Cocoon && window.Cocoon.Social ? Cocoon.Social.GooglePlayGames : null; if (this.GPG) { var config = {}; //if (this.GPGClientID) config.clientId = this.GPGClientID; this.GPG.init(config); - if (!!this.GPG.nativeAvailable) { - this.GPGInterface = this.GPG.getSocialInterface(); - } + this.GPGInterface = this.GPG.getSocialInterface(); } else { throw new Error("Cannot find Google Play Games service, are you using the latest ATP for Google Play Games?"); } @@ -70,7 +68,7 @@ cr.plugins_.ATPGooglePlayGames = function(runtime) { * Conditions */ Cnds.prototype.isLoggedIn = function() { - return this.GPGInterface.isLoggedIn(); + return this.GPGInterface ? this.GPGInterface.isLoggedIn() : false; }; Cnds.prototype.onGPGLoginSuccess = function() { return true;