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 29e4bb2
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions dsbridge/DWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,25 @@ -(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) {
@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 29e4bb2

Please sign in to comment.