From b022a3878996d6edd0c8a3dec8318298e8c1af6f Mon Sep 17 00:00:00 2001 From: Alex Fung Date: Wed, 22 Dec 2021 14:43:04 +1300 Subject: [PATCH] evalJavaScript directly --- dsbridge/DWKWebView.m | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/dsbridge/DWKWebView.m b/dsbridge/DWKWebView.m index 2e54d3c..2e48e74 100644 --- a/dsbridge/DWKWebView.m +++ b/dsbridge/DWKWebView.m @@ -294,20 +294,26 @@ -(NSString *)call:(NSString*) method :(NSString*) argStr del=[@"delete window." stringByAppendingString:cb]; } NSString*js=[NSString stringWithFormat:@"try {%@(JSON.parse(decodeURIComponent(\"%@\")).data);%@; } catch(e){};",cb,(value == nil) ? @"" : value,del]; - __strong typeof(self) strongSelf = weakSelf; - @synchronized(self) - { - UInt64 t=[[NSDate date] timeIntervalSince1970]*1000; - jsCache=[jsCache stringByAppendingString:js]; - if(t-lastCallTime<50){ - if(!isPending){ - [strongSelf evalJavascript:50]; - isPending=true; + dispatch_async(dispatch_get_main_queue(), ^{ + //__strong typeof(self) strongSelf = weakSelf; + if (weakSelf != nil) { + NSLog(@"evaluateJavaScript%@",js); + @synchronized(weakSelf) + { + // UInt64 t=[[NSDate date] timeIntervalSince1970]*1000; + // jsCache=[jsCache stringByAppendingString:js]; + // if(t-lastCallTime<50){ + // if(!isPending){ + // [strongSelf evalJavascript:50]; + // isPending=true; + // } + // }else{ + // [strongSelf evalJavascript:0]; + // } + [weakSelf evaluateJavaScript:js completionHandler:nil]; } - }else{ - [strongSelf evalJavascript:0]; } - } + }); };