Skip to content

Commit

Permalink
Merge pull request #29 from stefanalund/fix-startup
Browse files Browse the repository at this point in the history
Fix startup issue on older devices
  • Loading branch information
superdump committed Feb 5, 2015
2 parents 9a022ce + c15c4f9 commit 1221084
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
3 changes: 0 additions & 3 deletions bowser-ios/Bowser/BowserAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#import "BowserAppDelegate.h"
#import "BowserViewController.h"
#include <owr_bridge.h>
#import <AVFoundation/AVAudioSession.h>

#define kUserAgent @"Mozilla/5.0 (iOS; like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) not Chrome/36.0.1500.95 Mobile/12B411 Safari/600.1.4 Bowser/%@"
Expand All @@ -38,8 +37,6 @@ @implementation BowserAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
owr_bridge_start_in_thread();

NSError* theError = nil;
BOOL result = YES;

Expand Down
31 changes: 28 additions & 3 deletions bowser-ios/Bowser/BowserViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#import "BowserViewController.h"
#import "BowserHistoryTableViewCell.h"
#include <owr_bridge.h>

static NSString *const kGetUserMedia = @"getUserMedia";
static NSString *const kGetIpAndPort = @"qd_v1_getLocal";
Expand Down Expand Up @@ -126,16 +127,40 @@ - (void)viewDidLoad
[self.browserView.scrollView addSubview:selfView];
[self.headerView addSubview:self.bookmarkButton];
[self.consoleLogView loadHTMLString:[startHtml stringByAppendingString:@"</div></body>"] baseURL:nil];
}

- (void)viewDidAppear:(BOOL)animated
{
static BOOL isBridgeInitialized = NO;
if (isBridgeInitialized)
return;

NSString *startURL = [[NSUserDefaults standardUserDefaults] objectForKey:@"lastURL"];
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"has_started"] || !startURL) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"has_started"];
startURL = kDefaultStartURL;
}
self.urlField.text = startURL;

// Let's get started...
[self loadRequestWithURL:startURL];
dispatch_queue_t queue = dispatch_queue_create("OWR init queue", NULL);
dispatch_async(queue, ^{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Initializing"
message:@"Please wait..."
preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];

NSLog(@"OWR bridge starting...");
owr_bridge_start_in_thread();
NSLog(@"OWR bridge started");

[alert dismissViewControllerAnimated:YES completion:^{
// Let's get started...
self.urlField.text = startURL;
[self loadRequestWithURL:startURL];
}];
});

isBridgeInitialized = YES;
}

- (void)loadRequestWithURL:(NSString *)url
Expand Down

0 comments on commit 1221084

Please sign in to comment.