Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream IPC: Web container => Jasonette #253

Merged
merged 1 commit into from
Aug 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Jasonette/Jason.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#import "MBProgressHud.h"
@import MediaPlayer;

@interface Jason : NSObject <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITabBarControllerDelegate, PBJVisionDelegate>
@interface Jason : NSObject <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITabBarControllerDelegate, PBJVisionDelegate, UIWebViewDelegate>

@property (strong, nonatomic) NSDictionary *parser;
@property (strong, nonatomic) NSDictionary *data;
Expand Down
33 changes: 32 additions & 1 deletion app/Jasonette/Jason.m
Original file line number Diff line number Diff line change
Expand Up @@ -1834,14 +1834,23 @@ - (void)drawAdvancedBackground:(NSDictionary*)bg{
VC.background = nil;
}
VC.background = [[UIWebView alloc] initWithFrame: [UIScreen mainScreen].bounds];
((UIWebView*)VC.background).delegate = self;

// Need to make the background transparent so that it doesn't flash white when first loading
VC.background.opaque = NO;
VC.background.backgroundColor = [UIColor clearColor];
}
if(bg[@"text"]){
NSString *html = bg[@"text"];
[((UIWebView*)VC.background) loadHTMLString:html baseURL:nil];
if(VC.background.payload && VC.background.payload[@"html"] && [VC.background.payload[@"html"] isEqualToString:html]) {
// same html, no need to reload
} else {
// different html, reload
[((UIWebView*)VC.background) loadHTMLString:html baseURL:nil];
}

VC.background.payload = @{@"html": html};

}

// allow autoplay
Expand All @@ -1867,6 +1876,28 @@ - (void)drawAdvancedBackground:(NSDictionary*)bg{
}
});
}
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
NSString *summon = @"var JASON={call: function(e){var n=document.createElement(\"IFRAME\");n.setAttribute(\"src\",\"jason:\"+JSON.stringify(e)),document.documentElement.appendChild(n),n.parentNode.removeChild(n),n=null}};";
[webView stringByEvaluatingJavaScriptFromString:summon];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

if ([[[request URL] absoluteString] hasPrefix:@"jason:"]) {
// Extract the selector name from the URL
NSString *json = [[[request URL] absoluteString] substringFromIndex:6];
json = [json stringByRemovingPercentEncoding];

NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *action = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
[[Jason client] call: action];

return NO;
}

return YES;
}

- (void)drawBackground:(NSString *)bg{
dispatch_async(dispatch_get_main_queue(), ^{

Expand Down
20 changes: 20 additions & 0 deletions app/Jasonette/JasonHtmlComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ + (void)actionButtonClicked:(UIButton *)sender{
[[Jason client] call: sender.payload[@"action"]];
}
}
+ (void) webViewDidFinishLoad:(UIWebView *)webView
{
NSString *summon = @"var JASON={call: function(e){var n=document.createElement(\"IFRAME\");n.setAttribute(\"src\",\"jason:\"+JSON.stringify(e)),document.documentElement.appendChild(n),n.parentNode.removeChild(n),n=null}};";
[webView stringByEvaluatingJavaScriptFromString:summon];
}
+ (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

if ([[[request URL] absoluteString] hasPrefix:@"jason:"]) {
// Extract the selector name from the URL
NSString *json = [[[request URL] absoluteString] substringFromIndex:6];
json = [json stringByRemovingPercentEncoding];

NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *action = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
[[Jason client] call: action];

return NO;
}

return YES;
}

@end