From 70040e1f8be95e1d46adb2f47262d78e8da7b5b5 Mon Sep 17 00:00:00 2001 From: Jens de Boer Date: Mon, 8 Oct 2018 11:11:13 +0200 Subject: [PATCH 1/2] Changed from WebView to WKWebView (better performance); Added override of default event listeners --- p5.js-screen-saver/p5_js_screen_saverView.m | 28 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/p5.js-screen-saver/p5_js_screen_saverView.m b/p5.js-screen-saver/p5_js_screen_saverView.m index 2307e06..ed0226c 100644 --- a/p5.js-screen-saver/p5_js_screen_saverView.m +++ b/p5.js-screen-saver/p5_js_screen_saverView.m @@ -24,10 +24,10 @@ - (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview NSURL *url = [NSURL URLWithString:URLString]; // add webview - WebView *webView = [[WebView alloc] initWithFrame:frame]; - webView.frameLoadDelegate = self; + WKWebView *webView = [[WKWebView alloc] initWithFrame:[self bounds]]; + webView.navigationDelegate = self; NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; - [webView.mainFrame loadRequest:request]; + [webView loadRequest:request]; [self addSubview:webView]; return self; } @@ -62,4 +62,26 @@ - (NSWindow*)configureSheet return nil; } +// Override default listeners + +- (NSView *)hitTest:(NSPoint)aPoint { + return self; +} + +- (void)keyDown:(NSEvent *)theEvent { + return; +} + +- (void)keyUp:(NSEvent *)theEvent { + return; +} + +- (BOOL)acceptsFirstResponder { + return YES; +} + +- (BOOL)resignFirstResponder { + return NO; +} + @end From 599f0aa18b2400eeef9c4a8f835e070607722974 Mon Sep 17 00:00:00 2001 From: Jens de Boer Date: Tue, 9 Oct 2018 19:07:40 +0200 Subject: [PATCH 2/2] The webview is now hidden until the request is finished - this removes the white flashing background at the start --- p5.js-screen-saver/p5_js_screen_saverView.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/p5.js-screen-saver/p5_js_screen_saverView.m b/p5.js-screen-saver/p5_js_screen_saverView.m index ed0226c..7692f4b 100644 --- a/p5.js-screen-saver/p5_js_screen_saverView.m +++ b/p5.js-screen-saver/p5_js_screen_saverView.m @@ -28,10 +28,20 @@ - (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview webView.navigationDelegate = self; NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; [webView loadRequest:request]; + + // Hide webview while loading + [webView setHidden:true]; + [self addSubview:webView]; return self; } +// Show webview when finished loading +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation; +{ + [webView setHidden:false]; +} + - (void)startAnimation { [super startAnimation];