Retry the webkit load until we've connected to the server.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4542 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-10-19 18:05:34 +00:00
parent 1e5aa0ba93
commit 8c4ec71e26

View File

@ -1,6 +1,5 @@
#include "log.h"
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <WebKit/WKNavigationDelegate.h>
#import <WebKit/WKUIDelegate.h> #import <WebKit/WKUIDelegate.h>
#import <WebKit/WKWebView.h> #import <WebKit/WKWebView.h>
#import <WebKit/WKWebViewConfiguration.h> #import <WebKit/WKWebViewConfiguration.h>
@ -10,10 +9,16 @@
void tf_run_thread_start(const char* zip_path); void tf_run_thread_start(const char* zip_path);
@interface ViewController : UIViewController<WKUIDelegate> @interface ViewController : UIViewController<WKUIDelegate,WKNavigationDelegate>
@property(strong, nonatomic) WKWebView* web_view; @property(strong, nonatomic) WKWebView* web_view;
@property bool initial_load_complete;
@end @end
static void _start_initial_load(WKWebView* web_view)
{
[web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/"]]];
}
@implementation ViewController : UIViewController @implementation ViewController : UIViewController
- (void)viewDidLoad - (void)viewDidLoad
{ {
@ -21,8 +26,22 @@ void tf_run_thread_start(const char* zip_path);
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init]; WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration]; self.web_view = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
self.web_view.UIDelegate = self; self.web_view.UIDelegate = self;
[self.web_view loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:12345/"]]]; self.web_view.navigationDelegate = self;
[self.view addSubview:self.web_view]; [self.view addSubview:self.web_view];
_start_initial_load(self.web_view);
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
self.initial_load_complete = true;
}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
{
if (!self.initial_load_complete)
{
_start_initial_load(self.web_view);
}
} }
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler