Skip to content

Commit

Permalink
Merge pull request #1 from jnsdbr/master
Browse files Browse the repository at this point in the history
Changed from WebView to WKWebView (better performance)
  • Loading branch information
mactkg authored Aug 27, 2019
2 parents b1764ce + 599f0aa commit 7a6d4a4
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions p5.js-screen-saver/p5_js_screen_saverView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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

0 comments on commit 7a6d4a4

Please sign in to comment.