Allow the binary version to be specified independently of the app version

This commit is contained in:
Richard Hua
2016-08-01 17:02:12 -07:00
parent 12efdb0a85
commit 1a1004ee8b
4 changed files with 31 additions and 9 deletions

View File

@@ -29,6 +29,7 @@ public class CodePush implements ReactPackage {
private static boolean sIsRunningBinaryVersion = false;
private static boolean sNeedToReportRollback = false;
private static boolean sTestConfigurationFlag = false;
private static String sAppVersionOverride = null;
private boolean mDidUpdate = false;
@@ -40,7 +41,7 @@ public class CodePush implements ReactPackage {
private SettingsManager mSettingsManager;
// Config properties.
private String mAppVersion;
private String mPListAppVersion;
private String mDeploymentKey;
private String mServerUrl = "https://codepush.azurewebsites.net/";
@@ -65,7 +66,7 @@ public class CodePush implements ReactPackage {
try {
PackageInfo pInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
mAppVersion = pInfo.versionName;
mPListAppVersion = pInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
throw new CodePushUnknownException("Unable to get package info for " + mContext.getPackageName(), e);
}
@@ -96,7 +97,7 @@ public class CodePush implements ReactPackage {
}
public String getAppVersion() {
return mAppVersion;
return sAppVersionOverride == null ? mPListAppVersion : sAppVersionOverride;
}
public String getAssetsBundleFileName() {
@@ -177,14 +178,14 @@ public class CodePush implements ReactPackage {
String packageAppVersion = CodePushUtils.tryGetString(packageMetadata, "appVersion");
if (binaryModifiedDateDuringPackageInstall != null &&
binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
(isUsingTestConfiguration() || this.mAppVersion.equals(packageAppVersion))) {
(isUsingTestConfiguration() || this.getAppVersion().equals(packageAppVersion))) {
CodePushUtils.logBundleUrl(packageFilePath);
sIsRunningBinaryVersion = false;
return packageFilePath;
} else {
// The binary version is newer.
this.mDidUpdate = false;
if (!this.mIsDebugMode || !this.mAppVersion.equals(packageAppVersion)) {
if (!this.mIsDebugMode || !this.getAppVersion().equals(packageAppVersion)) {
this.clearUpdates();
}
@@ -249,6 +250,10 @@ public class CodePush implements ReactPackage {
return sNeedToReportRollback;
}
public static void overrideAppVersion(String appVersionOverride) {
sAppVersionOverride = appVersionOverride;
}
private void rollbackPackage() {
WritableMap failedPackage = mUpdateManager.getCurrentPackage();
mSettingsManager.saveFailedUpdate(failedPackage);
@@ -280,7 +285,7 @@ public class CodePush implements ReactPackage {
CodePushNativeModule codePushModule = new CodePushNativeModule(reactApplicationContext, this, mUpdateManager, mTelemetryManager, mSettingsManager);
CodePushDialog dialogModule = new CodePushDialog(reactApplicationContext);
List<NativeModule> nativeModules = new ArrayList<>();
List<NativeModule> nativeModules = new ArrayList<>();
nativeModules.add(codePushModule);
nativeModules.add(dialogModule);
return nativeModules;

View File

@@ -30,7 +30,14 @@
+ (NSString *)bundleAssetsPath;
/*
* This methods allows dynamically setting the app's
* This method allows the version of the app's binary interface
* to be specified, which would otherwise default to the
* App Store version of the app.
*/
+ (void)overrideAppVersion:(NSString *)deploymentKey;
/*
* This method allows dynamically setting the app's
* deployment key, in addition to setting it via
* the Info.plist file's CodePushDeploymentKey setting.
*/
@@ -45,7 +52,7 @@
@interface CodePushConfig : NSObject
@property (readonly) NSString *appVersion;
@property (copy) NSString *appVersion;
@property (readonly) NSString *buildVersion;
@property (readonly) NSDictionary *configuration;
@property (copy) NSString *deploymentKey;

View File

@@ -73,7 +73,7 @@ static NSString *bundleResourceSubdirectory = nil;
if (bundleResourceSubdirectory) {
resourcePath = [resourcePath stringByAppendingPathComponent:bundleResourceSubdirectory];
}
return [resourcePath stringByAppendingPathComponent:[CodePushUpdateUtils assetsFolderName]];
}
@@ -159,6 +159,11 @@ static NSString *bundleResourceSubdirectory = nil;
return applicationSupportDirectory;
}
+ (void)overrideAppVersion:(NSString *)appVersion
{
[CodePushConfig current].appVersion = appVersion;
}
+ (void)setDeploymentKey:(NSString *)deploymentKey
{
[CodePushConfig current].deploymentKey = deploymentKey;

View File

@@ -86,6 +86,11 @@ static NSString * const ServerURLConfigKey = @"serverUrl";
return [_configDictionary objectForKey:ClientUniqueIDConfigKey];
}
- (void)setAppVersion:(NSString *)appVersion
{
[_configDictionary setValue:appVersion forKey:AppVersionConfigKey];
}
- (void)setDeploymentKey:(NSString *)deploymentKey
{
[_configDictionary setValue:deploymentKey forKey:DeploymentKeyConfigKey];