This repository was archived by the owner on May 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Refactor plugin config, and change example so it can download updates #2
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b3a24a4
Make HybridMobileDeploy a dependency of the example app
e85b627
Update sdk reference to pull out AcquisitionManager
48d1d98
Fix update link for sample app
f72ab12
Refactor plugin and example based on new design
06e7d8b
Fix copy/paste errors in HybridMobileDeployConfig
e22d240
Rename cb to callback and switch to setImmediate
104169a
Update example app version to be semver compliant
866bd7e
Update appVersion and buildVersion configuration code
0f027ea
Use configuration to get appVersion when checking for updates
27df072
Revert switch to localhost code location
c9f9279
Upgrade react-native to 0.8.0
b5b2788
Simplify reload bundle function
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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
#import "RCTBridgeModule.h" | ||
|
||
@interface HybridMobileDeploy : NSObject <RCTBridgeModule> | ||
+ (NSString *) getBundlePath:(NSString*)bundleName; | ||
+ (NSURL *) getNativeBundleURL:(NSString*)bundleName; | ||
+ (NSURL *)appBundleUrl; | ||
+ (NSURL *)appBundleUrl:(NSString*)bundleName | ||
nativeBundleName:(NSString*)nativeBundleName; | ||
|
||
+ (NSURL *) getBundleUrl; | ||
|
||
@end | ||
|
||
@interface HybridMobileDeployConfig : NSObject | ||
|
||
+ (void)setDeploymentKey:(NSString *)deploymentKey; | ||
+ (NSString *)getDeploymentKey; | ||
|
||
+ (void)setServerUrl:(NSString *)setServerUrl; | ||
+ (NSString *)getServerUrl; | ||
|
||
+ (void)setAppVersion:(NSString *)appVersion; | ||
+ (NSString *)getAppVersion; | ||
|
||
+ (void)setBuildVersion:(NSString *)buildVersion; | ||
+ (NSString *)getBuildVersion; | ||
|
||
+ (void)setRootComponent:(NSString *)rootComponent; | ||
+ (NSString *)getRootComponent; | ||
|
||
+ (NSDictionary *)getConfiguration; | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,96 @@ | ||
#import "HybridMobileDeploy.h" | ||
|
||
#import "RCTBridgeModule.h" | ||
#import "RCTRootView.h" | ||
#import "RCTUtils.h" | ||
|
||
@implementation HybridMobileDeploy | ||
|
||
RCT_EXPORT_MODULE() | ||
|
||
RCTBridge * _bridge; | ||
|
||
@synthesize bridge = _bridge; | ||
|
||
+ (NSString *) getBundleFolderPath | ||
{ | ||
NSString* home = NSHomeDirectory(); | ||
NSString* bundleFolder = [home stringByAppendingPathComponent:@"HybridMobileDeploy"]; | ||
return bundleFolder; | ||
} | ||
|
||
+ (NSString *) getBundlePath:(NSString*)bundleName | ||
+ (NSString *) getBundlePath | ||
{ | ||
NSString * bundleFolderPath = [self getBundleFolderPath]; | ||
NSString* appBundleName = [bundleName stringByAppendingString:@".jsbundle"]; | ||
NSString* appBundleName = @"main.jsbundle"; | ||
return [bundleFolderPath stringByAppendingPathComponent:appBundleName]; | ||
} | ||
|
||
+ (NSURL *) getNativeBundleURL:(NSString*)bundleName | ||
+ (NSURL *) getNativeBundleURL | ||
{ | ||
return [[NSBundle mainBundle] URLForResource:bundleName withExtension:@"jsbundle"]; | ||
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | ||
} | ||
|
||
+ (NSURL *) appBundleUrl | ||
{ | ||
return [self appBundleUrl:@"bundle" | ||
nativeBundleName:@"main"]; | ||
} | ||
|
||
+ (NSURL *) appBundleUrl:(NSString*)bundleName | ||
nativeBundleName:(NSString*)nativeBundleName | ||
+ (NSURL *) getBundleUrl | ||
{ | ||
NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
|
||
NSString *bundlePath = [self getBundlePath:bundleName]; | ||
NSString *bundlePath = [self getBundlePath]; | ||
if ([fileManager fileExistsAtPath:bundlePath]) { | ||
return [[NSURL alloc] initFileURLWithPath:bundlePath]; | ||
} else { | ||
return [self getNativeBundleURL:nativeBundleName]; | ||
return [self getNativeBundleURL]; | ||
} | ||
} | ||
|
||
+ (void) loadBundle:(NSString*)moduleName | ||
nativeBundleName:(NSString*)nativeBundleName | ||
- (void) reloadBundle | ||
{ | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:[self appBundleUrl:moduleName nativeBundleName:nativeBundleName] | ||
moduleName:moduleName | ||
launchOptions:nil]; | ||
|
||
UIViewController *rootViewController = [[UIViewController alloc] init]; | ||
rootViewController.view = rootView; | ||
[UIApplication sharedApplication].delegate.window.rootViewController = rootViewController; | ||
self.bridge.bundleURL = [HybridMobileDeploy getBundleUrl]; | ||
[self.bridge reload]; | ||
}); | ||
} | ||
|
||
RCT_EXPORT_METHOD(installUpdateFromUrl:(NSString*)updateUrl | ||
bundleName:(NSString*)bundleName | ||
nativeBundleName:(NSString*)nativeBundleName | ||
failureCallback:(RCTResponseSenderBlock)failureCallback | ||
successCallback:(RCTResponseSenderBlock)successCallback) | ||
RCT_EXPORT_METHOD(getConfiguration:(RCTResponseSenderBlock)callback) | ||
{ | ||
NSError *parameterError; | ||
NSMutableDictionary *errorData; | ||
if (!updateUrl) { | ||
errorData = [NSMutableDictionary dictionary]; | ||
[errorData setValue:@"missing-updateUrl" forKey:NSLocalizedDescriptionKey]; | ||
} else if (!bundleName) { | ||
errorData = [NSMutableDictionary dictionary]; | ||
[errorData setValue:@"missing-bundleName" forKey:NSLocalizedDescriptionKey]; | ||
} | ||
callback(@[[NSNull null], [HybridMobileDeployConfig getConfiguration]]); | ||
} | ||
|
||
if (errorData) { | ||
parameterError = [NSError errorWithDomain:@"HybridMobileDeploy"code:200 userInfo:errorData]; | ||
NSDictionary *rctError = RCTMakeError(@"Error with input to installUpdateFromUrl", parameterError, errorData); | ||
failureCallback(@[rctError]); | ||
} else { | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
NSURL* url = [NSURL URLWithString:updateUrl]; | ||
NSError *err; | ||
RCT_EXPORT_METHOD(installUpdateFromUrl:(NSString*)updateUrl | ||
callback:(RCTResponseSenderBlock)callback) | ||
{ | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
NSURL* url = [NSURL URLWithString:updateUrl]; | ||
NSError *err; | ||
|
||
NSString *updateContents = [[NSString alloc] initWithContentsOfURL:url | ||
encoding:NSUTF8StringEncoding | ||
error:&err]; | ||
if (err) { | ||
failureCallback(@[err]); | ||
} else { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
NSError *saveError; | ||
NSString *bundleFolderPath = [HybridMobileDeploy getBundleFolderPath]; | ||
if (![[NSFileManager defaultManager] fileExistsAtPath:bundleFolderPath]) { | ||
[[NSFileManager defaultManager] createDirectoryAtPath:bundleFolderPath withIntermediateDirectories:YES attributes:nil error:&saveError]; | ||
} | ||
[updateContents writeToFile:[HybridMobileDeploy getBundlePath:bundleName] | ||
atomically:YES | ||
encoding:NSUTF8StringEncoding | ||
error:&saveError]; | ||
if (saveError) { | ||
failureCallback(@[saveError]); | ||
} else { | ||
[HybridMobileDeploy loadBundle:bundleName nativeBundleName:nativeBundleName]; | ||
successCallback(@[]); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
NSString *updateContents = [[NSString alloc] initWithContentsOfURL:url | ||
encoding:NSUTF8StringEncoding | ||
error:&err]; | ||
|
||
if (err) { | ||
// TODO send download url | ||
callback(@[RCTMakeError(@"Error downloading url", err, [[NSDictionary alloc] initWithObjectsAndKeys:updateUrl,@"updateUrl", nil])]); | ||
} else { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
NSError *saveError; | ||
NSString *bundleFolderPath = [HybridMobileDeploy getBundleFolderPath]; | ||
if (![[NSFileManager defaultManager] fileExistsAtPath:bundleFolderPath]) { | ||
[[NSFileManager defaultManager] createDirectoryAtPath:bundleFolderPath withIntermediateDirectories:YES attributes:nil error:&saveError]; | ||
} | ||
[updateContents writeToFile:[HybridMobileDeploy getBundlePath] | ||
atomically:YES | ||
encoding:NSUTF8StringEncoding | ||
error:&saveError]; | ||
if (saveError) { | ||
// TODO send file path | ||
callback(@[RCTMakeError(@"Error saving file", err, [[NSDictionary alloc] initWithObjectsAndKeys:[HybridMobileDeploy getBundlePath],@"bundlePath", nil])]); | ||
} else { | ||
[self reloadBundle]; | ||
callback(@[[NSNull null]]); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not generate JavaScript from TypeScript?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React Native already uses its own JS transformation/bundling pipeline, which would be very tricky to integrate with TypeScript. Since the JS surface area is so small, I think it's preferable to leave it as plain JS rather than trying to force the React Native into something it wasn't designed for.