Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
send build number in environment
  • Loading branch information
bleonard committed Oct 19, 2015
commit fa1aeecdeb2643e8f298c2eb20b34e6485d4cafa
4 changes: 3 additions & 1 deletion App/Mixins/AuthHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var Text = require('../Components/Text');
var Button = require('../Components/Button');
var TextInput = require('../Components/TextInput');

var EnvironmentStore = require('../Stores/EnvironmentStore');

var AuthHelper = {

// parent implements: onAuthButton, getDefaultProps
Expand Down Expand Up @@ -111,7 +113,7 @@ var AuthHelper = {
<View style={styles.bottom}>
{this.renderPassword()}
<View style={styles.flex} />
<Text style={[styles.bottomText, styles.version]}>TODO: v1</Text>
<Text style={[styles.bottomText, styles.version]}>Version {EnvironmentStore.get().displayVersion()}</Text>
</View>
</View>
)
Expand Down
25 changes: 24 additions & 1 deletion App/Models/Environment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assign = require('../Lib/assignDefined');
var jsVersion = require('../jsVersion');

var Model = function(options) {
this.data = {};
Expand All @@ -8,7 +9,11 @@ var Model = function(options) {
Model.prototype.setAttributes = function(options) {
options = (options || {});
assign(this.data, {
name: options.name
name: options.name,
simulator: options.simulator,
buildCode: parseInt(options.buildCode),
version: options.version,
locale: options.locale
});
};

Expand All @@ -18,9 +23,27 @@ Model.prototype.getApiHost = function() {
return 'http://localhost:3001';
case 'debug':
return 'http://localhost:3000';
case 'staging':
return 'https://someday.herokuapp.com';
default:
throw("Unknown Environment.getApiHost: " + this.data.name);
}
};

Model.prototype.combinedBuildCode = function() {
var ios = this.data.buildCode * 1000000;
return ios + jsVersion;
};

Model.prototype.displayVersion = function() {
var out = this.data.version;
out += "." + this.data.buildCode;
out += "." + jsVersion;
return out;
};

Model.prototype.getLocale = function() {
return this.data.locale;
};

module.exports = Model;
17 changes: 15 additions & 2 deletions App/Screens/Settings.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
var React = require('react-native');
var {
View,
StyleSheet
StyleSheet,
Text
} = React;

var cssVar = require('../Lib/cssVar');

var SimpleList = require('../Components/SimpleList');
var AppConstants = require('../Constants/AppConstants');

var EnvironmentStore = require('../Stores/EnvironmentStore');

function getListState() {
var list = [];
list.push({
Expand All @@ -28,6 +33,9 @@ var Settings = React.createClass({
return (
<View style={styles.container}>
<SimpleList currentRoute={this.props.currentRoute} items={this.state.items} />
<View style={styles.bottom}>
<Text style={styles.bottomText}>Version {EnvironmentStore.get().displayVersion()}</Text>
</View>
</View>
)
}
Expand All @@ -36,7 +44,12 @@ var Settings = React.createClass({
var styles = StyleSheet.create({
container: {
flex: 1
}
},
bottomText: {
padding: 10,
color: cssVar('gray20'),
fontSize: 12
},
});

module.exports = Settings;
6 changes: 3 additions & 3 deletions App/Stores/EnvironmentStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ var SingletonStore = assign({}, EventEmitter.prototype, {
Dispatcher.register(function(action) {
switch(action.actionType) {
case AppConstants.APP_LAUNCHED:
EnvironmentManager.get(function(name) {
console.log("Environment: " + name);
setSingleton({name: name});
EnvironmentManager.get(function(attributes) {
console.log("Environment: " + attributes.name);
setSingleton(attributes);
SingletonStore.emitChange();
});
break;
Expand Down
1 change: 1 addition & 0 deletions App/jsVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 2;
27 changes: 24 additions & 3 deletions ios/Sample/EnvironmentManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ @implementation EnvironmentManager

RCT_EXPORT_METHOD(get:(RCTResponseSenderBlock)callback)
{
//TODO: NSString * envName = kEnvironment;
NSString * envName = @"debug";
NSString *locale = [[NSLocale currentLocale] localeIdentifier];
locale = [locale stringByReplacingOccurrencesOfString:@"_" withString:@"-"];

NSNumber * simulator = @NO;
NSString * version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString * buildCode = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];

NSString * envName = kEnvironment;
NSDictionary *passed = [[NSProcessInfo processInfo] environment];
NSString *override = [passed valueForKey:@"SAMPLE_ENV"];
if (override) {
Expand All @@ -26,7 +32,22 @@ @implementation EnvironmentManager
#ifdef TEST_ENVIRONMENT
envName = @"test";
#endif
callback(@[envName]);
#ifdef STAGING_ENVIRONMENT
envName = @"staging";
#endif


#if TARGET_IPHONE_SIMULATOR
simulator = @YES;
#endif

callback(@[ @{
@"name": envName,
@"buildCode": buildCode,
@"simulator": simulator,
@"version": version,
@"locale": locale
}]);
}

@end