Skip to content

Commit

Permalink
Merge pull request #593 from gree/fix/osx_callonloaded
Browse files Browse the repository at this point in the history
fixed osx CallOnLoaded (cf. #592).
  • Loading branch information
KojiNakamaru authored Sep 15, 2020
2 parents 27f679a + 3ec4bd1 commit d5b8e87
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions plugins/Mac/Sources/WebView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ - (id)initWithGameObject:(const char *)gameObject_ transparent:(BOOL)transparent
// [webView setPolicyDelegate:(id)self];
webView.UIDelegate = self;
webView.navigationDelegate = self;
[webView addObserver:self forKeyPath: @"loading" options: NSKeyValueObservingOptionNew context:nil];
gameObject = [NSString stringWithUTF8String:gameObject_];
if (ua != NULL && strcmp(ua, "") != 0) {
[webView setCustomUserAgent:[NSString stringWithUTF8String:ua]];
Expand All @@ -186,12 +187,14 @@ - (void)dispose
{
@synchronized(self) {
if (webView != nil) {
WKWebView *webView0 = webView;
webView = nil;
// [webView setFrameLoadDelegate:nil];
// [webView setPolicyDelegate:nil];
webView.UIDelegate = nil;
webView.navigationDelegate = nil;
[webView stopLoading:nil];
webView = nil;
webView0.UIDelegate = nil;
webView0.navigationDelegate = nil;
[webView0 stopLoading];
[webView0 removeObserver:self forKeyPath:@"loading"];
}
if (window != nil) {
[window close];
Expand All @@ -218,11 +221,6 @@ - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigatio
[self addMessage:[NSString stringWithFormat:@"E%@",[error description]]];
}

- (void)webView:(WKWebView*)wkWebView didCommitNavigation:(null_unspecified WKNavigation *)navigation
{
[self addMessage:[NSString stringWithFormat:@"L%s","Unknown URL"]];
}

- (void)webView:(WKWebView *)wkWebView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
if (webView == nil) {
Expand Down Expand Up @@ -297,6 +295,19 @@ - (void)userContentController:(WKUserContentController *)userContentController
*/
}

- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (webView == nil)
return;

if ([keyPath isEqualToString:@"loading"] && [[change objectForKey:NSKeyValueChangeNewKey] intValue] == 0
&& [webView URL] != nil) {
[self addMessage:[NSString stringWithFormat:@"L%s",[[[webView URL] absoluteString] UTF8String]]];
}
}

- (void)addMessage:(NSString*)msg
{
@synchronized(messages)
Expand Down

0 comments on commit d5b8e87

Please sign in to comment.