From c15c4f98782d133855dc2069acecdf1b716ceb35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20A=CC=8Alund?= Date: Thu, 5 Feb 2015 09:50:34 +0100 Subject: [PATCH] Fix startup issue on older devices Moved initialisation of the the JavaScript bridge from the AppDelegate to BowserViewController and run it in a separate thread (GCD). --- bowser-ios/Bowser/BowserAppDelegate.m | 3 --- bowser-ios/Bowser/BowserViewController.m | 31 +++++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bowser-ios/Bowser/BowserAppDelegate.m b/bowser-ios/Bowser/BowserAppDelegate.m index ecc3f15..ecac511 100644 --- a/bowser-ios/Bowser/BowserAppDelegate.m +++ b/bowser-ios/Bowser/BowserAppDelegate.m @@ -29,7 +29,6 @@ #import "BowserAppDelegate.h" #import "BowserViewController.h" -#include #import #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/%@" @@ -38,8 +37,6 @@ @implementation BowserAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - owr_bridge_start_in_thread(); - NSError* theError = nil; BOOL result = YES; diff --git a/bowser-ios/Bowser/BowserViewController.m b/bowser-ios/Bowser/BowserViewController.m index a123be7..1a3e048 100644 --- a/bowser-ios/Bowser/BowserViewController.m +++ b/bowser-ios/Bowser/BowserViewController.m @@ -29,6 +29,7 @@ #import "BowserViewController.h" #import "BowserHistoryTableViewCell.h" +#include static NSString *const kGetUserMedia = @"getUserMedia"; static NSString *const kGetIpAndPort = @"qd_v1_getLocal"; @@ -126,16 +127,40 @@ - (void)viewDidLoad [self.browserView.scrollView addSubview:selfView]; [self.headerView addSubview:self.bookmarkButton]; [self.consoleLogView loadHTMLString:[startHtml stringByAppendingString:@""] 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