Skip to content

Commit

Permalink
Merge pull request arnesson#824 from kurtsergey/removed-init-remote-c…
Browse files Browse the repository at this point in the history
…onfig

Removed initRemoteConfig method
  • Loading branch information
soumak77 authored Sep 5, 2018
2 parents 3a28010 + 8c00811 commit 9939f3c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 102 deletions.
103 changes: 32 additions & 71 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ public class FirebasePlugin extends CordovaPlugin {
private final String ERRORINITFIREBASE = "Firebase isn't initialised";
private final String ERRORINITCRASHLYTICS = "Crashlytics isn't initialised";
private final String ERRORINITANALYTICS = "Analytics isn't initialised";
private final String ERRORINITREMOTECONFIG = "RemoteConfig isn't initialised";
private final String ERRORINITPERFORMANCE = "Performance isn't initialised";
protected static final String KEY = "badge";

private static boolean firebaseInit = false;
private static boolean crashlyticsInit = false;
private static boolean analyticsInit = false;
private static boolean remoteconfigInit = false;
private static boolean performanceInit = false;
private static boolean inBackground = true;
private static ArrayList<Bundle> notificationStack = null;
Expand Down Expand Up @@ -158,7 +156,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("setUserProperty")) {
this.setUserProperty(callbackContext, args.getString(0), args.getString(1));
return true;
} else if (action.equals("activateFetched") || action.equals("initRemoteConfig")) {
} else if (action.equals("activateFetched")) {
this.activateFetched(callbackContext);
return true;
} else if (action.equals("fetch")) {
Expand Down Expand Up @@ -403,10 +401,6 @@ public static boolean analyticsInit() {
return FirebasePlugin.analyticsInit;
}

public static boolean remoteconfigInit() {
return FirebasePlugin.remoteconfigInit;
}

public static boolean performanceInit() {
return FirebasePlugin.performanceInit;
}
Expand Down Expand Up @@ -713,13 +707,8 @@ private void activateFetched(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
if (!FirebasePlugin.remoteconfigInit()) {
final boolean activated = FirebaseRemoteConfig.getInstance().activateFetched();
FirebasePlugin.remoteconfigInit = true;
callbackContext.success(String.valueOf(activated));
} else {
callbackContext.error(String.valueOf(true));
}
} catch (Exception e) {
if(FirebasePlugin.crashlyticsInit()){
Crashlytics.logException(e);
Expand All @@ -731,19 +720,11 @@ public void run() {
}

private void fetch(CallbackContext callbackContext) {
if (FirebasePlugin.remoteconfigInit()) {
fetch(callbackContext, FirebaseRemoteConfig.getInstance().fetch());
} else {
callbackContext.error(ERRORINITREMOTECONFIG);
}
fetch(callbackContext, FirebaseRemoteConfig.getInstance().fetch());
}

private void fetch(CallbackContext callbackContext, long cacheExpirationSeconds) {
if (FirebasePlugin.remoteconfigInit()) {
fetch(callbackContext, FirebaseRemoteConfig.getInstance().fetch(cacheExpirationSeconds));
} else {
callbackContext.error(ERRORINITREMOTECONFIG);
}
fetch(callbackContext, FirebaseRemoteConfig.getInstance().fetch(cacheExpirationSeconds));
}

private void fetch(final CallbackContext callbackContext, final Task<Void> task) {
Expand Down Expand Up @@ -775,53 +756,44 @@ public void onFailure(Exception e) {
}

private void getByteArray(final CallbackContext callbackContext, final String key, final String namespace) {
if (FirebasePlugin.remoteconfigInit()) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
byte[] bytes = namespace == null ? FirebaseRemoteConfig.getInstance().getByteArray(key)
: FirebaseRemoteConfig.getInstance().getByteArray(key, namespace);
JSONObject object = new JSONObject();
object.put("base64", Base64.encodeToString(bytes, Base64.DEFAULT));
object.put("array", new JSONArray(bytes));
callbackContext.success(object);
} catch (Exception e) {
if(FirebasePlugin.crashlyticsInit()){
Crashlytics.logException(e);
}
callbackContext.error(e.getMessage());
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
byte[] bytes = namespace == null ? FirebaseRemoteConfig.getInstance().getByteArray(key)
: FirebaseRemoteConfig.getInstance().getByteArray(key, namespace);
JSONObject object = new JSONObject();
object.put("base64", Base64.encodeToString(bytes, Base64.DEFAULT));
object.put("array", new JSONArray(bytes));
callbackContext.success(object);
} catch (Exception e) {
if(FirebasePlugin.crashlyticsInit()){
Crashlytics.logException(e);
}
callbackContext.error(e.getMessage());
}
});
} else {
callbackContext.error(ERRORINITREMOTECONFIG);
}
}
});
}

private void getValue(final CallbackContext callbackContext, final String key, final String namespace) {
if (FirebasePlugin.remoteconfigInit()) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
FirebaseRemoteConfigValue value = namespace == null
? FirebaseRemoteConfig.getInstance().getValue(key)
: FirebaseRemoteConfig.getInstance().getValue(key, namespace);
callbackContext.success(value.asString());
} catch (Exception e) {
if(FirebasePlugin.crashlyticsInit()){
Crashlytics.logException(e);
}
callbackContext.error(e.getMessage());
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
FirebaseRemoteConfigValue value = namespace == null
? FirebaseRemoteConfig.getInstance().getValue(key)
: FirebaseRemoteConfig.getInstance().getValue(key, namespace);
callbackContext.success(value.asString());
} catch (Exception e) {
if(FirebasePlugin.crashlyticsInit()){
Crashlytics.logException(e);
}
callbackContext.error(e.getMessage());
}
});
} else {
callbackContext.error(ERRORINITREMOTECONFIG);
}
}
});
}

