Skip to content

Commit

Permalink
Fix hang in wkwebview implemenation of webview::cookies()
Browse files Browse the repository at this point in the history
  • Loading branch information
acharron-hl committed Feb 11, 2025
1 parent cf18194 commit 6e8440b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use std::{
panic::AssertUnwindSafe,
ptr::{null_mut, NonNull},
str::{self, FromStr},
sync::{Arc, Mutex},
sync::{Arc, Mutex}, time::Duration,
};

#[cfg(feature = "mac-proxy")]
Expand Down Expand Up @@ -1054,16 +1054,21 @@ unsafe fn window_position(view: &NSView, x: i32, y: i32, height: f64) -> CGPoint
CGPoint::new(x as f64, frame.size.height - y as f64 - height)
}

/// Wait synchronously for the NSRunLoop to run until a receiver has a message.
unsafe fn wait_for_blocking_operation<T>(rx: std::sync::mpsc::Receiver<T>) -> Result<T> {
let interval = 0.0002;
let limit = 1.;
let mut elapsed = 0.;
// run event loop until we get the response back, blocking for at most 3 seconds
loop {
let rl = objc2_foundation::NSRunLoop::mainRunLoop();
let d = NSDate::dateWithTimeIntervalSinceNow(interval);
rl.runUntilDate(&d);
if let Ok(response) = rx.try_recv() {
let limit_date = NSDate::dateWithTimeIntervalSinceNow(interval);

let mode = NSString::from_str("NSDefaultRunLoopMode");

rl.acceptInputForMode_beforeDate(&mode, &limit_date);

if let Ok(response) = rx.recv_timeout(Duration::from_secs_f64(interval)) {
return Ok(response);
}
elapsed += interval;
Expand Down

0 comments on commit 6e8440b

Please sign in to comment.