diff --git a/p5.js-screen-saver/p5_js_screen_saverView.m b/p5.js-screen-saver/p5_js_screen_saverView.m index 2307e06..7692f4b 100644 --- a/p5.js-screen-saver/p5_js_screen_saverView.m +++ b/p5.js-screen-saver/p5_js_screen_saverView.m @@ -24,14 +24,24 @@ - (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]; + + // 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]; @@ -62,4 +72,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