private void getInfo(final CallbackContext callbackContext) {
if (FirebasePlugin.remoteconfigInit()) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
Expand All @@ -838,19 +810,15 @@ public void run() {
callbackContext.success(info);
} catch (Exception e) {
if(FirebasePlugin.crashlyticsInit()){
Crashlytics.logException(e);
Crashlytics.logException(e);
}
callbackContext.error(e.getMessage());
}
}
});
} else {
callbackContext.error(ERRORINITREMOTECONFIG);
}
}

private void setConfigSettings(final CallbackContext callbackContext, final JSONObject config) {
if (FirebasePlugin.remoteconfigInit()) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
Expand All @@ -867,13 +835,9 @@ public void run() {
}
}
});
} else {
callbackContext.error(ERRORINITREMOTECONFIG);
}
}

private void setDefaults(final CallbackContext callbackContext, final JSONObject defaults, final String namespace) {
if (FirebasePlugin.remoteconfigInit()) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
Expand All @@ -890,9 +854,6 @@ public void run() {
}
}
});
} else {
callbackContext.error(ERRORINITREMOTECONFIG);
}
}

private static Map<String, Object> defaultsToMap(JSONObject object) throws JSONException {
Expand Down
1 change: 0 additions & 1 deletion src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- (void)initCrashlytics:(CDVInvokedUrlCommand*)command;
- (void)initAnalytics:(CDVInvokedUrlCommand*)command;
- (void)initPerformance:(CDVInvokedUrlCommand*)command;
- (void)initRemoteConfig:(CDVInvokedUrlCommand*)command;
- (void)getVerificationID:(CDVInvokedUrlCommand*)command;
- (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command;
- (void)getInstanceId:(CDVInvokedUrlCommand*)command;
Expand Down
23 changes: 3 additions & 20 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ @implementation FirebasePlugin
@synthesize firebaseInit;
@synthesize crashlyticsInit;
@synthesize analyticsInit;
@synthesize remoteconfigInit;
@synthesize performanceInit;

static NSInteger const kNotificationStackSize = 10;
static NSString * const ERRORINITFIREBASE = @"Firebase isn't initialised";
static NSString * const ERRORINITCRASHLYTICS = @"Crashlytics isn't initialised";
static NSString * const ERRORINITANALYTICS = @"Analytics isn't initialised";
static NSString * const ERRORINITREMOTECONFIG = @"RemoteConfig isn't initialised";
static NSString * const ERRORINITPERFORMANCE = @"Performance isn't initialised";
static FirebasePlugin *firebasePlugin;

Expand All @@ -50,7 +48,6 @@ - (void)pluginInitialize {
self.firebaseInit = NO;
self.crashlyticsInit = NO;
self.analyticsInit = NO;
self.remoteconfigInit = NO;
self.performanceInit = NO;
}

Expand Down Expand Up @@ -118,10 +115,6 @@ - (void)initPerformance:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)initRemoteConfig:(CDVInvokedUrlCommand *)command {
[self activateFetched:command];
}

- (void)getId:(CDVInvokedUrlCommand *)command {
__block CDVPluginResult *pluginResult;

Expand Down Expand Up @@ -452,7 +445,6 @@ - (void)setUserProperty:(CDVInvokedUrlCommand *)command {

- (void)fetch:(CDVInvokedUrlCommand *)command {
[self.commandDelegate runInBackground:^{
if(self.remoteconfigInit){
FIRRemoteConfig* remoteConfig = [FIRRemoteConfig remoteConfig];

if ([command.arguments count] > 0) {
Expand All @@ -472,18 +464,13 @@ - (void)fetch:(CDVInvokedUrlCommand *)command {
}
}];
}
} else {
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:ERRORINITREMOTECONFIG];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}];
}

- (void)activateFetched:(CDVInvokedUrlCommand *)command {
[self.commandDelegate runInBackground:^{
FIRRemoteConfig* remoteConfig = [FIRRemoteConfig remoteConfig];
BOOL activated = [remoteConfig activateFetched];
self.remoteconfigInit = activated;
CDVPluginResult *pluginResult;

if (activated) {
Expand All @@ -501,13 +488,9 @@ - (void)getValue:(CDVInvokedUrlCommand *)command {
CDVPluginResult *pluginResult;
NSString* key = [command.arguments objectAtIndex:0];

if(self.remoteconfigInit){
FIRRemoteConfig* remoteConfig = [FIRRemoteConfig remoteConfig];
NSString* value = remoteConfig[key].stringValue;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:ERRORINITREMOTECONFIG];
}
FIRRemoteConfig* remoteConfig = [FIRRemoteConfig remoteConfig];
NSString* value = remoteConfig[key].stringValue;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:value];

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
Expand Down
6 changes: 0 additions & 6 deletions www/firebase-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ exports.initPerformance = function (success, error) {
}
};

exports.initRemoteConfig = function (success, error) {
if (typeof success === 'function') {
success();
}
};

exports.getVerificationID = function (number, success, error) {
if (typeof success === 'function') {
success();
Expand Down
4 changes: 0 additions & 4 deletions www/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ exports.initPerformance = function (success, error) {
exec(success, error, "FirebasePlugin", "initPerformance", []);
};

exports.initRemoteConfig = function (success, error) {
exec(success, error, "FirebasePlugin", "initRemoteConfig", []);
};

exports.getVerificationID = function (number, success, error) {
exec(success, error, "FirebasePlugin", "getVerificationID", [number]);
};
Expand Down

0 comments on commit 9939f3c

Please sign in to comment.