Skip to content

Commit

Permalink
evalJavaScript directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Fung-GGL committed Dec 22, 2021
1 parent 937a32e commit b022a38
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions dsbridge/DWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
});

};

Expand Down

0 comments on commit b022a38

Please sign in to comment.